1

Let me say first my English is not so good and I'm totally new to Emacs.

In Org-Mode I can specify a monospace font in code-blocks while using a proportional font in normal text.

So I defined a proportional font as my default font.

But if I open now for example a shell script or init.el, I get syntax highlighting but no monospace font.

I can change each different item using M-x describe-face and set there a font.

Unfortunately this would force me to change the font for each item, for example (default ‘font-lock-comment-face’) for comments but it would be more easy to set a proportional font for plain text (files) in general.

An other possibility would be as a workaround to apply a specific font for the current buffer using a keyboard shortcut.

How can I configure one or both possibilities?


No, I configured Org Mode that way having a proportional font as default (via Menu 'default font') and monospace font for code-blocks, what is ok for me. But when I open a shell-script for exemple, it will be opened in my default-font not monospace as I would expect.

The function shown above does work fine for Org-mode but it does not enable me changing the font for files which does need monospace. I'm not talking about code blocks here but opening for exemple a shell script in monospace font, a plain text 'file.txt' in proportional font.


Yes, but that's exact my question how to set in a general way. But I think I explained this before... didn't meant expectation that way - but how to reach this target in general. I would suppose most people who use Emacs in a more literary way use a monospace font for code files nevertheless... But how do they realize this without editing each single item (meaning by mime type or ending). This because Emacs recognize a shell script for exemple and does correct syntax highlighting but not changing to a monospace font?

1

1 Answer 1

3

You can use buffer-face-mode for this purpose. For example:

(defun my-buffer-face-org-mode ()
    "Set a fixed width (monospace) font in `org-mode' buffers, with a
  height of 11pt."
    (interactive)
    (setq buffer-face-mode-face '(:family "Fira Mono" :height 110))
    (buffer-face-mode))

(add-hook 'org-mode-hook 'my-buffer-face-org-mode)

You can create a default value and then change it for particular buffer types. e.g., attach a hook to text-mode-hook, which is inherited by most text modes, such as XML. If you don't want the default in XML buffers, then change it with nxml-mode-hook.

3
  • IIUC, this will set the whole buffer to a monospace font. I believe the OP is asking for a monospace font in source code blocks (and probably tables as well, or else there will be alignment problems), but he wants a proportional font for the rest of the buffer.
    – NickD
    Nov 9, 2021 at 1:30
  • 1
    Org mode does this by default. e.g., my source blocks are Cascadia Mono PL 10pt and org text is Fira Mono 11pt. Table alignment is the reason I don't use proportional font in org text. I think what is happening is, he's getting proportional fonts inherited from whatever he set as 'default'. Nov 9, 2021 at 13:17
  • Thank's a lot for the function, have now on shortcut for proportional and monospace. For tables it's possible to set a font like for Org-blocks. But so far I understand You, it's maybe more easy to set a monospace font as default and specifie proportional font for plain text files and normal text in Org? That's why I ask if it's possible to design a face per filetype...?
    – OsunSeyi
    Nov 12, 2021 at 9:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.