bug#81421: 31.0.90; Consistent use of #' when defining key bindings in the Emacs Lisp reference manual

Eli Zaretskii <[email protected]> Sat, 01 Aug 2026 11:36:59 +0300
Newsgroups gmane.emacs.bugs
Message-ID <[email protected]>
> Cc: [email protected]
> Date: Thu, 16 Jul 2026 08:31:44 +0300
> From: Eli Zaretskii <[email protected]>
> 
> tags 81421 notabug
> thanks
> 
> > From: Markus Triska <[email protected]>
> > Date: Wed, 15 Jul 2026 23:38:42 +0200 (CEST)
> > 
> > 
> > As examples in "23.2 Changing Key Bindings" of the Emacs Lisp
> > reference manual, we find among others:
> > 
> >     (keymap-set map "C-f" 'forward-char)
> >     (keymap-set map "C-x f" 'forward-word)
> >     (keymap-set map "C-p" ctl-x-map)
> >     (keymap-set map "C-p C-f" 'foo)
> > 
> > Note that #' is not used to denote functions. Only ' (quote) is used.
> > 
> > For comparison, in "23.4 Creating Keymaps", we find examples such as:
> > 
> >     (define-keymap
> >       "n" #'forward-line
> >       "f" #'previous-line
> >       "C-c C-c" #'quit-window)
> > 
> > where #' is used to denote functions.
> > 
> > In the Emacs source code itself, #' is used very consistently to
> > denote functions in key bindings, and almost all occurrences of
> > keymap-set in the Emacs source code use it.
> > 
> > >From this I gather it is good practice to use #' in such cases? If so,
> > would you please consider adding it to the examples in 23.2 too?
> > 
> > One additional motivation for this: From the Emacs Lisp reference
> > manual, it is not clear (at least to me) whether using #' is even
> > admissible in such cases. I found only a single example that uses #'
> > in connection with keymap-set in the manual, and that example occurs
> > in a section apart from key bindings, namely in "22.9 Special Events":
> > 
> >     (keymap-set special-event-map "<sleep-event>" #'my-event-handler)
> > 
> > The documentation of #' says "In many ways, it is similar to ‘quote’
> > (*noteQuoting).", and further says:
> > 
> >     Assuming FUNCTION-OBJECT is a valid lambda expression, this has two effects ...
> > 
> > and also says that the following are all equivalent:
> > 
> >      (lambda (x) (* x x))
> >      (function (lambda (x) (* x x)))
> >      #'(lambda (x) (* x x))
> > 
> > (so why even use #' in connection with a lambda expression then?).
> > 
> > >From these descriptions, it is unclear (i.e., is this one of the
> > mentioned "many ways" in which #' is "similar" to `quote'?) whether it
> > is even admissible to write:
> > 
> >     (keymap-set map "C-f" #'forward-char)
> > 
> > instead of:
> > 
> >     (keymap-set map "C-f" 'forward-char)
> > 
> > and a few examples of the former could help make this more certain and
> > at the same also promote what seems to be best practice.
> > 
> > If #' remains used in 23.4 but is not used in 23.2, then it could be
> > interesting to note too what motivates its omission in Section 23.2.
> 
> Both ' and #' are acceptable.  Historically, we used ', but recently
> there's a tendency to prefer #', and we are slowly changing the
> documentation to follow suit.  "Slowly" because we make the changes in
> places that get other updates, but do not make such changes without
> changing something else "in the vicinity", because that's just causes
> excess code churn.
> 
> IOW, there's no problem here and no need to wonder what is "right":
> both will work.  We will eventually get to the chapter you mention as
> well, but no rush.
> 
> There's no bug here.

No further comments within 2 weeks, so I'm now closing this non-bug.