]> code.delx.au - gnu-emacs/commitdiff
Advertize set-keymap-parent as replacement for copy-keymap
authorStefan Monnier <monnier@iro.umontreal.ca>
Wed, 15 Jun 2016 15:36:51 +0000 (11:36 -0400)
committerStefan Monnier <monnier@iro.umontreal.ca>
Wed, 15 Jun 2016 15:36:51 +0000 (11:36 -0400)
* doc/lispref/keymaps.texi (Creating Keymaps):
* src/keymap.c (Fcopy_keymap): Advertize set-keymap-parent as replacement.

doc/lispref/keymaps.texi
src/keymap.c

index 61ac80c589cef6dd40168df90ac8cdd5dc11db32..9abbd898d912bb39698822758cf73b48a90d0606 100644 (file)
@@ -341,7 +341,21 @@ lots of bindings; for just a few, the sparse keymap is better.
 @end defun
 
 @defun copy-keymap keymap
-This function returns a copy of @var{keymap}.  Any keymaps that
+This function returns a copy of @var{keymap}.  This is almost never
+needed.  If you want a keymap that's like another yet with a few
+changes, you should use map inheritance rather than copying.
+I.e., something like:
+
+@example
+@group
+(let ((map (make-sparse-keymap)))
+  (set-keymap-parent map <theirmap>)
+  (define-key map ...)
+  ...)
+@end group
+@end example
+
+When performing @code{copy-keymap}, any keymaps that
 appear directly as bindings in @var{keymap} are also copied recursively,
 and so on to any number of levels.  However, recursive copying does not
 take place when the definition of a character is a symbol whose function
index 44335aded87b3169259ab5b320320715c5755a3b..b27df1d0452817f103aa22f90e5ababd81d9c17f 100644 (file)
@@ -971,8 +971,18 @@ copy_keymap_1 (Lisp_Object chartable, Lisp_Object idx, Lisp_Object elt)
 
 DEFUN ("copy-keymap", Fcopy_keymap, Scopy_keymap, 1, 1, 0,
        doc: /* Return a copy of the keymap KEYMAP.
-The copy starts out with the same definitions of KEYMAP,
-but changing either the copy or KEYMAP does not affect the other.
+
+Note that this is almost never needed.  If you want a keymap that's like
+another yet with a few changes, you should use map inheritance rather
+than copying.  I.e. something like:
+
+    (let ((map (make-sparse-keymap)))
+      (set-keymap-parent map <theirmap>)
+      (define-key map ...)
+      ...)
+
+After performing `copy-keymap', the copy starts out with the same definitions
+of KEYMAP, but changing either the copy or KEYMAP does not affect the other.
 Any key definitions that are subkeymaps are recursively copied.
 However, a key definition which is a symbol whose definition is a keymap
 is not copied.  */)