编写magit计时问题

时间:2012-10-05 11:28:11

标签: emacs elisp magit

C-x v = vc-diff很好。但是,我可以使用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 *”功能失败。它在我使用时有效 但是在magit缓冲区中eval-expression。所以这可能是一个时间问题 我必须在其他地方挂钩。

1 个答案:

答案 0 :(得分:1)

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

再见你的命题很有趣,并将它整合到magit contrib的命题中可能会很棒。