linum 模式下 Emacs 的字体大小问题

linum 模式下 Emacs 的字体大小问题

我使用的是 Emacs 23。线性模式如果使用默认设置,效果很好。

但是如果我增加字体大小,数字就无法显示。随着行号字体大小的增加,显示行号的框架似乎没有增加。

有人知道如何解决这个问题吗?

答案1

您可以在初始化配置中定义 linum 大小,这样它就不会依赖于default-face

(set-face-attribute 'linum nil :height 100)

如果您不使用linum-mode全局默认值(即,例如主模式挂钩),请set-face-attribute在加载时评估该命令,否则您将收到invalid face: linum错误:

(eval-after-load "linum"
  '(set-face-attribute 'linum nil :height 100))

如果您使用相对模式,也值得为此模式调整脸部。

(set-face-attribute 'linum-relative-current-face nil :height 100)

答案2

这是一个在我的设置中运行良好的解决方法,但我的 emacs 知识相当有限,而且我不确定它在其他人的设置中会如何表现,但它是:

因为行号栏才不是改变宽度的同时改变字体大小更改时,我采取的方法是防止行号的字体大小变得比其列宽。

我还没有找到一种方法(即函数)来确定特定比例的行号列的必要高度,因此我根据来自相当标准的 emacs 的经验数据构建了一个列表。该列表相对于text-scale-mode-step= 1.04... 进行缩放。此外,text-scale-mode-amount需要初始化,因为它似乎仅由文本缩放函数触发,但需要0通过解决方法函数进行首次计算。

编辑:缩小现在可以正确缩放,但我仍在寻找一种更好的方法来评估/控制行号列的字体高度,因此如果有人对此有任何想法,我将不胜感激。

;; This script is set for a `text-scale-mode-step` of `1.04`
(setq text-scale-mode-step 1.04)
;;
;; List: `Sub-Zoom Font Heights per text-scale-mode-step`  
;;   eg.  For a default font-height of 120 just remove the leading `160 150 140 130` 
(defvar sub-zoom-ht (list 160 150 140 130 120 120 110 100 100  90  80  80  80  80  70  70  60  60  50  50  50  40  40  40  30  20  20  20  20  20  20  10  10  10  10  10  10  10  10  10  10   5   5   5   5   5   2   2   2   2   2   2   2   2   1   1   1   1   1   1   1   1   1   1   1   1))
(defvar sub-zoom-len (safe-length sub-zoom-ht))
(defvar def-zoom-ht (car sub-zoom-ht))
(set-face-attribute 'default nil :height def-zoom-ht)

(defun text-scale-adjust-zAp ()
   (interactive)
   (text-scale-adjust 0)
   (set-face-attribute 'linum nil :height def-zoom-ht)
 )
(global-set-key [C-kp-multiply] 'text-scale-adjust-zAp)

(defun text-scale-decrease-zAp ()
   (interactive)
   (if (not (boundp 'text-scale-mode-amount)) ;; first-time init  
              (setq  text-scale-mode-amount 0))
   (setq text-scale (round (/ (* 1 text-scale-mode-amount) 
                                   text-scale-mode-step)))
   (if (> text-scale (- 1 sub-zoom-len))
       (progn
         (text-scale-decrease text-scale-mode-step)
         (if (<= 0 text-scale-mode-amount)
             (set-face-attribute 'linum nil :height def-zoom-ht)
           (if (> 0 text-scale-mode-amount)
               (set-face-attribute 'linum nil :height 
                                     (elt sub-zoom-ht (- 0 text-scale)))))))
)
(global-set-key [C-kp-subtract] 'text-scale-decrease-zAp)

(defun text-scale-increase-zAp ()
   (interactive)
   (if (not (boundp 'text-scale-mode-amount)) ;; first-time init  
              (setq  text-scale-mode-amount 0))
   (setq text-scale (round (/ (* 1 text-scale-mode-amount) 
                                   text-scale-mode-step)))
   (if (< text-scale 85)
       (progn
         (text-scale-increase text-scale-mode-step)
         (if (< (- 0 text-scale-mode-step) text-scale-mode-amount)
             (set-face-attribute 'linum nil :height def-zoom-ht)
           (if (> 0 text-scale-mode-amount)
               (set-face-attribute 'linum nil :height 
                                     (elt sub-zoom-ht (- 0 text-scale)))))))
)
(global-set-key [C-kp-add] 'text-scale-increase-zAp)


;; Zoom font via Numeric Keypad
(global-set-key [C-kp-multiply] 'text-scale-adjust-zAp)
(global-set-key [C-kp-subtract] 'text-scale-decrease-zAp)
(global-set-key [C-kp-add]      'text-scale-increase-zAp)

;; Zoomf font via Control Mouse Wheel
(global-set-key (kbd "<C-mouse-4>") 'text-scale-increase-zAp)
(global-set-key (kbd "<C-mouse-5>") 'text-scale-decrease-zAp)

答案3

我想我可以用下面的代码解决这个问题:

(require 'linum)
(defun linum-update-window-scale-fix (win)
  "fix linum for scaled text"
  (set-window-margins win
          (ceiling (* (if (boundp 'text-scale-mode-step)
                  (expt text-scale-mode-step
                    text-scale-mode-amount) 1)
              (if (car (window-margins))
                  (car (window-margins)) 1)
              ))))
(advice-add #'linum-update-window :after #'linum-update-window-scale-fix)

(编辑:修复了一些小错误。2015-10-19 01:47 CEST)它似乎可以工作,至少在 24.5 中是这样。

相关内容