13

I would like to have an org-mode file with the following content:

#+TITLE: My awesome Emacs file * My Header Here's some information under the header #+BEGIN_SRC sh echo "this is some code" #+END_SRC More text and =verbatim= things 

Is it possible to have Emacs display the header and text in a variable-width font and only the #+BEGIN_SRC, #+END_SRC, =verbatim= and source code in a fixed-width font?

3 Answers 3

7

This is all-but-a-dupe of this question on SO. As of this writing, the accepted answer over there is (mutatis mutandis):

(set-face-attribute 'org-verbatim nil :inherit 'fixed-pitch)

EDIT: Actually read your question. Since you want to change multiple faces, this is a more complete answer:

(dolist (face '(org-block-begin-line org-block-end-line org-verbatim org-block-background)) (set-face-attribute face nil :inherit 'fixed-pitch) 

Note that this will overwrite any existing :inherit parameters on the faces. If that's a problem, another answer to the same SO question provides code to work around the issue.

4

There is a package for precisely that: mixed-pitch mode.

1
  • Thank you — this is perfect and solves all the issues I've hit. Commented Jun 24, 2020 at 6:23
1

I'm not very familiar with how org-mode delimits blocks, so I can only give a general answer.

There is a standard face called variable-pitch, which you can apply to a given region like this:

(set-text-properties (region-beginning) (region-end) '(face (variable-pitch)))) 

This only works when automatic fontification is inhibited, though. You may be able to hook into org-mode's fontification code and override the face of selected regions with variable-pitch.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.