Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Basic git-wip-mode

- Since we can disable a minor mode, it's possible to disable git-wip
  on a per-buffer basis.

- The mode is automatically enabled if we are in vc-mode, even if we
  aren't actually using git.

Signed-off-by: Jerome Baum <jerome@jeromebaum.com>
  • Loading branch information...
commit 46d6e6fc6045553779b70578fc0e37496a20ff44 1 parent 06f71e2
@jeromebaum authored
Showing with 43 additions and 0 deletions.
  1. +43 −0 emacs/git-wip-mode.el
View
43 emacs/git-wip-mode.el
@@ -0,0 +1,43 @@
+(eval-when-compile
+ (require 'cl)
+ (require 'vc))
+
+(require 'vc-hooks)
+
+(defun git-wip-after-save ()
+ (interactive)
+ (when (string= (vc-backend (buffer-file-name)) "Git")
+ (shell-command (concat "git-wip save \"WIP from emacs: "
+ (buffer-file-name)
+ "\" --editor -- "
+ (buffer-file-name)))
+ (message (concat "Wrote and git-wip'd " (buffer-file-name)))))
+
+(define-minor-mode git-wip-mode
+ "Toggle git-wip mode.
+With no argument, this command toggles the mode.
+Non-null prefix argument turns on the mode.
+Null prefix argument turns off the mode.
+
+When git-wip mode is enabled, git-wip will be called every time
+you save a buffer."
+ ;; The initial value.
+ nil
+ ;; The indicator for the mode line.
+ " WIP"
+ :group 'git-wip
+
+ ;; (de-)register our hook
+ (if git-wip-mode
+ (add-hook 'after-save-hook 'git-wip-after-save nil t)
+ (remove-hook 'after-save-hook 'git-wip-after-save t)))
+
+(defun git-wip-mode-if-git ()
+ (interactive)
+ (vc-find-file-hook)
+ (when vc-mode
+ (git-wip-mode t)))
+
+(add-hook 'find-file-hook 'git-wip-mode-if-git)
+
+(provide 'git-wip-mode)
Please sign in to comment.
Something went wrong with that request. Please try again.