diff options
| author | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
| commit | 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch) | |
| tree | f1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/elisp/menu-example.html | |
new repository
Diffstat (limited to 'devdocs/elisp/menu-example.html')
| -rw-r--r-- | devdocs/elisp/menu-example.html | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/devdocs/elisp/menu-example.html b/devdocs/elisp/menu-example.html new file mode 100644 index 00000000..61621f74 --- /dev/null +++ b/devdocs/elisp/menu-example.html @@ -0,0 +1,24 @@ + <h4 class="subsection">Menu Example</h4> <p>Here is a complete example of defining a menu keymap. It is the definition of the ‘<samp>Replace</samp>’ submenu in the ‘<samp>Edit</samp>’ menu in the menu bar, and it uses the extended menu item format (see <a href="extended-menu-items">Extended Menu Items</a>). First we create the keymap, and give it a name: </p> <div class="example"> <pre class="example">(defvar menu-bar-replace-menu (make-sparse-keymap "Replace")) +</pre> +</div> <p>Next we define the menu items: </p> <div class="example"> <pre class="example">(define-key menu-bar-replace-menu [tags-repl-continue] + '(menu-item "Continue Replace" multifile-continue + :help "Continue last tags replace operation")) +(define-key menu-bar-replace-menu [tags-repl] + '(menu-item "Replace in tagged files" tags-query-replace + :help "Interactively replace a regexp in all tagged files")) +(define-key menu-bar-replace-menu [separator-replace-tags] + '(menu-item "--")) +;; <span class="roman">…</span> +</pre> +</div> <p>Note the symbols which the bindings are made for; these appear inside square brackets, in the key sequence being defined. In some cases, this symbol is the same as the command name; sometimes it is different. These symbols are treated as function keys, but they are not real function keys on the keyboard. They do not affect the functioning of the menu itself, but they are echoed in the echo area when the user selects from the menu, and they appear in the output of <code>where-is</code> and <code>apropos</code>. </p> <p>The menu in this example is intended for use with the mouse. If a menu is intended for use with the keyboard, that is, if it is bound to a key sequence ending with a keyboard event, then the menu items should be bound to characters or real function keys, that can be typed with the keyboard. </p> <p>The binding whose definition is <code>("--")</code> is a separator line. Like a real menu item, the separator has a key symbol, in this case <code>separator-replace-tags</code>. If one menu has two separators, they must have two different key symbols. </p> <p>Here is how we make this menu appear as an item in the parent menu: </p> <div class="example"> <pre class="example">(define-key menu-bar-edit-menu [replace] + (list 'menu-item "Replace" menu-bar-replace-menu)) +</pre> +</div> <p>Note that this incorporates the submenu keymap, which is the value of the variable <code>menu-bar-replace-menu</code>, rather than the symbol <code>menu-bar-replace-menu</code> itself. Using that symbol in the parent menu item would be meaningless because <code>menu-bar-replace-menu</code> is not a command. </p> <p>If you wanted to attach the same replace menu to a mouse click, you can do it this way: </p> <div class="example"> <pre class="example">(define-key global-map [C-S-down-mouse-1] + menu-bar-replace-menu) +</pre> +</div><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/Menu-Example.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Menu-Example.html</a> + </p> +</div> |
