I would like to set the glyph of a certain unicode character. Specifically, I would like the glyph § (SECTION SIGN) to represent the unicode character U+202A (LEFT-TO-RIGHT EMBEDDING), a normally non-visible character, in the main buffer. However, this glyph assignment must be confined to the main buffer; in particular, it must not be used when printing the document as a PDF file.
Asked
Active
Viewed 588 times
6
-
Have a look at the manual on [text properties](https://www.gnu.org/software/emacs/manual/html_node/elisp/Text-Properties.html) and [overlays](http://www.gnu.org/software/emacs/manual/html_node/elisp/Overlays.html), which are alternate means to affect the printed representation on the screen without affecting the underlying content of the buffer/file. – Dan Jan 05 '15 at 15:54
-
"main buffer" has no meaning without context. With respect to importance, all emacs buffers are created equal. – Malabarba Jan 06 '15 at 02:29
2 Answers
6
What you want to do is to set the display-table entry for character LEFT-TO-RIGHT EMBEDDING
to the glyph that is used for character SECTION SIGN
.
(aset (or (window-display-table) standard-display-table)
8234 ; 0x202A, which is the char LEFT-TO-RIGHT EMBEDDING
(vector (make-glyph-code ?§)))
If the selected window has its own display table, then update that. If not, update the standard display table.
You can also put a face on that section-symbol glyph, if you like. For example:
(aset (or (window-display-table) standard-display-table)
8234
(vector (make-glyph-code ?§ 'escape-glyph)))

Drew
- 75,699
- 9
- 109
- 225
-
1
-
1@jch: Yes. The first arg to `aset` here should be a display table. You can use any display table you want - whatever is appropriate for your context. But yes, it needs to be a display table, not, e.g., `nil`. – Drew Jan 06 '15 at 03:11
-
Thank you very much. I've ended up adding a slightly modified code to my .emacs file. I posted it in an answer to this thread. – Evan Aad Jan 06 '15 at 10:14
-
What did you mean by 'you can also put a face on that section-symbol glyph'? What's a face? And what is the difference between this method and the first method described in your answer? Does the face argument always have to be `'escape-glyph`? If not - what other values can it take, and what does this value mean? – Evan Aad Jun 29 '17 at 13:00
-
@EvanAad: See the Emacs and Elisp manuals, for what a face is. No, the face need not be face `escape-glyph` - see `C-h f make-glyph-code`. – Drew Jun 29 '17 at 13:57
0
Thanks to Drew's answer and to jch's comment, I've added the following lines to the beginning of my .emacs file.
(unless standard-display-table
(setq standard-display-table (make-display-table))
)
(unless (aref standard-display-table #x202a) (aset standard-display-table #x202a (vector (make-glyph-code #x22c9 'escape-glyph)))
)
(unless (aref standard-display-table #x202b)
(aset standard-display-table #x202b (vector (make-glyph-code #x22ca 'escape-glyph)))
)
(unless (aref standard-display-table #x202c)
(aset standard-display-table #x202c (vector (make-glyph-code #x22c8 'escape-glyph)))
)

Evan Aad
- 1,461
- 1
- 14
- 29