]> code.delx.au - gnu-emacs-elpa/commitdiff
Define diff-hl-command-map without destroying existing bindings
authorJonas Bernoulli <jonas@bernoul.li>
Tue, 18 Aug 2015 12:15:38 +0000 (14:15 +0200)
committerJonas Bernoulli <jonas@bernoul.li>
Tue, 18 Aug 2015 15:07:18 +0000 (17:07 +0200)
Keymaps are usually defined using `defvar' which has the advantage that
it only sets a variables value if that is not defined yet.  As a result
re-evaluating (i.e. during development) a buffer that contains such a
definition does not reset the value, which would lose all user
customization.

Unfortunately `define-prefix-command' does not do that.  So use `defvar'
to define the variable and then also store the in the function cell
using `fset'.

diff-hl.el

index 8f2221a7c0ee399488b8f0c1375eeff86315722f..18b92c716cba3d3fe5fc983cb5e30b749f15345e 100644 (file)
@@ -437,13 +437,13 @@ in the source file, or the last line of the hunk above it."
   (interactive)
   (diff-hl-next-hunk t))
 
-(define-prefix-command 'diff-hl-command-map)
-
-(let ((map diff-hl-command-map))
-  (define-key map "n" 'diff-hl-revert-hunk)
-  (define-key map "[" 'diff-hl-previous-hunk)
-  (define-key map "]" 'diff-hl-next-hunk)
-  map)
+(defvar diff-hl-command-map
+  (let ((map (make-sparse-keymap)))
+    (define-key map "n" 'diff-hl-revert-hunk)
+    (define-key map "[" 'diff-hl-previous-hunk)
+    (define-key map "]" 'diff-hl-next-hunk)
+    map))
+(fset 'diff-hl-command-map diff-hl-command-map)
 
 ;;;###autoload
 (define-minor-mode diff-hl-mode