2

Need

Default emacs font for most buffers is okay. But for coding-related activities I need a smaller, crisp font.

What works

In the spirit of Is it possible to change the font size in specific buffers? - Emacs Stack Exchange I've followed https://www.emacswiki.org/emacs/FacesPerBuffer and it works for most modes.

Those work very well:

(add-hook 'emacs-lisp-mode-hook 'my-buffer-face-mode-fixed)
(add-hook 'graphviz-dot-mode-hook 'my-buffer-face-mode-fixed)
(add-hook 'text-mode-hook 'my-buffer-face-mode-fixed)
(add-hook 'c-mode-hook 'my-buffer-face-mode-fixed)
(add-hook 'c++-mode-hook 'my-buffer-face-mode-fixed)
(add-hook 'objc-mode-hook 'my-buffer-face-mode-fixed)
(add-hook 'cmake-mode-hook 'my-buffer-face-mode-fixed)
(add-hook 'compilation-mode-hook 'my-buffer-face-mode-fixed)
(add-hook 'shell-dirtrack-mode-hook 'my-buffer-face-mode-fixed)
...(and many others)...

What fails

When using M-x gdb, a multi-buffer interface appears, and I can't set the font for them.

describe-mode reports Gdb-Many-Windows and many others.

So I added

(add-hook 'gdb-many-windows-hook 'my-buffer-face-mode-fixed)

But it had no effect.

Then browsed https://github.com/Hawstein/my-emacs/blob/master/_emacs/multi-gdb-ui.el and added all the lines below, to hook, well, on every hook visible in that source code:

(add-hook 'prog-mode-hook 'my-buffer-face-mode-fixed)
(add-hook 'gdb-local-mode-hook 'my-buffer-face-mode-fixed)
(add-hook 'gdba-mode-hook 'my-buffer-face-mode-fixed)
(add-hook 'gdb-breakpoints-mode-hook 'my-buffer-face-mode-fixed)
(add-hook 'gdb-frames-mode-hook 'my-buffer-face-mode-fixed)
(add-hook 'gdb-threads-mode-hook 'my-buffer-face-mode-fixed)
(add-hook 'gdb-registers-mode-hook 'my-buffer-face-mode-fixed)
(add-hook 'gdb-memory-mode-hook 'my-buffer-face-mode-fixed)
(add-hook 'gdb-info-locals-mode-hook 'my-buffer-face-mode-fixed)
(add-hook 'gdb-locals-mode-hook 'my-buffer-face-mode-fixed)
(add-hook 'gdb-assembler-mode-hook 'my-buffer-face-mode-fixed)
(add-hook 'global-ede-mode-hook 'my-buffer-face-mode-fixed)

Still no effect.

It's tedious to manually change font every time in the ~5 buffers at each gdb invocation.

What now?

How to set font for gdb emacs interface buffers?

  • There's also `(set-frame-font "Envy Code R-9" nil t)` which sets font as global default for all frames, which include gdb-mi frames. But it's global, not specific to mode. – Stéphane Gourichon Mar 10 '17 at 10:18

2 Answers2

1

Maybe something like this?

(add-hook 'gdb-mode-hook 'my-buffer-face-mode-fixed)
(advice-add 'gdb-parent-mode :after 'my-buffer-face-mode-fixed)

Some of the buffers are in non-gdb modes, however (e.g. buffer-menu-mode, comint-mode), so you would need to do those separately if you want them as well.

Muir
  • 311
  • 2
  • 5
  • Thanks a lot! The answer as is sets font for the "stack frames", "locals" and "registers" buffers. The "input/output" buffer remains with default font, and this can be fixed with: `(advice-add 'comint-mode :after 'my-buffer-face-mode-fixed)`. – Stéphane Gourichon May 04 '18 at 10:10
  • Since you mentioned it, buffer-menu mode was already working well with `(add-hook 'buffer-menu-mode-hook 'my-buffer-face-mode-fixed)`. – Stéphane Gourichon May 04 '18 at 10:12
  • Regarding my first comment: for `comint-mode`, there is a working hook so no need to resort to `advice-add`, the traditional way works: `(add-hook 'comint-mode-hook 'my-buffer-face-mode-fixed)` – Stéphane Gourichon May 04 '18 at 11:54
0

Found a hack that works...

I added this line:

(set-frame-font "Envy Code R-9")

In that:

 ;; Use monospaced font faces in current buffer
 (defun my-buffer-face-mode-fixed ()
   "Sets a fixed width (monospace) font in current buffer"
   (interactive)
   (setq buffer-face-mode-face '(:family "Envy Code R" :height 100))
   (set-frame-font "Envy Code R-9")
   (buffer-face-mode))

As a result, the whole frame gets the smaller font I need, not the buffer. Opening the same buffer in another frame doesn't get the font, but, well, that's a hack. Also, at startup emacs window changes appearance even more than before.

I'd like a cleaner answer.