aboutsummaryrefslogtreecommitdiff
path: root/contrib/emacs
diff options
context:
space:
mode:
authorAlexandre Julliard <julliard@winehq.org>2007-09-29 11:59:07 +0200
committerJunio C Hamano <gitster@pobox.com>2007-09-29 23:44:05 -0700
commit0365d885ad17031de27440fec3553675d02aa4c3 (patch)
treece0a42f5224ce4e81935cd8b0fd4408c0450be4c /contrib/emacs
parent9f5599b9829615379353f676369018c47296e1a1 (diff)
downloadgit-0365d885ad17031de27440fec3553675d02aa4c3.tar.gz
git-0365d885ad17031de27440fec3553675d02aa4c3.tar.xz
git.el: Update a file status in the git buffer upon save.
Signed-off-by: Alexandre Julliard <julliard@winehq.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'contrib/emacs')
-rw-r--r--contrib/emacs/git.el18
1 files changed, 16 insertions, 2 deletions
diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el
index ec2e69906..c2a1c3d1a 100644
--- a/contrib/emacs/git.el
+++ b/contrib/emacs/git.el
@@ -36,7 +36,6 @@
;; TODO
;; - portability to XEmacs
;; - better handling of subprocess errors
-;; - hook into file save (after-save-hook)
;; - diff against other branch
;; - renaming files from the status buffer
;; - creating tags
@@ -1352,9 +1351,24 @@ Commands:
(cd dir)
(git-status-mode)
(git-refresh-status)
- (goto-char (point-min)))
+ (goto-char (point-min))
+ (add-hook 'after-save-hook 'git-update-saved-file))
(message "%s is not a git working tree." dir)))
+(defun git-update-saved-file ()
+ "Update the corresponding git-status buffer when a file is saved.
+Meant to be used in `after-save-hook'."
+ (let* ((file (expand-file-name buffer-file-name))
+ (dir (condition-case nil (git-get-top-dir (file-name-directory file))))
+ (buffer (and dir (git-find-status-buffer dir))))
+ (when buffer
+ (with-current-buffer buffer
+ (let ((filename (file-relative-name file dir)))
+ ; skip files located inside the .git directory
+ (unless (string-match "^\\.git/" filename)
+ (git-call-process-env nil nil "add" "--refresh" "--" filename)
+ (git-update-status-files (list filename) 'uptodate)))))))
+
(defun git-help ()
"Display help for Git mode."
(interactive)