[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#65128: 30.0.50; Strange code in help-fns.el
From: |
Drew Adams |
Subject: |
bug#65128: 30.0.50; Strange code in help-fns.el |
Date: |
Tue, 8 Aug 2023 15:50:12 +0000 |
> > > I am looking at lisp/help-fns.el:describe-keymap and seeing
> > > (let ((sym nil))
> > > (unless sym ...
> > >
> > > It looks like an oversight - sym will always be nil there.
> >
> > Adding Stefan, who wrote that function.
>
> Thanks, now fixed on master.
>
> PS. For the record, this function was originally written by Drew, and
> integrated into Emacs by me. I do get credit for the stylistic
> mistake here, however.
;-) Thanks for the attribution and mea culpa.
Yes, I wrote `describe-keymap'. My version
is in library `help-fns+.el':
https://www.emacswiki.org/emacs/download/help-fns%2b.el
My code differs here: it tests SYM because
there's conditional code that can set it:
(let ((sym nil))
(when search-symbols-p ; <==================
(setq sym (catch 'describe-keymap ; <====
(mapatoms
(lambda (symb)
(when (and (boundp symb)
(eq (symbol-value symb) keymap)
(not (eq symb 'keymap))
(throw 'describe-keymap symb)))))
nil)))
(unless sym ; <=============================
(setq sym (cl-gentemp "KEYMAP OBJECT (no variable) "))
(set sym keymap))
(setq keymap sym))
Vanilla code:
(let ((sym nil))
(unless sym
(setq sym (cl-gentemp "KEYMAP OBJECT (no variable) "))
(setq used-gentemp t)
(set sym keymap))
(setq keymap sym))
In my code, `describe-keymap' takes optional arg
SEARCH-SYMBOLS-P. That's used non-interactively
to search all vars for one whose value is KEYMAP,
when KEYMAP isn't a symbol. It tells you a var
(if there is one) that corresponds to the KEYMAP.
It's a feature that was suggested by a user.
Vanilla Emacs didn't want/include the feature, so
yes, the `(unless sym' test there is gratuitous
(but harmless).