opened 09:00AM - 02 Jun 16 UTC
closed 01:11PM - 23 Jan 21 UTC
Fonts
Microsoft Windows
Running as daemon
- Bug tracker -
stale
In my `~/.spacemacs.d/init.el` I have:
``` lisp
dotspacemacs-default-font '(… "DejaVu Sans Mono-12"
; Size etc, don't work in Windows
; :size 13
; :weight normal
; :width normal
:powerline-scale 1.1)
```
This works fine if I start Emacs normally. However, if I do `emacs.exe --daemon` I see the following in the output:
```
>emacs.exe -daemon
Loading c:/Users/UK03306/.emacs.d/core/core-load-paths.el (source)...
Loading c:/Users/UK03306/.emacs.d/core/core-load-paths.el (source)...done
Loading c:/Users/UK03306/.spacemacs.d/init.el (source)...
Loading c:/Users/UK03306/.spacemacs.d/init.el (source)...done
Setting the font...
(Spacemacs) Warning: Cannot find font "DejaVu Sans Mono-12"! Font settings may not be correct.
```
... and when I open a frame via `emacsclient -c` the default font (Courier New) is used rather than my configured font. Checking `default-frame-alist`, my font preference has not been set.
The problem seems to lie in this code in `core-spacemacs.el`:
```
(spacemacs|do-after-display-system-init
;; If you are thinking to remove this call to `message', think twice. You'll
;; break the life of several Spacemacser using Emacs in daemon mode. Without
;; this, their chosen font will not be set on the *first* instance of
;; emacsclient, at least if different than their system font. You don't
;; believe me? Go ahead, try it. After you'll have notice that this was true,
;; increase the counter bellow so next people will give it more confidence.
;; Counter = 1
(message "Setting the font...")
(if (find-font (font-spec :name (car dotspacemacs-default-font)))
(spacemacs/set-default-font dotspacemacs-default-font)
(spacemacs-buffer/warning
"Cannot find font \"%s\"! Font settings may not be correct."
(car dotspacemacs-default-font))))
```
I know that `find-font` will not find GUI fonts when called early in the initialisation in Daemon mode on Windows. At that point, there's no GUI frame and so the "current frame" used by default by `find-font` doesn't have access to the fonts available on the GUI display for some reason. However, I'm not sure that's everything that is going on here, as I checked `find-font` on a Linux machine and got a similar result.
#### System Info :computer:
- OS: windows-nt
- Emacs: 25.0.93.1
- Spacemacs: 0.105.20
- Spacemacs branch: develop (rev. 8f45a94)
- Graphic display: t
- Distribution: spacemacs
- Editing style: vim
- Completion: helm
- Layers:
``` elisp
(windows-scripts python helm auto-completion emacs-lisp)
```
这个Issue里面提到 Deamon 模式下字体不能正确设置,所以 TheBB 后来加了一句话:
syl20bnr:develop
← TheBB:font-alist
opened 11:08AM - 06 Jun 16 UTC
See https://github.com/syl20bnr/spacemacs/issues/6197#issuecomment-223926811
;; core/core-fonts-support.el
(push `(font . ,(frame-parameter nil 'font)) default-frame-alist)
但貌似这句话对中文不起作用,我是使用 chinese layer 中指定 charset 字体的方法:
;; Set the monospaced font size when mixed Chinese and English words
(defun spacemacs//set-monospaced-font (english chinese english-size chinese-size)
(set-face-attribute 'default nil :font
(format "%s:pixelsize=%d" english english-size))
(dolist (charset '(kana han cjk-misc bopomofo))
(set-fontset-font (frame-parameter nil 'font) charset
(font-spec :family chinese :size chinese-size))))
不知有何方法可以支持开新的 frame 时一并支持中文字体,感谢!
这问题貌似早就解决了,你换 develop 分支试试?
我看 develop history 里面并没啥变化,不知你说的是在那个函数里解决的呢?
提问的时候的推荐问题并不相关,但怪我没有在论坛里面搜索。抱歉隔年坟哈哈哈,谢谢了!