emacs 在启动时不应用我的配置



我是 emacs 新手,我目前正在我的 ~/.emacs.d/init.el 文件中设置行号,如下所示:

(setq display-line-numbers 'relative)

整个 init.el 看起来像这样:

(setq display-line-numbers 'relative)
;; set up melpa
(require 'package)
(setq package-enable-at-startup nil)
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/"))
(package-initialize)
;; set packages
(require 'evil)
(evil-mode 1)
(require 'doom-modeline)
(doom-modeline-mode 1)
(require 'sublimity)
;; (require 'sublimity-scroll)
;; (require 'sublimity-map) ;; experimental
;; (require 'sublimity-attractive)
(sublimity-mode 1)
;; (require 'smooth-scrolling)
;; (smooth-scrolling-mode 1)

;;system set values
(custom-set-variables
;; custom-set-variables 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.
'(ansi-color-faces-vector
[default bold shadow italic underline bold bold-italic bold])
'(ansi-color-names-vector
["#454545" "#cd5542" "#6aaf50" "#baba36" "#5180b3" "#ab75c3" "#68a5e9" "#bdbdb3"])
'(beacon-color "#cc6666")
'(custom-enabled-themes (quote (atom-one-dark)))
'(custom-safe-themes
(quote
("d1af5ef9b24d25f50f00d455bd51c1d586ede1949c5d2863bef763c60ddf703a" "36ca8f60565af20ef4f30783aa16a26d96c02df7b4e54e9900a5138fb33808da" "c9ddf33b383e74dac7690255dd2c3dfa1961a8e8a1d20e401c6572febef61045" "06f0b439b62164c6f8f84fdda32b62fb50b6d00e8b01c2208e55543a6337433a" "628278136f88aa1a151bb2d6c8a86bf2b7631fbea5f0f76cba2a0079cd910f7d" "82d2cac368ccdec2fcc7573f24c3f79654b78bf133096f9b40c20d97ec1d8016" default)))
'(fci-rule-color "#373b41")
'(flycheck-color-mode-line-face-to-color (quote mode-line-buffer-id))
'(frame-background-mode (quote dark))
'(package-selected-packages
(quote
(sublimity atom-one-dark-theme ample-theme color-theme-sanityinc-tomorrow doom-modeline vterm evil undo-tree)))
'(vc-annotate-background nil)
'(vc-annotate-color-map
(quote
((20 . "#cc6666")
(40 . "#de935f")
(60 . "#f0c674")
(80 . "#b5bd68")
(100 . "#8abeb7")
(120 . "#81a2be")
(140 . "#b294bb")
(160 . "#cc6666")
(180 . "#de935f")
(200 . "#f0c674")
(220 . "#b5bd68")
(240 . "#8abeb7")
(260 . "#81a2be")
(280 . "#b294bb")
(300 . "#cc6666")
(320 . "#de935f")
(340 . "#f0c674")
(360 . "#b5bd68"))))
'(vc-annotate-very-old-color nil)
'(vterm-kill-buffer-on-exit t)
'(window-divider-mode nil))
(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.
)

;; bindings
(define-key evil-insert-state-map (kbd "C-a") 'evil-normal-state) 
;; addition customization
(scroll-bar-mode -1)
;; scroll one line at a time (less "jumpy" than defaults)
(setq mouse-wheel-scroll-amount '(1 ((shift) . 1))) ;; one line at a time
(setq mouse-wheel-progressive-speed nil) ;; don't accelerate scrolling
(setq mouse-wheel-follow-mouse 't) ;; scroll window under mouse
(setq scroll-step 1) ;; keyboard scroll one line at a time

;; set evil-mode delete always goes to black hole register
(defun bb/evil-delete (orig-fn beg end &optional type _ &rest args)
(apply orig-fn beg end type ?_ args))
(advice-add 'evil-delete :around 'bb/evil-delete)

问题是 Emacs 在启动时不显示相对行号,这是我在 init.el 的第一行要求,但是如果我使用它M-x load-file <RET> ~/.emacs.d/init.el <RET>它会根据需要显示行号。

我还检查了描述变量(C-h v(中的用户初始化文件,它显示了user-init-file is a variable defined in ‘C source code’. Its value is "/Users/<USER>/.emacs.d/init.el"。所以我完全困惑为什么 emacs 在似乎加载时不能在启动时自动显示行号。

IM 使用 macOS 和 MacPort Emacs,并且不使用任何 Emacs 发行版。

该变量是缓冲区本地变量,即当您启用它时,它仅在当前缓冲区中启用,这可能不是访问当前文件的缓冲区。

使用自定义全局启用变量。当您运行M-xdescribe-variabledisplay-line-numbers时,帮助文本将包含指向自定义的链接。您可以选择"相对">值并保存该值以供将来的会话使用。

也许你想要这个?

(setq-default display-line-numbers 'relative)
(global-display-line-numbers-mode 1)

您需要使用display-line-numbers-type而不是display-line-numbers

从它的文档中:

文档:要使用的默认行号类型 "显示行号模式"。

最新更新