怎样在`which-key` buffer中不显示行号?

我的行号显示配置如下:

(use-package display-line-numbers
      :ensure nil
      :init
      (setq display-line-numbers-width-start t)
      (setq display-line-numbers-current-absolute t)
      (setq-default display-line-numbers 'visual)
      :config
      (dolist (mode '(org-mode-hook
                      term-mode-hook
                      eshell-mode-hook
                      vterm-mode-hook
                      which-key-mode-hook
                      helpful-mode-hook
                      help-mode-hook))
        (add-hook mode (lambda () (display-line-numbers-mode 0)))))

按照我的理解,既然已经(add-hook 'which-key-mode-hook (lambda () (display-line-numbers-mode 0)))了,那which-key buffer中应该没有行号了才对,但是实际上仍然存在行号。请问该如何关闭which-key-mode中的buffer呢?

If called from Lisp, toggle the mode if ARG is ‘toggle’. Enable the mode if ARG is nil, omitted, or is a positive number. Disable the mode if ARG is a negative number.

所以,请用 (display-line-numbers-mode -1)

仍然没有生效。之前即使是使用(display-line-numbers-mode 0),在org-mode, helpful-mode等地方仍然是生效了的,只有which-key buffer有问题

你似乎需要用 which-key-init-buffer-hook.

你应该反过来用,hook 只管理那些需要加行号的mode, 参考我的配置 lazycat-emacs/init-line-number.el at master · manateelazycat/lazycat-emacs · GitHub

3 个赞

感谢,使用这个方法确实就对了。

这部分配置我一开始是抄的System Crafter的,现在感觉懒猫大佬说得对,

确实需要行号的mode是少数,手动管理需要行好的地方就行了