@peccul is peccu

(love peccu '(emacs lisp cat outdoor bicycle mac linux coffee))

Emacsのmode-lineにブランチ名を表示する(ちょっと短い版)

Git Flowに従って開発しているとmode-lineに表示されるブランチ名がかなり長くなります。

syohexさんの下記設定を少し変更しました。

d.hatena.ne.jp

(2015/5/11 追記) ※末尾追記の通り、リージョン選択が正しく動作しなくなりました。 (追記終わり)

;; Show Git branch information to mode-line
(let ((cell (or (memq 'mode-line-position mode-line-format)
                (memq 'mode-line-buffer-identification mode-line-format)))
      (newcdr '(:eval (my/update-git-branch-mode-line))))
  (unless (member newcdr mode-line-format)
    (setcdr cell (cons newcdr (cdr cell)))))

(defun my/update-git-branch-mode-line ()
  (let* ((branch (replace-regexp-in-string
                  "[\r\n]+\\'" ""
                  (shell-command-to-string "git symbolic-ref -q HEAD")))
         (mode-line-str (if (string-match "^refs/heads/" branch)
                            (cond
                             ((string-match "^refs/heads/feature/" branch)
                              (format "[f/%s]" (substring branch 19)))
                             ((string-match "^refs/heads/release/" branch)
                              (format "[r/%s]" (substring branch 19)))
                             ((string-match "^refs/heads/hotfix/" branch)
                              (format "[h/%s]" (substring branch 18)))
                             (t
                              (format "[%s]" (substring branch 11))))
                          "[Not Repo]")))
    (propertize mode-line-str
                'face '((:foreground "Dark green" :weight bold)))))

これでブランチ名が[feature/branch-name-hogehoge]から[f/branch-name-hogehoge]へと、少し短くなります。

(2015/5/11 追記)

この設定を追加してから、リージョンを広げるのに上下キーを使えなくなりました。 マークしてから左右方向やsexpの移動であればリージョンを広げられるのですが、 上下方向に広げようとすると、マークが解除され、リージョンがなくなってしまいます。

ここで上下方向は、カーソルキーの上下、C-n、C-pです。 左右方向はカーソルキーの左右、M-f、M-bの単語移動、C-e、C-aの行頭/行末移動です。 sexpの移動はM-N、M-Pの、対応する開きかっこ閉じかっこへの移動です。 (2015/5/11 追記)