Stefan Monnier writes: >> Here's another attempt. Like the previous patch, I define >> key-binding-keymap which finds the keymap by mimicking key-binding, and >> describe-key--binding-locus which matches the keymap to a symbol and >> makes a description suitable for describe-key. > > Looks pretty good. Feel free to install it into `trunk'. I can send a patch, including a ChangeLog entry, but I don't have permission to commit. >> + (when (integerp found) >> + ;; prefix was found but not the whole sequence >> + (setq found nil))) > > If key-binding returned a command, then we should never hit this case. > It's OK to keep the code, but you might like to add a comment mentioning > that we don't expect this case to happen. We do hit the case, because we look in active keymaps one by one, instead of using the keymap (cons 'keymap active-keymaps) like key-binding does. >> + ;; look into these advertised symbols first >> + (while (and (not found) advertised-syms) >> + (let ((sym (pop advertised-syms))) >> + (setq found >> + (when (and >> + (boundp sym) >> + (eq map (symbol-value sym))) >> + sym)))) >> + ;; only look in other symbols otherwise >> + (when (not found) >> + (mapatoms >> + (lambda (x) >> + (when (and (boundp x) >> + ;; avoid let-bound symbols >> + (special-variable-p x) >> + (eq (symbol-value x) map)) >> + (push x found)))) >> + (when (and (consp found) >> + (null (cdr found))) >> + (setq found (car found)))) > > I think this code will be simpler if you use catch/throw (you can then > use dolist over advertised-syms, for example and you don't need > `found'). Shall I return only the first symbol that matches, also in the mapatoms case ? I assume yes because of your next suggestion : > I think it's better to make this function return the symbol rather than > a string, and let the caller turn it into a string. Ok. Here's the patch.