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.
-
Can you talk about a use case about those dashes causing problem when writing code? The only dash I have come across while reading and writing code is the regular dash. I use n-dash and m-dash only in org-mode documentation using `--` and `---`. – Kaushal Modi Feb 27 '15 at 00:53
-
http://unix.stackexchange.com/questions/187010/rsync-error-during-incremental-backup/187033#187033 – Tim Feb 27 '15 at 00:55
-
So the problem is not with the code in emacs but from something you copied from a web page. It's likely that the person who wrote that article did so in `org-mode` where `--` will render as n-dash unless it is wrapped in verbatim or code formatting like `=command --some-arg=`. – Kaushal Modi Feb 27 '15 at 01:00
-
I believe some? all? flavors of markdown also support that which is much more prevalent than org mode for writing blogs. So that is a very likely issue. – Kaushal Modi Feb 27 '15 at 01:04
-
What is the relationship between [the webpage](http://schlutech.com/2011/11/rsync-full-incremental-differential-snapshots/) you posted in the above referenced [unix.SE link](http://unix.stackexchange.com/questions/187010/rsync-error-during-incremental-backup/187033#187033) and emacs? Are you viewing that in `eww` and you want to render the en- and em- dashes as `--` and `---`? Or are you copying those command line snippets and pasting them in emacs `shell` or alike and you want those dashes to convert at the time of pasting? – Kaushal Modi Feb 27 '15 at 01:34
-
@kaushalmodi: want to check if a text has those misleading characters in Emacs before running the text as command. – Tim Feb 27 '15 at 02:21
-
1Surely that first one is a hyphen, not a dash at all. – TRiG Feb 27 '15 at 07:04
-
A very valid question. Book and journal typography may use both hyphen and en-dash, or all three variants, em-dash included. Emacs, using monospaced fonts, may easily show all those as the same glyph. – yury10578 Jun 30 '22 at 05:35
3 Answers
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]))

- 18,826
- 5
- 37
- 118
-
Can the en-dash be rendered as `--` and em-dash as `---` with a distinct face like bold red so that the user knows that emacs has rendered those differently? – Kaushal Modi Feb 27 '15 at 01:35
-
2@kaushalmodi -- I updated the example to include `8211` as `--` with the `font-lock-keyword-face`; and the `8212` as `---` with the `font-lock-function-name-face`. – lawlist Feb 27 '15 at 01:47
To quote the docs:
C-x = runs the command
what-cursor-position
, which is an interactive compiled Lisp function insimple.el
.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:
HYPHEN-MINUS
45EN DASH
8211EM DASH
8212
But if you forget them, you can easily do C-u C-x =, which pops up a buffer with extra info, including a name:
field.

- 10,243
- 2
- 29
- 75
-
1what is the difference between hyphen, minus and dash in terms of their glyphs? – Tim Feb 27 '15 at 02:08
-
`HYPHEN-MINUS` is the canonical Unicode name for the plain dash, which you can usually type by pressing the key to the left of `=` key. It's the "regular" dash used everywhere in programming. – PythonNut Feb 27 '15 at 02:29
-
-
@Tim As far as we are concerned, they are synonyms. The Unicode standards body calls it a hyphen. You call it a dash.... neither of you are wrong. – PythonNut Feb 27 '15 at 02:31
-
4@Tim. In English orthography, hyphens connect things. There's a hyphen in *twenty-three*, for example. Dashes separate things. I wouldn't call that a dash at all. – TRiG Feb 27 '15 at 07:06
-
Use library highlight-chars.el
to highlight any Unicode chars anyway you want. See Highlight Characters on Emacs Wiki.
You can use command hc-highlight-chars
to do highlight characters in four ways:
- individually
- using ranges
- using character classes (e.g.
[:digit:]
) - using character sets (e.g.
iso-8859-1
orlao
)
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.

- 75,699
- 9
- 109
- 225