Hatena::ブログ(Diary)

わからん

2011.03.26

[] vc-annotate-goto-line()

行単位で誰がいつ編集したかを調べられる git annotate, svn annotate などを emacs から統一的に扱うのが vc-annotate() 。 その画面から、元ファイルへ移動するのが、以下の vc-annotate-goto-line()。 emacs-devel だけあって(?)、渋いコマンドが紹介されています。RET に割り当ててみました。

(defun vc-annotate-goto-line ()
  (interactive)
  (unless (eq major-mode 'vc-annotate-mode)
    (error "vc-annotate-goto-line must be used on a VC-Annotate buffer"))
  (let* ((name (buffer-name))
         (base (and (string-match "Annotate \\(.*\\) (rev" name)
                    (match-string 1 name)))
         (line (save-restriction
                 (widen)
                 (line-number-at-pos))))
    (with-current-buffer (get-buffer base)
      ;; (pop-to-buffer (current-buffer)) 
      (switch-to-buffer (current-buffer)) ;ウィンドウ分割が嫌なので s/pop-to-buffer/switch-to-buffer/ しました
      (save-restriction
        (widen)
        (goto-char (point-min))
        (forward-line (1- line))
        (recenter)))))

(add-hook 'vc-annotate-mode-hook
          (lambda ()
            (define-key vc-annotate-mode-map (kbd "RET") 'vc-annotate-goto-line)))

はてなユーザーのみコメントできます。はてなへログインもしくは新規登録をおこなってください。

Google