【问题标题】:How to set font-size to an evaluated value in emacs?如何将字体大小设置为 emacs 中的评估值?
【发布时间】:2019-11-22 02:00:49
【问题描述】:

我是 emacs lisp 的新手,并尝试将关键字值设置为如下所示的评估表达式:

(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(default ((t (:height (+ 70 70)))))
)

请注意,最初的高度是一个静态值140,它运行良好。但是,当我将其更改为表达式时,它因 msg 失败:

error: Default face height not absolute and positive, +, 70, 70

我尝试这样做的原因是我在具有不同屏幕尺寸的多台计算机上共享相同的.emacs 文件。所以我的最终目标是根据屏幕大小计算字体大小。

将关键字值设置为表达式的正确方法是什么?

【问题讨论】:

  • 如果您手动对自定义部分进行更改,那么如果使用内置方法再次保存自定义,这些更改可能会有些丢失。例如,你可以将 70 + 70 计算为 140,但是下次通过普通的内置方法保存自定义时,该值将是 140,而不是拼写为 70 + 70。话虽如此,你可以尝试更改单引用反引号并在要评估的部分之前放置逗号;即,尝试:`(default ((t (:height ,(+ 70 70))))) 。请参阅:gnu.org/software/emacs/manual/html_node/elisp/Backquote.html 您可以在自定义之外执行此操作。
  • @lawlist 谢谢。像魅力一样工作

标签: fonts emacs


【解决方案1】:

你可以完全按照法律清单所说的去做,这是完全合理的。如果您想在自定义之外执行此操作:

(set-face-attribute 'default nil :height (+ 70 70))

不需要准引号,因为表达式一开始就没有被引用。

【讨论】:

    【解决方案2】:

    我有类似的设置,我经常插拔显示器并使用 Mac Retina 显示器。

    我发现default-text-scale 效果很好。如果您的设置使用use-package,这是我配置的。

    (use-package default-text-scale
        :ensure t
        :config
        (setq default-text-scale-amount 8)
        :bind
        ;; Plus makes it better
        ("M-+" . default-text-scale-increase)
        ;; Underscore makes it smaller (- is already bound)
        ("M-_" . default-text-scale-decrease))
    

    它不能解决您的具体问题,但它适用于所有窗口并调整字体大小。如果您需要演示,它会派上用场。

    【讨论】:

      【解决方案3】:

      您可以做您尝试做的事情,但使用经过评估的代码,而不是受quote 保护免于评估的代码。例如,使用 backquote 表达式:将引号更改为反引号,并在要评估的 sexp 之前放置一个逗号。

      (custom-set-faces
       `(default ((t (:height ,(+ 70 70))))))
      

      相当于这样:

      (custom-set-faces
       (list 'default (list (list t (list :height (+ 70 70))))))
      

      【讨论】:

        猜你喜欢
        • 2010-09-22
        • 2013-09-29
        • 1970-01-01
        • 2018-03-21
        • 1970-01-01
        • 2021-04-07
        • 1970-01-01
        • 2021-07-31
        • 1970-01-01
        相关资源
        最近更新 更多