1

I've just added a nice custom key binding:

;; Open files in dired mode using 'open'
(eval-after-load "dired"
  '(progn
     (define-key dired-mode-map (kbd "z")
       (lambda () (interactive)
         (let ((fn (dired-get-file-for-visit)))
           (start-process "default-app" nil "open" fn))))))

https://jblevins.org/log/dired-open

Now, on dired, I look at C-h b (show all key bindings) but this new custom binding on the "z" key is shown as bound to ?? in the listing.

So, my question is, how can one add a bit of documentation to a custom key binding, which will be displayed in the "show all key bindings" list?

Perhaps does one have to give the function a global name?

1 Answer 1

3

Don't bind keys to anonymous functions -- C-hb can't tell you the name of the command, because you didn't name it!

Define a named function (give it a docstring too), and bind your key to that symbol.

(Also notice how unhelpful the C-hkz help is with your current code. The suggested changes will fix that too.)

2
  • Thank for your input! So, I wonder what the naming convention is. I'm afraid of creating a global name, which may cause future name clash. Because this function is used only under the dired mode, I hope the name exists only in that mode. [I know very little about elisp.]
    – Ryo
    Feb 7, 2022 at 11:07
  • 2
    Virtually all functions and variables are in the respective global name spaces in Emacs. It might sound alarming, but it's basically fine in practice. You do indeed (simply) have to name things sensibly. I always suggest using a prefix of my- for all custom symbols.
    – phils
    Feb 7, 2022 at 12:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.