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

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

[nongnu] elpa/git-commit bac25e7 1/4: Avoid needless selection re-highli


From: ELPA Syncer
Subject: [nongnu] elpa/git-commit bac25e7 1/4: Avoid needless selection re-highlighting
Date: Sun, 29 Aug 2021 15:57:30 -0400 (EDT)

branch: elpa/git-commit
commit bac25e73c50fda8ed319cebb69f20e56f8bc7376
Author: Jonas Bernoulli <jonas@bernoul.li>
Commit: Jonas Bernoulli <jonas@bernoul.li>

    Avoid needless selection re-highlighting
    
    The old attempt in [1: 1301db2c2] did not work because region
    highlighting is updated more often than section highlighting
    (on redisplay, not just on post-command-hook) and the former
    always reset the state that could allow for the latter to be
    avoided.
    
    Closes #3976.
    
    1: 2015-04-29 1301db2c2e6e21beac50fa215d543c09bb8516c5
       avoid re-highlighting when moving within the same section
---
 Documentation/RelNotes/3.3.0.org |  3 +++
 lisp/magit-mode.el               |  2 +-
 lisp/magit-section.el            | 23 +++++++++++++----------
 3 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/Documentation/RelNotes/3.3.0.org b/Documentation/RelNotes/3.3.0.org
index 4443e07..5ec65ea 100644
--- a/Documentation/RelNotes/3.3.0.org
+++ b/Documentation/RelNotes/3.3.0.org
@@ -47,3 +47,6 @@
   ~magit-wip-log-current~ failed to extract the previous tips of the
   wip refs from the reflog (which is relevant when
   ~~magit-wip-merge-branch~ is nil).
+
+- An old attempt to avoid needlessly updating section highlighting
+  did not actually succeed.  #3976
diff --git a/lisp/magit-mode.el b/lisp/magit-mode.el
index 7396a26..5f29cd3 100644
--- a/lisp/magit-mode.el
+++ b/lisp/magit-mode.el
@@ -1094,8 +1094,8 @@ Run hooks `magit-pre-refresh-hook' and 
`magit-post-refresh-hook'."
                        (or (nreverse (get-buffer-window-list buffer nil t))
                            (list (selected-window))))))
         (deactivate-mark)
+        (setq magit-section-pre-command-section nil)
         (setq magit-section-highlight-overlays nil)
-        (setq magit-section-highlighted-section nil)
         (setq magit-section-highlighted-sections nil)
         (setq magit-section-unhighlight-sections nil)
         (magit-process-unset-mode-line-error-status)
diff --git a/lisp/magit-section.el b/lisp/magit-section.el
index d44074e..b9e36c6 100644
--- a/lisp/magit-section.el
+++ b/lisp/magit-section.el
@@ -357,8 +357,9 @@ Magit-Section is documented in info node `(magit-section)'."
   ;; (hack-dir-local-variables-non-file-buffer)
   (make-local-variable 'text-property-default-nonsticky)
   (push (cons 'keymap t) text-property-default-nonsticky)
+  (add-hook 'pre-command-hook #'magit-section-pre-command-hook nil t)
   (add-hook 'post-command-hook #'magit-section-update-highlight t t)
-  (add-hook 'deactivate-mark-hook #'magit-section-update-highlight t t)
+  (add-hook 'deactivate-mark-hook #'magit-section-deactivate-mark t t)
   (setq-local redisplay-highlight-region-function
               'magit-section--highlight-region)
   (setq-local redisplay-unhighlight-region-function
@@ -1240,13 +1241,20 @@ evaluated its BODY.  Admittedly that's a bit of a hack."
 
 ;;; Highlight
 
+(defvar-local magit-section-pre-command-section nil)
 (defvar-local magit-section-highlight-overlays nil)
-(defvar-local magit-section-highlighted-section nil)
 (defvar-local magit-section-highlighted-sections nil)
 (defvar-local magit-section-unhighlight-sections nil)
-(defun magit-section-update-highlight ()
+
+(defun magit-section-pre-command-hook ()
+  (setq magit-section-pre-command-section (magit-current-section)))
+
+(defun magit-section-deactivate-mark ()
+  (magit-section-update-highlight t))
+
+(defun magit-section-update-highlight (&optional force)
   (let ((section (magit-current-section)))
-    (unless (eq section magit-section-highlighted-section)
+    (when (or force (not (eq magit-section-pre-command-section section)))
       (let ((inhibit-read-only t)
             (deactivate-mark nil)
             (selection (magit-region-sections)))
@@ -1261,11 +1269,7 @@ evaluated its BODY.  Admittedly that's a bit of a hack."
         (dolist (s magit-section-unhighlight-sections)
           (run-hook-with-args-until-success
            'magit-section-unhighlight-hook s selection))
-        (restore-buffer-modified-p nil)
-        (unless (eq magit-section-highlighted-section section)
-          (setq magit-section-highlighted-section
-                (and (not (oref section hidden))
-                     section)))))
+        (restore-buffer-modified-p nil)))
     (magit-section-maybe-paint-visibility-ellipses)))
 
 (defun magit-section-highlight (section selection)
@@ -1384,7 +1388,6 @@ invisible."
              start end window rol)))
 
 (defun magit-section--unhighlight-region (rol)
-  (setq magit-section-highlighted-section nil)
   (magit-section--delete-region-overlays)
   (funcall (default-value 'redisplay-unhighlight-region-function) rol))
 



reply via email to

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