Playing with Emacs’ fontsets definitions should be the answer.
After reading
The startup fontset will use the font that you specify, or a variant
with a different registry and encoding, for all the characters that
are supported by that font, and fallback on ‘fontset-default’ for
other characters.
If some characters appear on the screen as empty boxes or hex codes,
this means that the fontset in use for them has no font for those
characters.
- set-fontset-font description:
TARGET may be a cons; (FROM . TO), where FROM and TO are characters.
In that case, use FONT-SPEC for all characters in the range FROM and
TO (inclusive).
TARGET may be a script name symbol. In that case, use FONT-SPEC for
all characters that belong to the script.
TARGET may be a charset. In that case, use FONT-SPEC for all
characters in the charset.
TARGET may be nil. In that case, use FONT-SPEC for any characters for
that no FONT-SPEC is specified.
There are two commands that can be used to obtain information about charsets. The command M-x list-charset-chars prompts for a charset name, and displays all the characters in that character set. The command M-x describe-character-set prompts for a charset name, and displays information about that charset, including its internal representation within Emacs.
To find out which charset a character in the buffer belongs to, put point before it and type C-u C-x =
In our init file we should be able to set one font for full range of characters:
(let ((my-font "DejaVu Sans Mono-14"))
(set-fontset-font "fontset-startup" '(#x000000 . #x3FFFFF) my-font)
(set-fontset-font "fontset-default" '(#x000000 . #x3FFFFF) my-font)
(set-fontset-font "fontset-standard" '(#x000000 . #x3FFFFF) my-font))
But to set a font for a range of characters and force it as a fallback font for characters not supported by it we also must add nil
as a target:
(let ((my-font "DejaVu Sans Mono-14")
(font-sets '("fontset-default"
"fontset-standard"
"fontset-startup")))
(mapcar
(lambda (font-set)
;; all the characters in that range (which is the full possible range)
(set-fontset-font font-set '(#x000000 . #x3FFFFF) my-font)
;; for all characters without font specification
;; in another words it is a setting for lack of fallback font
;; if e.g. ℕ called DOUBLE-STRUCK CAPITAL N is not covered by our font
;; it will be displayed as placeholder-box,
;; because fallback for our font is now... our font :)
(set-fontset-font font-set nil my-font))
font-sets))
Now as we can see under point (cursor) with C-u C-x =
or M-x describe-char
:
position: 1430 of 1954 (73%), column: 16
character: ℕ (displayed as ℕ) (codepoint 8469, #o20425, #x2115)
preferred charset: unicode (Unicode (ISO10646))
code point in charset: 0x2115
script: symbol
syntax: w which means: word
category: .:Base, L:Left-to-right (strong)
to input: type "C-x 8 RET HEX-CODEPOINT" or "C-x 8 RET NAME"
buffer code: #xE2 #x84 #x95
file code: #xE2 #x84 #x95 (encoded by coding system utf-8-unix)
display: no font available
Character code properties: customize what to show
name: DOUBLE-STRUCK CAPITAL N
old-name: DOUBLE-STRUCK N
general-category: Lu (Letter, Uppercase)
decomposition: (font 78) (font 'N')
Important part: display: no font available.
It should be possible to set that in our .Xresources file:
With the X resource ‘Emacs.Font’, you can specify a fontset name
just like an actual font name.
I do not know what is a proper syntax for that though.
Before that change I was able to see a lot of unicode glyphs not supported by my font of choice.
After that change — I can only see one font in my Emacs and empty boxes-placeholders for glyphs not supported by it.
It works in my system and should be enough for now before someone
else give you a detailed, technical and correct answer.
(set-fontset-font t nil MY-FONT)
whereMY-FONT
is the name of your font?describe-char
).(set-fontset-font t nil "fontset-default")
. P.S.: It's necessary to set thedefault
face (Menu bar:Options > Set Default Font... > {choose font}
thenOptions > Save Options
).