Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs: Multiple fonts in a single buffer

Tags:

emacs

org-mode

I use org-mode daily for all sorts of things, and I like variable-width fonts for reading text which makes up the majority of my files. But for tables to be correctly aligned, a fixed-width font it necessary. Is it possible to configure emacs to show org-mode tables in a fixed-with font and the rest of the buffer in a variable-width font?

I understand the typical question is not: "Is X possible in emacs?" but rather "How do I do X in emacs?" so I'm optimistic, but haven't found an answer on Google or SO yet...

like image 423
Matthew Gilliard Avatar asked Sep 17 '13 10:09

Matthew Gilliard


People also ask

What is a buffer in Emacs?

A buffer is an interface between Emacs and a file or process. It doesn’t have to be visible on the screen. You can (and sometimes will) have hundreds of buffers open in Emacs, but you’ll probably only have windows open to one or two at a time. Buffers hold text and each one has a unique name.

How do I change the font size in Emacs 23?

GlobalTextScaleMode – Adjust font size for all buffers at once using face remapping (Emacs 23+). You can use any of the following to increase or decrease the font size for the current frame, effectively resizing it incrementally – zooming the text in or out. ‘zoom-in/out’, ‘zoom-in’, ‘zoom-out’ (in zoom-frm.el) – see above for the descriptions.

What does font mean in Emacs?

where FONT is a string naming the font you want, for example, "Droid Sans Mono-10". This should work on all platforms. As of Emacs 23, all of your system fonts including TrueType are available to Emacs.

How do I use xfontsel in Emacs?

If you are running Linux, you may be able to run `xfontsel` from a shell. This program helps you select a font. Once you’ve found one that you like, save the specification string. In my version, clicking the “select” button near the top left copies the string to my clipboard so I can yank (paste) it into Emacs.


1 Answers

You can have multiple fonts in a buffer (C-h C-a to see an example).

You can customize the font family of any face in emacs, so you can have variable and fixed width sizes fonts.

Then you can use font-lock-add-keywords (for example) in org-mode-hook to instruct font-lock to use a face with fixed width the regular expression that matches rows of a table (I think it would be something like "\s*|.*", but maybe I am oversimplifying)

like image 106
juanleon Avatar answered Sep 19 '22 13:09

juanleon