From 9394869bb30f3d7a750e3df4c6b4a50893a44b87 Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Wed, 4 Feb 2026 16:28:48 -0500 Subject: [PATCH] fix(visual-fill-column): improve line number detection --- config.org | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/config.org b/config.org index 03d3b83..74370fb 100644 --- a/config.org +++ b/config.org @@ -1304,17 +1304,23 @@ 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. #+begin_src emacs-lisp -(add-hook! display-line-numbers-mode +(defun ~/update-visual-fill-column-line-numbers (&optional _s _e _len) (require 'visual-fill-column) - (setq-local - visual-fill-column-extra-text-width - (cons 0 (if display-line-numbers-mode - ;; Width of line number + 2 padding columns - (+ 2 (line-number-display-width)) - 0))) - (visual-fill-column--adjust-window)) + (let ((dw (line-number-display-width))) + ;; 2 extra columns for padding (when line numbers are on) + (when display-line-numbers + (setq dw (+ dw 2))) + (unless (= dw (or (cdr visual-fill-column-extra-text-width) 0)) + (setq-local visual-fill-column-extra-text-width + (cons 0 dw)) + (visual-fill-column--adjust-window)))) + +(add-hook! '(display-line-numbers-mode-hook post-command-hook doom-switch-buffer-hook) + #'~/update-visual-fill-column-line-numbers) #+end_src +We unfortunately have to make this check /very/ often, anywhere that could conceivably change the output of ~line-number-display-width~. This includes all buffer movement commands, which unfortunately don't have a hook + ** Dashboard #+call: confpkg("Dashboard")