]> git.eshelyaron.com Git - emacs.git/commitdiff
Take better care when setting margins in erc-stamp
authorF. Jason Park <jp@neverwas.me>
Mon, 10 Apr 2023 07:08:37 +0000 (00:08 -0700)
committerF. Jason Park <jp@neverwas.me>
Mon, 10 Apr 2023 20:42:29 +0000 (13:42 -0700)
* lisp/erc/erc-stamp.el (erc-stamp--adjust-right-margin,
erc-stamp--display-margin-mode): Prefer setting
`fringes-outside-margins' to hiding right margin, and check whether
current buffer is showing before adjusting anything.  (Bug#60936.)

lisp/erc/erc-stamp.el

index 8bca9bdb56b94ebe3881ff17c08e5bfdf449eedc..61f289a8753c2555c111f4a981ce6559666f3442 100644 (file)
@@ -302,10 +302,9 @@ or one col more than the `string-width' of
                                         (current-time)
                                         erc-timestamp-format)))))
            (+ right-margin-width cols))))
-    (setq right-margin-width width
-          right-fringe-width 0)
-    (set-window-margins nil left-margin-width width)
-    (set-window-fringes nil left-fringe-width 0)))
+    (setq right-margin-width width)
+    (when (eq (current-buffer) (window-buffer))
+      (set-window-margins nil left-margin-width width))))
 
 ;;;###autoload
 (defun erc-stamp-prefix-log-filter (text)
@@ -344,6 +343,9 @@ message text so that stamps will be visible when yanked."
   :interactive nil
   (if erc-stamp--display-margin-mode
       (progn
+        (setq fringes-outside-margins t)
+        (when (eq (current-buffer) (window-buffer))
+          (set-window-buffer (selected-window) (current-buffer)))
         (erc-stamp--adjust-right-margin 0)
         (add-function :filter-return (local 'filter-buffer-substring-function)
                       #'erc--remove-text-properties)
@@ -354,9 +356,10 @@ message text so that stamps will be visible when yanked."
     (remove-function (local 'erc-insert-timestamp-function)
                      #'erc-stamp--display-margin-force)
     (kill-local-variable 'right-margin-width)
-    (kill-local-variable 'right-fringe-width)
-    (set-window-margins nil left-margin-width nil)
-    (set-window-fringes nil left-fringe-width nil)))
+    (kill-local-variable 'fringes-outside-margins)
+    (when (eq (current-buffer) (window-buffer))
+      (set-window-margins nil left-margin-width nil)
+      (set-window-buffer (selected-window) (current-buffer)))))
 
 (defun erc-insert-timestamp-left (string)
   "Insert timestamps at the beginning of the line."