I've been playing around with keymaps. Apparently they can be used to create menus that give the user a visual list of options. The canonical way to make them is aparently with make-sparse-keymap to create the menu and define-key to add options to it, but this causes some confusing behaviour.
Take the following example:
(let ((menu (make-sparse-keymap "My menu")))
(define-key menu "a"
'(menu-item "Foo" foo))
(define-key menu "b"
'(menu-item "Bar" bar))
menu)Yields the following:
(keymap (98 menu-item "Bar" bar) (97 menu-item "Foo" foo) "My menu")Each new entry is added to the top of the list, so when the menu is displayed, they're listed in reverse order. This is very counter intuitive.
Now, I understand that the nature of lists in lisp make inserting an element at the top of the list less computationally expensive, but when you've already got to walk the whole list anyway to ensure the key binding isn't already present, this no longer feels like an adequate excuse.
Am I missing something?
Trump may be the anti-christ likes this.
reshared this
Robert Pluim 🇪🇺
in reply to Jonathan Lamothe • • •Sensitive content
Jonathan Lamothe likes this.
Jonathan Lamothe
in reply to Robert Pluim 🇪🇺 • •Jonathan Lamothe
in reply to Jonathan Lamothe • •@Robert Pluim 🇪🇺 It looks though like it's primarily meant to build a menu for a menu bar or pop up menu, which is not what I'm looking for.
I'm tempted to just build the structure by hand, but the docs are very emphatic that I must not do this for some reason.
Robert Pluim 🇪🇺
in reply to Jonathan Lamothe • • •Sensitive content
Jonathan Lamothe
in reply to Robert Pluim 🇪🇺 • •defvar-keymapis worth investigating.Zenie
in reply to Jonathan Lamothe • • •Define key is my least favorite way to make a keymap.
I like defvar-keymap, bind-keys, if you've got a map create already. Like a sparce map.
General is nice too. But then you have to have that installed.
Jonathan Lamothe likes this.