]> code.delx.au - gnu-emacs-elpa/commitdiff
diff-hl-fringe-bmp-function: New option
authorDmitry Gutov <dgutov@yandex.ru>
Sun, 8 Sep 2013 03:33:41 +0000 (06:33 +0300)
committerDmitry Gutov <dgutov@yandex.ru>
Sun, 8 Sep 2013 03:33:41 +0000 (06:33 +0300)
* diff-hl-define-bitmaps: Add new bitmaps.
* diff-hl-fringe-bmp-from-pos, diff-hl-fringe-bmp-from-type: New functions.
* diff-hl-fringe-spec: Include fringe-bmp-function in the hash key.

diff-hl.el

index ea7a1b5f56592b97269be3f9e750e39b2441cacf..d75c3bc05da1870937f9e1ab033bea9420cead4b 100644 (file)
   :group 'diff-hl\r
   :type 'boolean)\r
 \r
+(defcustom diff-hl-fringe-bmp-function 'diff-hl-fringe-bmp-from-pos\r
+  "Function to choose the fringe bitmap for a given change type\r
+  and position within a hunk.  Should accept two arguments."\r
+  :group 'diff-hl\r
+  :type '(choice (const diff-hl-fringe-bmp-from-pos)\r
+                 (const diff-hl-fringe-bmp-from-type)\r
+                 function))\r
+\r
 (defvar diff-hl-reference-revision nil\r
   "Revision to diff against.  nil means the most recent one.")\r
 \r
     (define-fringe-bitmap 'diff-hl-bmp-top top h w 'top)\r
     (define-fringe-bitmap 'diff-hl-bmp-middle middle h w 'center)\r
     (define-fringe-bitmap 'diff-hl-bmp-bottom bottom h w 'bottom)\r
-    (define-fringe-bitmap 'diff-hl-bmp-single single h w 'top)))\r
+    (define-fringe-bitmap 'diff-hl-bmp-single single h w 'top)\r
+    (let* ((w2 (- w 2))\r
+           (delete-row (1- (expr 2 w2)))\r
+           (middle-bit (expt 2 (1- (/ w2 2))))\r
+           (insert-bmp (make-vector 2 (* 3 middle-bit))))\r
+      (define-fringe-bitmap 'diff-hl-bmp-delete (make-vector 2 delete-row))\r
+      (aset insert-bmp middle-bit delete-row)\r
+      (aset insert-bmp (1+ middle-bit) delete-row)\r
+      (define-fringe-bitmap 'diff-hl-bmp-insert insert-bmp)\r
+      (define-fringe-bitmap 'diff-hl-bmp-change (make-vector\r
+                                                 w (* 3 middle-bit))))))\r
 \r
 (defvar diff-hl-spec-cache (make-hash-table :test 'equal))\r
 \r
 (defun diff-hl-fringe-spec (type pos)\r
-  (let* ((key (cons type pos))\r
+  (let* ((key (list type pos diff-hl-fringe-bmp-function))\r
          (val (gethash key diff-hl-spec-cache)))\r
     (unless val\r
-      (let* ((face-sym (intern (concat "diff-hl-" (symbol-name type))))\r
-             (bmp-sym (intern (concat "diff-hl-bmp-" (symbol-name pos)))))\r
+      (let* ((face-sym (intern (format "diff-hl-%s" type)))\r
+             (bmp-sym (funcall diff-hl-fringe-bmp-function type pos)))\r
         (setq val (propertize " " 'display `((left-fringe ,bmp-sym ,face-sym))))\r
         (puthash key val diff-hl-spec-cache)))\r
     val))\r
 \r
+(defun diff-hl-fringe-bmp-from-pos (type pos)\r
+  (intern (format "diff-hl-bmp-%s" pos)))\r
+\r
+(defun diff-hl-fringe-bmp-from-type (type pos)\r
+  (if (eq type 'unknown)\r
+      'question-mark\r
+    (intern (format "diff-hl-bmp-%s" type))))\r
+\r
 (defmacro diff-hl-with-diff-switches (body)\r
   `(let ((vc-git-diff-switches nil)\r
          (vc-hg-diff-switches nil)\r