0

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 缓冲区中使用时,它可以工作。所以也许这是一个时间问题,我必须在其他地方挂上钩。

4

1 回答 1

1

正如我在评论中所说,在与部分相关的功能不起作用的时候调用了钩子。您可以从那里尝试 magit:https ://github.com/vanicat/magit/tree/t/refresh-stasus-hook ,您的代码应该可以使用它。

再见,你的提议很有趣,把它整合到 magit contrib 的提议中可能会很棒。

于 2012-10-07T14:11:30.443 回答