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

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

[nongnu] elpa/git-commit 84922c3997: magit-show-commit: Fix handling of


From: ELPA Syncer
Subject: [nongnu] elpa/git-commit 84922c3997: magit-show-commit: Fix handling of current buffer's file
Date: Wed, 11 May 2022 23:58:10 -0400 (EDT)

branch: elpa/git-commit
commit 84922c3997980a44f9fa2702a4e7db678adf98f8
Author: Kyle Meyer <kyle@kyleam.com>
Commit: Kyle Meyer <kyle@kyleam.com>

    magit-show-commit: Fix handling of current buffer's file
    
    If magit-file-relative-name returns a file for the current buffer,
    magit-show-commit expects the file's buffer to remain the current
    buffer when calling save-buffer and line-number-at-pos.  However,
    these calls are downstream of a magit-revision-setup-buffer call that
    may have changed the current buffer to the revision buffer, depending
    on the value of magit-display-buffer-noselect.
    
    Due to the location of this line-number-at-pos call, invoking
    magit-show-commit on a blame chunk does _not_ put point on the
    relevant line while magit-diff-show-or-scroll-up does, because the
    latter binds magit-display-buffer-noselect to t.
    
    Move the save-buffer and line-number-at-pos calls before the
    magit-revision-setup-buffer call.
---
 lisp/magit-diff.el | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/lisp/magit-diff.el b/lisp/magit-diff.el
index 1687ef1382..4ce51cbebb 100644
--- a/lisp/magit-diff.el
+++ b/lisp/magit-diff.el
@@ -1325,18 +1325,19 @@ for a revision."
            (and mcommit
                 (magit-section-parent-value (magit-current-section))))))
   (require 'magit)
-  (let ((file (magit-file-relative-name)))
+  (let* ((file (magit-file-relative-name))
+         (ln (and file (line-number-at-pos))))
     (magit-with-toplevel
       (when module
         (setq default-directory
               (expand-file-name (file-name-as-directory module))))
       (unless (magit-commit-p rev)
         (user-error "%s is not a commit" rev))
+      (when file
+        (save-buffer))
       (let ((buf (magit-revision-setup-buffer rev args files)))
         (when file
-          (save-buffer)
-          (let ((line (magit-diff-visit--offset file (list "-R" rev)
-                                                (line-number-at-pos)))
+          (let ((line (magit-diff-visit--offset file (list "-R" rev) ln))
                 (col (current-column)))
             (with-current-buffer buf
               (magit-diff--goto-position file line col))))))))



reply via email to

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