Skip to main content


Another #elisp question: Why does #Emacs have separate bits for the meta key (2**27) and alt (2**22)? Aren't they the same key, or is it a remapping thing like the ESC prefix?
in reply to Jonathan Lamothe

Meta and ALT are not the same key.
The original keyboards used long ago had Ctrl, Super, Hyper, Meta, and ALT keys. We now map Meta (i.e. ESC) to the Alt key on our keyboards as a convenience. I do not believe there is a way, on modern keyboards, to have both META and ALT mapped to a key. We can have Super, and Meta. I can't recall if I was able to map Hyper on a modern keyboard.


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

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.

in reply to Jonathan Lamothe

I think you've got it right. Many who write lisp think of adding to the head of the list as normal, even if they still have to walk it for things like uniqueness checks.


A thing I keep seeing in #elisp documentation:

If such-and-such a condition occurs within function foo, it will signal an error.

Cool, which error exactly? I mean, I can wrap it in a condition-case and put a handler on t, but...

#Emacs

in reply to Zenie

@Zenie That's an option, but my concern is that the reason they might be vague in the docs is because the specific error might change in future versions.

Perhaps I'm just being overly paranoid.

in reply to Jonathan Lamothe

It's lisp. Stuff doesn't change that much.
Usually errors are obvious and for very specific reasons. You can just catch them and print the message so if anything does change you will know.
I don't think it's worth worrying about.


A thing that's really nice about #Emacs and #elisp: I don't need an internet connection to read the documentation.

reshared this



Just spent a good half hour pulling my hair out trying to figure out why one of the #elisp functions I had just written was always returning nil when I tested it. Turns out, my test was mistakenly passing its inputs to the wrong (but similarly named) function (pivot-table-get-columns instead of pivot-table-get-body).

#Haskell's type system would've caught this. πŸ™ƒ

#emacs #lisp

in reply to Jonathan Lamothe

C's type system would also have caught it, and it isn't worth a hill of beans.

By caught it what do we mean? This is not a case of some undetected error escaping your attention due to dynamic typing. You know you got a nil which is unexpected and wrong. It's in a test case which catches it.

The only thing a type system would change is that you would instead waste a half hour not understanding how your obviously correct function call can possibly have the wrong return type.

in reply to Kazinator

@Kazinator I feel that that would have been much more useful information. nil is about the least useful failure state there is.


For all the criticism I have of dynamically typed languages, I have to admit that the way #elisp (and presumably #lisp in general) does in-line documentation is pretty nice.


The seemingly canonical way of detecting whether the C-u modifier was used on an interactive function call (when an actual numerical argument wasn't provided) in #elisp feels... icky. #emacs
in reply to Jonathan Lamothe

To be fair C-u *is* a numerical argument so you're not really meant to differentiate (it means the number 4). πŸ˜…
in reply to Alessio Vanni

@Alessio Vanni Yeah, it's just very magic number-ey.

Ah well, such is the way it is with legacy code sometimes. No way to change it without breaking about a billion other things.



I wonder how difficult it would be to introduce rudimentary namespaces into #elisp.

#emacs

Harald reshared this.

in reply to Jonathan Lamothe

Just learned about interned vs. uninterned symbols. Feels like this would be a big piece of this puzzle.

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

⇧