配置emacs自动加载上一次git comment

不想每次都去复制粘贴comment到editor,就在emacs里捣腾,LISP还不会用,不过总是凑出两个函数可以用了,可能很蹩脚,以后会用ELISP了再优化吧。

大概意思就是把每次提交的comment存到一个文件里,下次再加载commit msg 文件时,就从备份的文件里读出来。

保存的comment是Signed-off-by前面那一部分。

(defun my-load-file-mode ()
  (when (and (stringp buffer-file-name)
             (string-match "\\COMMIT_EDITMSG\\'" buffer-file-name))
    (when (file-exists-p "COMMIT_EDITMSG_1")
      (insert-file-contents  "COMMIT_EDITMSG_1" nil 0 500 )
      ))
      (set-buffer-file-coding-system  'utf-8))

(defun my-save-file-hook ()
  (when (and (stringp buffer-file-name)
             (string-match "\\COMMIT_EDITMSG\\'" buffer-file-name))
    (save-excursion
      (beginning-of-buffer)
      (write-region (point)
		    (progn
		    (re-search-forward "Signed-off-by")
		    (previous-line)(end-of-line)
		    (point)) "COMMIT_EDITMSG_1" nil nil nil nil))))

(add-hook 'find-file-hook 'my-load-file-mode)
(add-hook 'after-save-hook 'my-save-file-hook)

 

posted on 2012-05-03 20:43  jianglili  阅读(240)  评论(0编辑  收藏  举报

导航