0

I am making a topmenu named MCP with a submenu named Daphne.

;; Topmenu MCP 
(define-key-after global-map
   [menu-bar mcp-menu]
   (cons "MCP" (make-sparse-keymap "MCP")) 'Tools)

;; Submenu Daphne
(define-key global-map
   [menu-bar mcp-menu daphne-subm]
   (cons "Daphne" (make-sparse-keymap "daphne")))

I am looking at the following parts

(cons "MCP" (make-sparse-keymap "MCP")) 'tools)
(cons "Daphne" (make-sparse-keymap "daphne"))

Reading through the emacs documentation, "Daphne" and "daphne" are both Menu Item Names. The declarations seem conflicting as it is difficult to see what will be used.

Can someone figure out what goes on.

Dilna
  • 1,173
  • 3
  • 10
  • Hi @dilna, if you use `C-h f` on vanilla emacs, you trigger the search for help on a given function. If you do `C-h f define-key RET` for instance, you find the documentation for `define-key`. The answer to your first question is in that help file, and second question is in `C-h f make-sparse-keymap`. (Note that if you are not on vanilla emacs, you are looking for the function `describe-function`). emacs.SE is not trying to replicate the emacs documentation, so this question is not a great fit for the site, I'm afraid. – Trevoke Jul 16 '23 at 15:28
  • Take as example `(cons "Daphne" (make-sparse-keymap "daphne")`. The documentation says that "Daphne" and "daphne" are both Menu Item Names. These seem conflicting. One of them looks superfluous. – Dilna Jul 16 '23 at 16:15
  • @Trevoke Tags should be about what the question asks. This question doesn't ask about command descriptions etc. - it doesn't ask about help commands. It asks about defining menus and their item key bindings. Your comment might help as an answer, but that doesn't affect the tags - tag `help` should be for questions asking about Emacs's help system/commands. – Drew Jul 16 '23 at 16:15
  • You're right. Thanks. – Trevoke Jul 16 '23 at 16:53
  • 1
    @dilna Okay, with the example you provide here, it is clear that your question is about an unclear bit of documentation. Please edit your question so we all know what to answer, and then we can disambiguate that. That is a good question for this site. – Trevoke Jul 16 '23 at 16:57

1 Answers1

1

The elisp manual has a section for defining menus: https://www.gnu.org/software/emacs/manual/html_node/elisp/Defining-Menus.html. It says,

A keymap acts as a menu if it has an overall prompt string [...]

Emacs displays the overall prompt string as the menu title in some cases, depending on the toolkit (if any) used for displaying menus

[the string] is required for menus which do not use a toolkit, e.g., on a text terminal.

So, there's your answer. And what that means in practice is that you're probably better off using the same string for both, so that your emacs interface is as similar as possible in terminal and GUI mode.

As a side note...

(define-minor-mode dilna-mode "docstring"
  :keymap (make-sparse-keymap "Dilna Mode")
  :lighter " DNA")  

(easy-menu-define dilna-menu dilna-mode-map "docstring"
  '("Easy Dilna Menu"
    ["Emacs Version" emacs-version t]))

(easy-menu-define dilna-submenu nil "docstring"
  '("Dilna Submenu"
     ["Emacs Submenu Version" emacs-version t]))

(easy-menu-add-item dilna-menu nil dilna-submenu)

This adds a GUI menu called "Easy Dilna Menu". The lighter menu has a "title" of "Easy Dilna Menu". Both menus have a command to show the emacs version and a submenu with a single command to also show the emacs version.

It's worth noting that this is very close to Getting easy-menu to display a submenu and that the documentation is really very clear about getting this.

You're probably better off using easy-menu-define.

Trevoke
  • 2,375
  • 21
  • 34