]> code.delx.au - gnu-emacs-elpa/blobdiff - diff-hl-margin.el
Merge pull request #39 from jamessan/diff-hl-margin-load-error
[gnu-emacs-elpa] / diff-hl-margin.el
index eb871b225a8c64154255e305c5818eb2f2a0d45f..4f999943645056d1dec6879b92d9670d95d51bde 100644 (file)
@@ -1,6 +1,6 @@
 ;;; diff-hl-margin.el --- Highlight buffer changes on margins -*- lexical-binding: t -*-
 
-;; Copyright (C) 2012-2013  Free Software Foundation, Inc.
+;; Copyright (C) 2012-2014  Free Software Foundation, Inc.
 
 ;; This file is part of GNU Emacs.
 
@@ -19,7 +19,7 @@
 
 ;;; Commentary:
 
-;; This is a global mode, it modified `diff-hl-mode' to use the margin
+;; This is a global mode, it modifies `diff-hl-mode' to use the margin
 ;; instead of the fringe. To toggle, type `M-x diff-hl-margin-mode'.
 ;;
 ;; Compared to the default behavior, this makes `diff-hl-mode'
   "Highlight buffer changes on margin"
   :group 'diff-hl)
 
+;;;###autoload
+(define-minor-mode diff-hl-margin-mode
+  "Toggle displaying `diff-hl-mode' highlights on the margin."
+  :lighter "" :global t
+  (if diff-hl-margin-mode
+      (progn
+        (add-hook 'diff-hl-mode-on-hook 'diff-hl-margin-minor-mode)
+        (add-hook 'diff-hl-mode-off-hook 'diff-hl-margin-minor-mode-off)
+        (add-hook 'diff-hl-dired-mode-on-hook 'diff-hl-margin-minor-mode)
+        (add-hook 'diff-hl-dired-mode-off-hook 'diff-hl-margin-minor-mode-off))
+    (remove-hook 'diff-hl-mode-on-hook 'diff-hl-margin-minor-mode)
+    (remove-hook 'diff-hl-mode-off-hook 'diff-hl-margin-minor-mode-off)
+    (remove-hook 'diff-hl-dired-mode-on-hook 'diff-hl-margin-minor-mode)
+    (remove-hook 'diff-hl-dired-mode-off-hook 'diff-hl-margin-minor-mode-off))
+  (dolist (buf (buffer-list))
+    (with-current-buffer buf
+      (cond
+       (diff-hl-mode
+        (diff-hl-margin-minor-mode (if diff-hl-margin-mode 1 -1))
+        (diff-hl-update))
+       (diff-hl-dired-mode
+        (diff-hl-margin-minor-mode (if diff-hl-margin-mode 1 -1))
+        (diff-hl-dired-update))))))
+
+(define-minor-mode diff-hl-margin-minor-mode
+  "Toggle displaying `diff-hl-mode' highlights on the margin locally.
+You probably shouldn't use this function directly."
+  :lighter ""
+  (let ((width-var (intern (format "%s-margin-width" diff-hl-margin-side))))
+    (if diff-hl-margin-minor-mode
+        (progn
+          (set (make-local-variable 'diff-hl-margin-old-highlight-function)
+               diff-hl-highlight-function)
+          (set (make-local-variable 'diff-hl-highlight-function)
+               'diff-hl-highlight-on-margin)
+          (set width-var 1))
+      (setq diff-hl-highlight-function diff-hl-margin-old-highlight-function
+            diff-hl-margin-old-highlight-function nil)
+      (set width-var 0)))
+  (dolist (win (get-buffer-window-list))
+    (set-window-buffer win (current-buffer))))
+
 (defcustom diff-hl-margin-side 'left
   "Which margin to use for indicators."
   :type '(choice (const left)
            (set-default var value)
            (when on (diff-hl-margin-mode 1)))))
 
-;;;###autoload
-(define-minor-mode diff-hl-margin-mode
-  "Toggle displaying `diff-hl-mode' highlights on the margin."
-  :lighter "" :global t
-  (let ((width-var (intern (format "%s-margin-width" diff-hl-margin-side))))
-    (if diff-hl-margin-mode
-        (progn
-          (setq diff-hl-margin-old-highlight-function diff-hl-highlight-function
-                diff-hl-highlight-function 'diff-hl-highlight-on-margin)
-          (set-default width-var 1))
-      (setq diff-hl-highlight-function diff-hl-margin-old-highlight-function
-            diff-hl-margin-old-highlight-function nil)
-      (set-default width-var 0)))
-  (dolist (buffer (buffer-list))
-    (with-current-buffer buffer
-      (cond
-       (diff-hl-mode
-        (diff-hl-update))
-       (diff-hl-dired-mode
-        (diff-hl-dired-update)))))
-  (walk-windows (lambda (win) (set-window-buffer win (window-buffer win)))))
+(defun diff-hl-margin-minor-mode-off ()
+  (diff-hl-margin-minor-mode -1))
 
 (defvar diff-hl-margin-spec-cache
   (cl-loop for (type . char) in '((insert . "+") (delete . "-")
-                                  (change . "|") (unknown . "?"))
+                                  (change . "!") (unknown . "?")
+                                  (ignored . "i"))
         nconc
         (cl-loop for side in '(left right)
                  collect