emacs how to reload fonts from system?
- User
User: emacs how to reload fonts from system? Assistant: InIn Emacs, if you have updated or installed new system fonts and want Emacs to recognize and use them without restarting the entire Emacs session, you generally need to reload or refresh the font cache that Emacs uses.
However, Emacs does not have a built-in command that explicitly "reloads" system fonts on the fly because font loading is typically done at startup or when you explicitly set fonts in Emacs. But you can try the following approaches:
Method 1: Reinitialize fontsets
You can try to reset the default font or modify the fontset to force Emacs to re-read fonts from the system:
elisp(set-frame-font nil t)or explicitly set a font you know is newly installed:
elisp(set-frame-font "YourFontName-12" t t)This forces Emacs to reload the font for the current frame.
Method 2: Restart Emacs
The surest way to get Emacs to pick up new system-installed fonts is to fully restart Emacs.
Method 3: Use
fontset-reload(Emacs 28+)Starting with Emacs 28, there is a function
fontset-reloadto reload fontsets:elisp(fontset-reload)But note: this reloads Emacs fontsets, but it may not force Emacs to scan newly installed system fonts if the font availability changed externally.
Method 4: Use
fc-cacheOn Linux systems, you normally run
fc-cache -fvin the terminal to update the font cache, but this is outside Emacs. After that, restart Emacs or reload fonts as above.
Summary
- To reload fonts inside Emacs without restart, set the frame font again with
set-frame-font. - For newer Emacs (28+), try
(fontset-reload). - Otherwise, restart Emacs after updating system fonts.
- Make sure your OS font cache is up-to-date (outside Emacs with
fc-cacheor OS tools).
If you want a quick snippet to reload font in current frame:
elisp(set-frame-font (face-attribute 'default :font) nil t)This resets the font on the current frame using the existing default font, effectively refreshing font information.
Let me know if you want help with a specific platform or Emacs version! User: Emacs how to set font only for string face? (set-frame-font "JetBrainsMono Nerd Font 16" nil t) Assistant:
- To reload fonts inside Emacs without restart, set the frame font again with
- Assistant
To set the font only for a specific face, such as the built-in
stringface in Emacs (which is used to display strings in code), you should customize its font separately instead of setting the frame font globally.Here’s how you can do it:
elisp(set-face-attribute 'font-lock-string-face nil :font "JetBrainsMono Nerd Font-16")Explanation:
'font-lock-string-faceis the face used for strings in most major modes (programming modes).nilmeans apply to the current frame (or all frames if you call it early during startup).