branch: elpa/magit
commit 2b6516e04431c339a41887b27ce6a1193df6e9c3
Author: Jonas Bernoulli <jo...@bernoul.li>
Commit: Jonas Bernoulli <jo...@bernoul.li>

    magit-blame-mode: Restore previous margin width
    
    When turning off `magit-blame-mode' or switching to a style, which
    doesn't use the margin, restore the width of the left margin to the
    width that was used before the mode was enabled.
    
    Closes #5236.
---
 CHANGELOG           |  8 ++++++++
 lisp/magit-blame.el | 17 +++++++++++++----
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index a9d6c26ca3a..f5fee0d53de 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,4 +1,12 @@
 # -*- mode: org -*-
+* v4.1.2    UNRELEASED
+
+Bug fixes:
+
+- If the left margin was in use before ~magit-blame-mode~ started using
+  that margin, then the old width was not restored when the mode was
+  disabled.  #5236
+
 * v4.1.1    2024-10-01
 
 - Avoid unnecessary work when ~auto-revert-remote-files~ is ~nil~.  #5222
diff --git a/lisp/magit-blame.el b/lisp/magit-blame.el
index 7acddadb661..fe5a210a15d 100644
--- a/lisp/magit-blame.el
+++ b/lisp/magit-blame.el
@@ -346,7 +346,7 @@ in `magit-blame-read-only-mode-map' instead."
                (and (cl-find-if (lambda (style)
                                   (assq 'margin-format (cdr style)))
                                 magit-blame-styles)))
-         (magit-blame--update-margin))
+         (magit-blame--update-margin 'enable))
         (t
          (when (process-live-p magit-blame-process)
            (kill-process magit-blame-process)
@@ -365,7 +365,7 @@ in `magit-blame-read-only-mode-map' instead."
          (kill-local-variable 'magit-blame-disabled-modes)
          (kill-local-variable 'magit-blame-type)
          (kill-local-variable 'magit-blame--style)
-         (magit-blame--update-margin)
+         (magit-blame--update-margin 'disable)
          (magit-blame--remove-overlays))))
 
 (defun magit-blame--refresh ()
@@ -537,6 +537,8 @@ modes is toggled, then this mode also gets toggled 
automatically.
 
 ;;; Display
 
+(defvar-local magit-blame--previous-margin-width nil)
+
 (defsubst magit-blame--style-get (key)
   (cdr (assoc key (cdr magit-blame--style))))
 
@@ -604,8 +606,15 @@ modes is toggled, then this mode also gets toggled 
automatically.
     (overlay-put ov 'magit-blame-highlight t)
     (magit-blame--update-highlight-overlay ov)))
 
-(defun magit-blame--update-margin ()
-  (setq left-margin-width (or (magit-blame--style-get 'margin-width) 0))
+(defun magit-blame--update-margin (&optional action)
+  (when (eq action 'enable)
+    (setq magit-blame--previous-margin-width left-margin-width))
+  (setq left-margin-width
+        (if (eq action 'disable)
+            (prog1 magit-blame--previous-margin-width
+              (setq magit-blame--previous-margin-width nil))
+          (or (magit-blame--style-get 'margin-width)
+              magit-blame--previous-margin-width)))
   (set-window-buffer (selected-window) (current-buffer)))
 
 (defun magit-blame--update-overlays ()

Reply via email to