A dash (-), an en-dash (–) and an emdash (—) are different but difficult to tell apart. This causes problems e.g. when writing programs. Is there some way to tell them apart easier in emacs? Thanks.
Here is a little fun with Unicode smiley faces. The en-dash visually becomes a black smiley face. The em-dash visually becomes a white smiley face. Note, some Emacs versions may not support the smiley face Unicode characters -- it is only meant to be a demonstration -- other Unicode characters can of course be chosen. Other faces can be used, and the user is free to compose his / her own faces.
(let ((glyph-en-dash (make-glyph-code ?\u263A 'font-lock-keyword-face)) (glyph-em-dash (make-glyph-code ?\u263B 'font-lock-function-name-face)) ) (when (not buffer-display-table) (setq buffer-display-table (make-display-table))) (aset buffer-display-table 8211 `[,glyph-en-dash]) (aset buffer-display-table 8212 `[,glyph-em-dash]))
Here is an updated example that effectively concatenates the hyphen-minus and adds color -- i.e., the
8211 visually becomes
-- with the
font-lock-keyword-face as coloration; and, the
8212 visually becomes
--- with the
font-lock-function-name-face as coloration.
(let ((glyph-en-dash (make-glyph-code ?\u002D 'font-lock-keyword-face)) (glyph-em-dash (make-glyph-code ?\u002D 'font-lock-function-name-face)) ) (when (not buffer-display-table) (setq buffer-display-table (make-display-table))) (aset buffer-display-table 8211 `[,glyph-en-dash ,glyph-en-dash]) (aset buffer-display-table 8212 `[,glyph-em-dash ,glyph-em-dash ,glyph-em-dash]))
To quote the docs:
C-x = runs the command
what-cursor-position, which is an interactive compiled Lisp function in
It is bound to C-x =.
(what-cursor-position &optional DETAIL)
Print info on cursor position (on screen and within buffer). Also describe the character after point, and give its character code in octal, decimal and hex.
For a non-ASCII multibyte character, also give its encoding in the buffer's selected coding system if the coding system encodes the character safely. If the character is encoded into one byte, that code is shown in hex. If the character is encoded into more than one byte, just "..." is shown.
In addition, with prefix argument, show details about that character in *Help* buffer. See also the command `describe-char'.
Emphasis and formatting mine.
Try to remember these codes:
But if you forget them, you can easily do C-u C-x =, which pops up a buffer with extra info, including a
You can use command
hc-highlight-chars to do highlight characters in four ways:
- using ranges
- using character classes (e.g.
- using character sets (e.g.
hc-highlight-chars prompts you for the character(s) to highlight in a particular face and the face to use for them. (With a prefix arg it unhighlights.)
When you are prompted for the character(s) to highlight, you can use
C-x 8 RET to choose Unicode characters using completion.