Skip to main content



elisp nonsense

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?

#emacs #elisp

reshared this

in reply to Jonathan Lamothe

elisp nonsense

@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.

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.



I virtually never set custom keybindings in #Emacs preferring instead to rely on M-x function calls because I had such a hard time finding key sequences that weren't used by something else. Since learning that C-c /[A-Za-z]/ is reserved for user-defined keybindings, I've gone mad with power.

reshared this

in reply to Lens

@Lens @Robert Pluim πŸ‡ͺπŸ‡Ί On my system C-z suspends Emacs and drops me back to the terminal until I issue the fg command to bring it back. I use this for issuing git commands. I could probably do this from within Emacs, but I haven't bothered to figure it out.
in reply to Jonathan Lamothe

@rpluim magit is a pretty awesome git porcelain I think you'd like. It's shipped with emacs by default
in reply to Lens

@lens_r magit is awesome, but it's not part of standard Emacs. VC is, but that's not as good as magit for git (it's great however when you're forced to use some other version control system like CVS, since VC provides bindings that work whatever the underlying system is)
@Lens


I love that Instacart sent us a Starbucks gift card ro reward us for our "hard work and loyalty" on the same day they fired us. πŸ™ƒ

This website uses cookies. If you continue browsing this website, you agree to the usage of cookies.

⇧