diff options
| author | Stefan Monnier | 2016-06-15 11:36:51 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2016-06-15 11:36:51 -0400 |
| commit | 4a2092efd2ac76fce04a2587b360ed2ca1eac4d7 (patch) | |
| tree | bf5f38017fa292ee4bf17af607d5163831b26d64 | |
| parent | 090060a72c7245796bffeb14daf9da1b49f339f0 (diff) | |
| download | emacs-4a2092efd2ac76fce04a2587b360ed2ca1eac4d7.tar.gz emacs-4a2092efd2ac76fce04a2587b360ed2ca1eac4d7.zip | |
Advertize set-keymap-parent as replacement for copy-keymap
* doc/lispref/keymaps.texi (Creating Keymaps):
* src/keymap.c (Fcopy_keymap): Advertize set-keymap-parent as replacement.
| -rw-r--r-- | doc/lispref/keymaps.texi | 16 | ||||
| -rw-r--r-- | src/keymap.c | 14 |
2 files changed, 27 insertions, 3 deletions
diff --git a/doc/lispref/keymaps.texi b/doc/lispref/keymaps.texi index 61ac80c589c..9abbd898d91 100644 --- a/doc/lispref/keymaps.texi +++ b/doc/lispref/keymaps.texi | |||
| @@ -341,7 +341,21 @@ lots of bindings; for just a few, the sparse keymap is better. | |||
| 341 | @end defun | 341 | @end defun |
| 342 | 342 | ||
| 343 | @defun copy-keymap keymap | 343 | @defun copy-keymap keymap |
| 344 | This function returns a copy of @var{keymap}. Any keymaps that | 344 | This function returns a copy of @var{keymap}. This is almost never |
| 345 | needed. If you want a keymap that's like another yet with a few | ||
| 346 | changes, you should use map inheritance rather than copying. | ||
| 347 | I.e., something like: | ||
| 348 | |||
| 349 | @example | ||
| 350 | @group | ||
| 351 | (let ((map (make-sparse-keymap))) | ||
| 352 | (set-keymap-parent map <theirmap>) | ||
| 353 | (define-key map ...) | ||
| 354 | ...) | ||
| 355 | @end group | ||
| 356 | @end example | ||
| 357 | |||
| 358 | When performing @code{copy-keymap}, any keymaps that | ||
| 345 | appear directly as bindings in @var{keymap} are also copied recursively, | 359 | appear directly as bindings in @var{keymap} are also copied recursively, |
| 346 | and so on to any number of levels. However, recursive copying does not | 360 | and so on to any number of levels. However, recursive copying does not |
| 347 | take place when the definition of a character is a symbol whose function | 361 | take place when the definition of a character is a symbol whose function |
diff --git a/src/keymap.c b/src/keymap.c index 44335aded87..b27df1d0452 100644 --- a/src/keymap.c +++ b/src/keymap.c | |||
| @@ -971,8 +971,18 @@ copy_keymap_1 (Lisp_Object chartable, Lisp_Object idx, Lisp_Object elt) | |||
| 971 | 971 | ||
| 972 | DEFUN ("copy-keymap", Fcopy_keymap, Scopy_keymap, 1, 1, 0, | 972 | DEFUN ("copy-keymap", Fcopy_keymap, Scopy_keymap, 1, 1, 0, |
| 973 | doc: /* Return a copy of the keymap KEYMAP. | 973 | doc: /* Return a copy of the keymap KEYMAP. |
| 974 | The copy starts out with the same definitions of KEYMAP, | 974 | |
| 975 | but changing either the copy or KEYMAP does not affect the other. | 975 | Note that this is almost never needed. If you want a keymap that's like |
| 976 | another yet with a few changes, you should use map inheritance rather | ||
| 977 | than copying. I.e. something like: | ||
| 978 | |||
| 979 | (let ((map (make-sparse-keymap))) | ||
| 980 | (set-keymap-parent map <theirmap>) | ||
| 981 | (define-key map ...) | ||
| 982 | ...) | ||
| 983 | |||
| 984 | After performing `copy-keymap', the copy starts out with the same definitions | ||
| 985 | of KEYMAP, but changing either the copy or KEYMAP does not affect the other. | ||
| 976 | Any key definitions that are subkeymaps are recursively copied. | 986 | Any key definitions that are subkeymaps are recursively copied. |
| 977 | However, a key definition which is a symbol whose definition is a keymap | 987 | However, a key definition which is a symbol whose definition is a keymap |
| 978 | is not copied. */) | 988 | is not copied. */) |