C-x v = vc-diff
很好。magit-status
但是,如果差异显示在缓冲区中,我可以直接使用差异。
我试图在这里做到这一点:
(defvar le::vc-diff-data nil)
(defun le::magit-go-to-change-once ()
(destructuring-bind (filename orig-buff relative-name) le::vc-diff-data
(pop-to-buffer "*magit: magit*")
(goto-char (point-min))
(if (and (search-forward-regexp "^Changes:$" nil t)
;; WIP fix
(progn (magit-show-level-2) t)
(search-forward relative-name nil t))
(progn (recenter-top-bottom 0)
;; WIP fix me here
(magit-show-level-4)
)
;; no diff
(pop-to-buffer orig-buf)
(message "no diff found.")))
(remove-hook 'magit-refresh-status-hook #'le::magit-go-to-change-once))
(defadvice vc-diff (around magit-redirect activate compile)
"redirect to magit"
(let* ((vc-info (vc-deduce-fileset t))
(filename (buffer-file-name))
(orig-buf (current-buffer))
(relative-name (replace-regexp-in-string
(concat "\\`"
(regexp-quote (expand-file-name (locate-dominating-file filename ".git"))))
"" filename)))
(if (string-equal "Git" (car vc-info))
(progn
(setq le::vc-diff-data (list filename orig-buf relative-name))
(add-hook 'magit-refresh-status-hook #'le::magit-go-to-change-once)
(call-interactively 'magit-status))
ad-do-it)))
但是“magit-show-level*”功能失败。不过,当我
eval-expression
在 magit 缓冲区中使用时,它可以工作。所以也许这是一个时间问题,我必须在其他地方挂上钩。