fix(visual-fill-column): only trigger hook when active

This commit is contained in:
Kiana Sheibani 2026-02-04 17:17:45 -05:00
parent 5fb65ed973
commit 99ff48d1d3
Signed by: toki
GPG key ID: 6CB106C25E86A9F7

View file

@ -1311,7 +1311,7 @@ The =visual-fill-column= package works by expanding the window's right margin. T
When a buffer has line numbers, they can interfere with the margins and make the line smaller than it should be. We can mitigate this issue by adding extra columns to the window. When a buffer has line numbers, they can interfere with the margins and make the line smaller than it should be. We can mitigate this issue by adding extra columns to the window.
#+begin_src emacs-lisp #+begin_src emacs-lisp
(defun ~/update-visual-fill-column-line-numbers (&optional _s _e _len) (defun ~/update-visual-fill-column-line-numbers ()
(require 'visual-fill-column) (require 'visual-fill-column)
(let ((dw (line-number-display-width))) (let ((dw (line-number-display-width)))
;; 2 extra columns for padding (when line numbers are on) ;; 2 extra columns for padding (when line numbers are on)
@ -1320,7 +1320,7 @@ When a buffer has line numbers, they can interfere with the margins and make the
(unless (= dw (or (cdr visual-fill-column-extra-text-width) 0)) (unless (= dw (or (cdr visual-fill-column-extra-text-width) 0))
(setq-local visual-fill-column-extra-text-width (setq-local visual-fill-column-extra-text-width
(cons 0 dw)) (cons 0 dw))
(visual-fill-column--adjust-window)))) (visual-fill-column-adjust))))
(add-hook! '(display-line-numbers-mode-hook post-command-hook doom-switch-buffer-hook) (add-hook! '(display-line-numbers-mode-hook post-command-hook doom-switch-buffer-hook)
#'~/update-visual-fill-column-line-numbers) #'~/update-visual-fill-column-line-numbers)