diff options
Diffstat (limited to 'devdocs/elisp/remapping-commands.html')
| -rw-r--r-- | devdocs/elisp/remapping-commands.html | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/devdocs/elisp/remapping-commands.html b/devdocs/elisp/remapping-commands.html new file mode 100644 index 00000000..c4ca0dcb --- /dev/null +++ b/devdocs/elisp/remapping-commands.html @@ -0,0 +1,17 @@ + <h3 class="section">Remapping Commands</h3> <p>A special kind of key binding can be used to <em>remap</em> one command to another, without having to refer to the key sequence(s) bound to the original command. To use this feature, make a key binding for a key sequence that starts with the dummy event <code>remap</code>, followed by the command name you want to remap; for the binding, specify the new definition (usually a command name, but possibly any other valid definition for a key binding). </p> <p>For example, suppose My mode provides a special command <code>my-kill-line</code>, which should be invoked instead of <code>kill-line</code>. To establish this, its mode keymap should contain the following remapping: </p> <div class="example"> <pre class="example">(define-key my-mode-map [remap kill-line] 'my-kill-line) +</pre> +</div> <p>Then, whenever <code>my-mode-map</code> is active, if the user types <kbd>C-k</kbd> (the default global key sequence for <code>kill-line</code>) Emacs will instead run <code>my-kill-line</code>. </p> <p>Note that remapping only takes place through active keymaps; for example, putting a remapping in a prefix keymap like <code>ctl-x-map</code> typically has no effect, as such keymaps are not themselves active. In addition, remapping only works through a single level; in the following example, </p> <div class="example"> <pre class="example">(define-key my-mode-map [remap kill-line] 'my-kill-line) +(define-key my-mode-map [remap my-kill-line] 'my-other-kill-line) +</pre> +</div> <p><code>kill-line</code> is <em>not</em> remapped to <code>my-other-kill-line</code>. Instead, if an ordinary key binding specifies <code>kill-line</code>, it is remapped to <code>my-kill-line</code>; if an ordinary binding specifies <code>my-kill-line</code>, it is remapped to <code>my-other-kill-line</code>. </p> <p>To undo the remapping of a command, remap it to <code>nil</code>; e.g., </p> <div class="example"> <pre class="example">(define-key my-mode-map [remap kill-line] nil) +</pre> +</div> <dl> <dt id="command-remapping">Function: <strong>command-remapping</strong> <em>command &optional position keymaps</em> +</dt> <dd> +<p>This function returns the remapping for <var>command</var> (a symbol), given the current active keymaps. If <var>command</var> is not remapped (which is the usual situation), or not a symbol, the function returns <code>nil</code>. <code>position</code> can optionally specify a buffer position or an event position to determine the keymaps to use, as in <code>key-binding</code>. </p> <p>If the optional argument <code>keymaps</code> is non-<code>nil</code>, it specifies a list of keymaps to search in. This argument is ignored if <code>position</code> is non-<code>nil</code>. </p> +</dd> +</dl><div class="_attribution"> + <p class="_attribution-p"> + Copyright © 1990-1996, 1998-2022 Free Software Foundation, Inc. <br>Licensed under the GNU GPL license.<br> + <a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Remapping-Commands.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Remapping-Commands.html</a> + </p> +</div> |
