summaryrefslogtreecommitdiff
path: root/lisp/init-git.el
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2016-01-09 03:30:07 -0500
committerKyle Meyer <kyle@kyleam.com>2016-01-09 03:30:07 -0500
commit2f8756246fd3edbd12daf8997bd0a831ca905e8c (patch)
tree3ae3bdd780a2b4f22d6bc6e803b6e485325b0e8b /lisp/init-git.el
parent6ea21024f7a30fd24cfcd44222247d5145b41473 (diff)
downloademacs.d-2f8756246fd3edbd12daf8997bd0a831ca905e8c.tar.gz
Add wrapper around magit-diff-visit-file
Diffstat (limited to 'lisp/init-git.el')
-rw-r--r--lisp/init-git.el30
1 files changed, 30 insertions, 0 deletions
diff --git a/lisp/init-git.el b/lisp/init-git.el
index 678231d..85ef138 100644
--- a/lisp/init-git.el
+++ b/lisp/init-git.el
@@ -591,6 +591,29 @@ show tags by default."
((derived-mode-p 'magit-log-mode)
(call-interactively #'km/magit-log-flip-revs))))
+(defun km/magit-diff-visit-file (&optional prev-rev other-window)
+ "Like `magit-diff-visit-file', but with the option to visit REV^.
+
+If prefix argument PREV-REV is non-nil, visit file for REV^
+instead of REV. If not in `magit-revision-mode', the prefix
+argument has no effect.
+
+OTHER-WINDOW corresponds to `magit-diff-visit-file's OTHER-WINDOW
+argument. Interactively, this can be accessed using the command
+`km/magit-diff-visit-file-other-window'."
+ (interactive "P")
+ (let ((magit-refresh-args (if (and prev-rev
+ (derived-mode-p 'magit-revision-mode))
+ (cons (concat (car magit-refresh-args) "^")
+ (cdr magit-refresh-args))
+ magit-refresh-args))
+ (current-prefix-arg (and other-window (list 4))))
+ (call-interactively #'magit-diff-visit-file)))
+
+(defun km/magit-diff-visit-file-other-window (&optional prev-rev)
+ (interactive "P")
+ (km/magit-diff-visit-file prev-rev t))
+
(define-key ctl-x-4-map "g" 'magit-find-file-other-window)
(define-key km/file-map "g" 'magit-find-file)
@@ -607,6 +630,8 @@ show tags by default."
;; `magit-diff-visit-file-worktree' is also on C-RET.
(define-key magit-file-section-map (kbd "C-j") 'magit-diff-visit-file-worktree)
(define-key magit-hunk-section-map (kbd "C-j") 'magit-diff-visit-file-worktree)
+(define-key magit-file-section-map (kbd "C-o") 'km/magit-diff-visit-file-other-window)
+(define-key magit-hunk-section-map (kbd "C-o") 'km/magit-diff-visit-file-other-window)
(define-key magit-log-mode-map "j" 'km/magit-avy-goto-subword-1)
(define-key magit-refs-mode-map "j" 'km/magit-avy-goto-subword-1)
@@ -614,6 +639,11 @@ show tags by default."
(define-key magit-refs-mode-map (kbd "C-c C-t") 'km/magit-refs-toggle-tags)
+(define-key magit-file-section-map [remap magit-visit-thing]
+ 'km/magit-diff-visit-file)
+(define-key magit-hunk-section-map [remap magit-visit-thing]
+ 'km/magit-diff-visit-file)
+
(define-key magit-refs-mode-map (kbd "C-c C-f") 'km/magit-refs-filter-recent)
(define-key magit-process-mode-map (kbd "C-c C-k") 'magit-process-kill)