emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/visual-fill-column 159dcee48e 051/137: Make sure we only a


From: ELPA Syncer
Subject: [nongnu] elpa/visual-fill-column 159dcee48e 051/137: Make sure we only affect margins of buffers with v-f-c-mode enabled.
Date: Sun, 2 Jan 2022 22:59:11 -0500 (EST)

branch: elpa/visual-fill-column
commit 159dcee48e7311ee816686d62e7ce36619127462
Author: Joost Kremers <joostkremers@fastmail.fm>
Commit: Joost Kremers <joostkremers@fastmail.fm>

    Make sure we only affect margins of buffers with v-f-c-mode enabled.
    
    This fixes #22.
---
 visual-fill-column.el | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/visual-fill-column.el b/visual-fill-column.el
index aeb1df6826..1050142ba1 100644
--- a/visual-fill-column.el
+++ b/visual-fill-column.el
@@ -93,8 +93,8 @@ in which `visual-line-mode' is active as well."
 (defun visual-fill-column-mode--disable ()
   "Disable `visual-fill-column-mode' for the current buffer."
   (remove-hook 'window-configuration-change-hook 
#'visual-fill-column--adjust-window 'local)
-  (set-window-fringes (selected-window) nil)
-  (set-window-margins (selected-window) 0 0))
+  (set-window-fringes (get-buffer-window (current-buffer)) nil)
+  (set-window-margins (get-buffer-window (current-buffer)) nil))
 
 (defun visual-fill-column-split-window (&optional window size side pixelwise)
   "Split WINDOW, unsetting its margins first.
@@ -105,7 +105,7 @@ function is for use in the window parameter `split-window'."
     (when horizontal
       ;; Reset margins.
       (setq margins (window-margins window))
-      (set-window-margins window nil nil))
+      (set-window-margins window nil))
     ;; Now try to split the window.
     (set-window-parameter window 'split-window nil)
     (unwind-protect
@@ -129,7 +129,8 @@ windows with wide margins."
   (let ((margins (window-margins window))
         new)
     ;; unset the margins and try to split the window
-    (set-window-margins window nil nil)
+    (when (buffer-local-value 'visual-fill-column-mode (window-buffer window))
+      (set-window-margins window nil))
     (unwind-protect
         (setq new (split-window-sensibly window))
       (when (not new)
@@ -137,10 +138,12 @@ windows with wide margins."
 
 (defun visual-fill-column--adjust-window ()
   "Adjust the window margins and fringes."
-  (set-window-fringes (selected-window) nil nil 
visual-fill-column-fringes-outside-margins)
-  (if (>= emacs-major-version 25)
-      (set-window-parameter (selected-window) 'split-window 
#'visual-fill-column-split-window))
-  (visual-fill-column--set-margins))
+  ;; Only run when we're really looking at a buffer that has v-f-c-mode 
enabled. See #22.
+  (when (buffer-local-value 'visual-fill-column-mode (window-buffer 
(selected-window)))
+    (set-window-fringes (get-buffer-window (current-buffer)) nil nil 
visual-fill-column-fringes-outside-margins)
+    (if (>= emacs-major-version 25)
+        (set-window-parameter (get-buffer-window (current-buffer)) 
'split-window #'visual-fill-column-split-window))
+    (visual-fill-column--set-margins)))
 
 (defun visual-fill-column-adjust (&optional _inc)
   "Adjust the window margins and fringes.
@@ -157,7 +160,7 @@ area plus the margins, but excluding the fringes, scroll 
bar and
 right divider.  WINDOW defaults to the selected window.  The
 return value is scaled to account for `text-scale-mode-amount'
 and `text-scale-mode-step'."
-  (or window (setq window (selected-window)))
+  (or window (setq window (get-buffer-window (current-buffer))))
   (let* ((margins (window-margins window))
          (buffer (window-buffer window))
          (scale (if (and (boundp 'text-scale-mode-step)
@@ -174,7 +177,7 @@ and `text-scale-mode-step'."
 (defun visual-fill-column--set-margins ()
   "Set window margins for the current window."
   ;; calculate left & right margins
-  (let* ((window (selected-window))
+  (let* ((window (get-buffer-window (current-buffer)))
          (total-width (visual-fill-column--window-max-text-width window))
          (width (or visual-fill-column-width
                     fill-column))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]