12

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?

Lee H
  • 2,697
  • 1
  • 16
  • 31

3 Answers3

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.

purple_arrows
  • 2,373
  • 10
  • 19
3

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

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.