3

我正在尝试为 emacsclient 设置我的字体,如下所示:

(let ((default-font (cond
                     ((member "Inconsolata" (font-family-list))
                      "Inconsolata 14")
                     (t
                      "monospace 20"))))
  (set-default-font default-font)
  (add-to-list 'default-frame-alist `(font . ,default-font)))

C-x C-econd性交,它返回"Inconsolata 14"。我C-x C-elet性交和字体更新。

当我通过

$ emacs

它可以工作(字体设置为 Inconsolata 14)。

但是,当我通过启动应用程序时

$ emacsclient --alternate-editor="" --create-frame "$@"

字体改为等宽 20。

请指教。

编辑:

我发现通过包括

(message "%s" (font-family-list))

在emacsclient 启动时(font-family-list)返回的我的 .emacs 文件中。nil

不幸的是,也在初始化期间:

;; Both also print `nil` to the `*Messages*` buffer.
(message "%s" (find-font (font-spec :name "inconsolata")))
(message "%s" (find-font (font-spec :name "Inconsolata")))

;; Throws "error: No fonts being used"
(message "%s" (describe-font "Inconsolata"))

我不知道如何检测初始化期间是否安装了字体。我的问题变成了:如何在 emacsclient 启动时可靠地检查字体是否可用?

编辑2:

after-init-hook, emacs-startup-hook, window-setup-hook,中回显before-make-frame-hookafter-make-frame-functions也会导致nil.

4

4 回答 4

3

叹息...也对这个问题感到恼火,但我找到了 Emacs Lisp 解决方案。这是我的 Emacs 配置中相应片段的直接复制/粘贴:

(defun frame-font-setup
    (&rest ...)
  ;; (remove-hook 'focus-in-hook #'frame-font-setup)
  (unless (assoc 'font default-frame-alist)
    (let* ((font-family (catch 'break
                          (dolist (font-family
                                   '("Powerline Consolas"
                                     "Consolas for Powerline"
                                     "Consolas"
                                     ;;
                                     "Powerline Inconsolata-g"
                                     "Inconsolata-g for Powerline"
                                     "Inconsolata-g"
                                     ;;
                                     "Powerline Source Code Pro"
                                     "Source Code Pro for Powerline"
                                     "Source Code Pro"
                                     ;;
                                     "Powerline DejaVu Sans Mono"
                                     "DejaVu Sans Mono for Powerline"
                                     "DejaVu Sans Mono"
                                     ;;
                                     "Monospace"))
                            (when (member font-family (font-family-list))
                              (throw 'break font-family)))))
           (font (when font-family (format "%s-12" font-family))))
      (when font
        (add-to-list 'default-frame-alist (cons 'font font))
        (set-frame-font font t t)))))
(add-hook 'focus-in-hook #'frame-font-setup)

嗯……[高兴]

于 2015-11-01T02:36:43.487 回答
2

当您将 Emacs 作为守护程序启动时(由 emacsclient 按需隐式完成),在 Emacs 连接到任何“显示设备”(又名“终端”)之前加载 .emacs,即它没有连接到任何GUI 也没有任何 tty。相反,它的终端是一个虚拟设备,它从标准输入读取并将输出发送到标准输出(好吧,在开始时和之后不久,即使该通信链接被切断),所以那里没有字体。

获得您想要的东西的一种方法是执行以下操作:

(add-to-list face-font-family-alternatives '("myfont" "Inconsolata" "Monospace"))

然后自定义default脸部以使用字体系列myfont。您可能仍然对字体大小有问题,在这种情况下,您可能需要使用face-font-rescale-alist.

于 2014-08-09T19:23:37.810 回答
2

我设法在 emacs subreddit的这篇文章中找到了答案。

这是我输入的代码片段init.el

(defun rag-set-face (frame)
  "Configure faces on frame creation"
  (select-frame frame)
  (if (display-graphic-p)
      (progn
        (when (member "PragmataPro" (font-family-list))
            (set-frame-font "PragmataPro-13")))))
于 2016-12-28T03:34:45.347 回答
0

单独使用 elisp 似乎几乎是不可能的,所以我已经解决了fc-list. 这行得通。

(let ((default-font (cond
                     ((and
                       (eq system-type 'gnu/linux)
                       (null (string= "" (shell-command-to-string "which fc-list")))
                       (null (string= "" (shell-command-to-string "fc-list inconsolata"))))
                      "Inconsolata 14")
                     (t
                      "monospace 12"))))
  (set-default-font default-font)
  (add-to-list 'default-frame-alist `(font . ,default-font)))
于 2014-08-09T20:44:52.287 回答