* bug#24221: 25.1.50; binding anonymous functions to keys cause help buffer navigation errors
@ 2016-08-14 0:59 Zachary Kanfer
2016-08-28 20:07 ` Peder O. Klingenberg
0 siblings, 1 reply; 7+ messages in thread
From: Zachary Kanfer @ 2016-08-14 0:59 UTC (permalink / raw)
To: 24221
[-- Attachment #1: Type: text/plain, Size: 3961 bytes --]
This is a bug that happens when trying to navigate between two *Help*
buffers.
==Reproduction instructions==
emacs -Q
Evaluate this code:
(global-set-key (kbd "C-c l") (lambda () (interactive) (insert "This
messes up the help buffer somehow.")))
Then open up a help buffer for that function:
C-h k C-c l
And a help buffer for something else:
C-h k a
Then, in the help buffer, go to the bottom, and try to select the
"[back]" link. I get an error: "user-error: You didn’t specify a function
symbol". If I try again, I get a different error: "apply: Symbol’s
function definition is void: nil". These errors happen whether I've
select the link with pressing Enter on the keyboard or by clicking the
mouse.
==End of instructions==
In GNU Emacs 25.1.50.2 (x86_64-unknown-linux-gnu, GTK+ Version 3.18.9)
of 2016-07-10 built on zck-laptop
Repository revision: 466ee1b3ea76425d201b5d59950e88251870c836
Windowing system distributor 'The X.Org Foundation', version 11.0.11803000
System Description: Ubuntu 16.04.1 LTS
Recent messages:
Mark set
(lambda nil (interactive) (insert "This messes up the help buffer
somehow."))
Type C-x 1 to delete the help window.
Mark set
user-error: You didn’t specify a function symbol
apply: Symbol’s function definition is void: nil
scroll-up-command: End of buffer [2 times]
apply: Symbol’s function definition is void: nil [3 times]
p is undefined
Configured features:
XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS GCONF GSETTINGS
NOTIFY ACL LIBSELINUX GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB
TOOLKIT_SCROLL_BARS GTK3 X11
Important settings:
value of $LANG: en_US.UTF-8
value of $XMODIFIERS: @im=ibus
locale-coding-system: utf-8-unix
Major mode: Lisp Interaction
Minor modes in effect:
tooltip-mode: t
global-eldoc-mode: t
electric-indent-mode: t
mouse-wheel-mode: t
tool-bar-mode: t
menu-bar-mode: t
file-name-shadow-mode: t
global-font-lock-mode: t
font-lock-mode: t
blink-cursor-mode: t
auto-composition-mode: t
auto-encryption-mode: t
auto-compression-mode: t
line-number-mode: t
transient-mark-mode: t
Load-path shadows:
None found.
Features:
(shadow sort mail-extr emacsbug message puny seq byte-opt gv bytecomp
byte-compile cconv dired dired-loaddefs format-spec rfc822 mml mml-sec
password-cache epa derived epg epg-config gnus-util rmail rmail-loaddefs
mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev gmm-utils
mailheader sendmail rfc2047 rfc2045 ietf-drums mm-util mail-prsvr
mail-utils cl-extra help-fns radix-tree help-mode easymenu edmacro
kmacro cl-loaddefs pcase cl-lib time-date mule-util tooltip eldoc
electric uniquify ediff-hook vc-hooks lisp-float-type mwheel term/x-win
x-win term/common-win x-dnd tool-bar dnd fontset image regexp-opt fringe
tabulated-list newcomment elisp-mode lisp-mode prog-mode register page
menu-bar rfn-eshadow timer select scroll-bar mouse jit-lock font-lock
syntax facemenu font-core term/tty-colors frame cl-generic cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european
ethiopic indian cyrillic chinese charscript case-table epa-hook
jka-cmpr-hook help simple abbrev obarray minibuffer cl-preloaded nadvice
loaddefs button faces cus-face macroexp files text-properties overlay
sha1 md5 base64 format env code-pages mule custom widget
hashtable-print-readable backquote dbusbind inotify dynamic-setting
system-font-setting font-render-setting move-toolbar gtk x-toolkit x
multi-tty make-network-process emacs)
Memory information:
((conses 16 98309 6988)
(symbols 48 20970 0)
(miscs 40 262 168)
(strings 32 18601 4494)
(string-bytes 1 595182)
(vectors 16 13861)
(vector-slots 8 449156 6768)
(floats 8 188 43)
(intervals 56 248 0)
(buffers 976 12)
(heap 1024 25332 985))
[-- Attachment #2: Type: text/html, Size: 4371 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#24221: 25.1.50; binding anonymous functions to keys cause help buffer navigation errors
2016-08-14 0:59 bug#24221: 25.1.50; binding anonymous functions to keys cause help buffer navigation errors Zachary Kanfer
@ 2016-08-28 20:07 ` Peder O. Klingenberg
2016-08-28 21:56 ` Drew Adams
0 siblings, 1 reply; 7+ messages in thread
From: Peder O. Klingenberg @ 2016-08-28 20:07 UTC (permalink / raw)
To: Zachary Kanfer; +Cc: 24221
Zachary Kanfer <zkanfer@gmail.com> writes:
> emacs -Q
>
> Evaluate this code:
>
> (global-set-key (kbd "C-c l") (lambda () (interactive) (insert "This
> messes up the help buffer somehow.")))
>
> Then open up a help buffer for that function:
>
> C-h k C-c l
>
> And a help buffer for something else:
>
> C-h k a
>
> Then, in the help buffer, go to the bottom, and try to select the
> "[back]" link. I get an error: "user-error: You didn’t specify a function
> symbol". If I try again, I get a different error: "apply: Symbol’s
> function definition is void: nil". These errors happen whether I've
> select the link with pressing Enter on the keyboard or by clicking the
> mouse.
I can confirm this. Here's what I think is happening:
`describe-key' (C-h k) finds your lambda expression when it calls
`key-binding'. It then pushes this lambda on the help-xref-stack as an
argument to `describe-function'. But `describe-function' doesn't know
what to do with a lamda expression, and gives you that "You didn't
specify a function symbol" message when the xref stack is popped and
`describe-function' is called.
I don't know what the best fix would be - fix the xref setup in
`describe-key' or teach `describe-function' to do something useful with
a lambda expression.
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#24221: 25.1.50; binding anonymous functions to keys cause help buffer navigation errors
2016-08-28 20:07 ` Peder O. Klingenberg
@ 2016-08-28 21:56 ` Drew Adams
2016-09-16 17:43 ` Drew Adams
0 siblings, 1 reply; 7+ messages in thread
From: Drew Adams @ 2016-08-28 21:56 UTC (permalink / raw)
To: peder, Zachary Kanfer; +Cc: 24221
> > C-h k C-c l
> > And a help buffer for something else:
> > C-h k a
> >
> > Then, in the help buffer, go to the bottom, and try to select the
> > "[back]" link. I get an error: "user-error: You didn’t specify a
> > function symbol".
This is apparently a regression from Emacs 24.5.
I see the same regression in this older pre-Emacs 25 build:
In GNU Emacs 25.0.50.1 (i686-pc-mingw32)
of 2015-05-29 on LEG570
Windowing system distributor `Microsoft Corp.', version 6.1.7601
Configured using:
`configure --prefix=/mingw32 --host=i686-pc-mingw32
--enable-checking=yes,glyphs'
So it seems to have been introduced on or before 2015-05-29.
And I do not see the regression in this older pre-25 build:
In GNU Emacs 25.0.50.1 (i686-pc-mingw32)
of 2015-04-05 on LEG570
Repository revision: 16eec6fc55dcc05d1d819f18998e84a9580b2521
Windowing system distributor `Microsoft Corp.', version 6.1.7601
Configured using:
`configure --host=i686-pc-mingw32 --enable-checking=yes,glyphs'
So it seems to have been introduced after 2015-04-05, i.e., between
2015-04-05 and 2015-05-29.
> I don't know what the best fix would be - fix the xref setup in
> `describe-key' or teach `describe-function' to do something useful with
> a lambda expression.
Remove the regression. Maybe restore some of the code from before
it was introduced.
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#24221: 25.1.50; binding anonymous functions to keys cause help buffer navigation errors
2016-08-28 21:56 ` Drew Adams
@ 2016-09-16 17:43 ` Drew Adams
2016-09-17 18:28 ` Drew Adams
2016-10-03 23:33 ` npostavs
0 siblings, 2 replies; 7+ messages in thread
From: Drew Adams @ 2016-09-16 17:43 UTC (permalink / raw)
To: peder, Zachary Kanfer; +Cc: 24221
This is the problem behind this regression:
1. `describe-key' calls `describe-function', passing it the
command definition.
2. Someone changed `describe-function' so that it now barfs
if its arg is not a function symbol.
The doc string of `describe-function' says (and has long
said) that the arg is a symbol. However, that should be
the case only for interactive use (the `completing-read'
call requires a match against a function symbol).
What should be done:
1. Remove the error for a non-symbol, except perhaps for the
interactive case.
2. Fix the doc, to say that it need not be a symbol when
called from Lisp.
Before the regression was introduced, both `describe-function'
and using `[back]' to get to it worked for a lambda form.
And a doc string in the lambda form was shown correctly as
the doc, in *Help* - just as if the function had a name.
And a byte-compiled lambda form also worked perfectly well
prior to the introduction of the regression:
(global-set-key
(kbd "C-c l")
(byte-compile
(lambda () "DOC" (interactive) (message "FOO"))))
This regression removed a bunch of useful behavior.
`describe-function' should describe a function - any
function. The argument should be limited to a function
symbol only when called interactively.
(An argument could even be made that it should not even
be so limited for interactive use, that is, that
`completing-read' should be lax, letting you type a
lambda form if you want. I'm not making that argument
here, however.)
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#24221: 25.1.50; binding anonymous functions to keys cause help buffer navigation errors
2016-09-16 17:43 ` Drew Adams
@ 2016-09-17 18:28 ` Drew Adams
2016-10-03 23:33 ` npostavs
1 sibling, 0 replies; 7+ messages in thread
From: Drew Adams @ 2016-09-17 18:28 UTC (permalink / raw)
To: peder, Zachary Kanfer; +Cc: 24221
I suggest using code such as that below - allow FUNCTION to be
`functionp', not only a symbol that is `fboundp' (and test for
the former first).
Also, the function that raises an error should be `user-error'
only when called interactively. Otherwise, it should be `error'.
[I would even argue that for interactive use it should be
`message', not `user-error', as that allows `describe-function'
to be used, e.g., in the minibuffer to get help on different
function-name candidates.]
(let* ((interactivep (called-interactively-p 'interactive))
(err-fn (if interactivep #user-error #'error)))
(if (and interactivep (not function))
(funcall err-fn "You did not specify a function symbol")
(if (not (or (functionp function) ; Allow anonymous functions.
(and function ; Allow macros and special forms.
(fboundp (intern-soft function))))))
(funcall err-fn "Not a defined function: `%S'" function)
(help-setup-xref ...)
...)
^ permalink raw reply [flat|nested] 7+ messages in thread
* bug#24221: 25.1.50; binding anonymous functions to keys cause help buffer navigation errors
2016-09-16 17:43 ` Drew Adams
2016-09-17 18:28 ` Drew Adams
@ 2016-10-03 23:33 ` npostavs
2016-10-22 2:48 ` npostavs
1 sibling, 1 reply; 7+ messages in thread
From: npostavs @ 2016-10-03 23:33 UTC (permalink / raw)
To: Drew Adams; +Cc: 24221, peder, Zachary Kanfer
[-- Attachment #1: Type: text/plain, Size: 489 bytes --]
tags 24221 patch
quit
Drew Adams <drew.adams@oracle.com> writes:
>
> 2. Someone changed `describe-function' so that it now barfs
> if its arg is not a function symbol.
Yes, seems to have been 82d0f42a "* lisp/help-fns.el
(describe-function): More type checking[...]". I think it was an
accident: the non-interactive case wasn't considered, probably because
the docstring doesn't mention it.
Here's a patch that moves the checks into the interactive form and
updates the docstring:
[-- Attachment #2: patch --]
[-- Type: text/plain, Size: 2804 bytes --]
From 7dffe1868222f33c8845cac7b5e46836149c72f8 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@gmail.com>
Date: Mon, 3 Oct 2016 18:49:56 -0400
Subject: [PATCH v1] Let describe-function work for lambda again
Since commit "* lisp/help-fns.el (describe-function): More type
checking[...]", `describe-function' throws a user-error when given a
non-symbol. This prevents the [back] button in a *Help* buffer from
working when the page it goes back to describes an anonymous
function (e.g., the result of `describe-key' on a key which is bound to
a lambda form).
* lisp/help-fns.el (describe-function): Move the checks on FUNCTION
being an fbound symbol into the `interactive' form. This allows
non-interactive calls to pass an anonymous function (Bug #24221). Note
that passing a non-bound symbol non-interactively will still trigger a
`void-function' error from `describe-function-1'.
---
lisp/help-fns.el | 33 +++++++++++++++++----------------
1 file changed, 17 insertions(+), 16 deletions(-)
diff --git a/lisp/help-fns.el b/lisp/help-fns.el
index 26d8839..7dfa670 100644
--- a/lisp/help-fns.el
+++ b/lisp/help-fns.el
@@ -50,23 +50,24 @@ describe-function-orig-buffer
;;;###autoload
(defun describe-function (function)
- "Display the full documentation of FUNCTION (a symbol)."
+ "Display the full documentation of FUNCTION (a symbol).
+When called from lisp, FUNCTION may also be a function object."
(interactive
- (let ((fn (function-called-at-point))
- (enable-recursive-minibuffers t)
- val)
- (setq val (completing-read (if fn
- (format "Describe function (default %s): " fn)
- "Describe function: ")
- obarray 'fboundp t nil nil
- (and fn (symbol-name fn))))
- (list (if (equal val "")
- fn (intern val)))))
- (or (and function (symbolp function))
- (user-error "You didn't specify a function symbol"))
- (or (fboundp function)
- (user-error "Symbol's function definition is void: %s" function))
-
+ (let* ((fn (function-called-at-point))
+ (enable-recursive-minibuffers t)
+ (val (completing-read
+ (if fn
+ (format "Describe function (default %s): " fn)
+ "Describe function: ")
+ obarray 'fboundp t nil nil
+ (and fn (symbol-name fn)))))
+ (unless (equal val "")
+ (setq fn (intern val)))
+ (unless (and fn (symbolp fn))
+ (user-error "You didn't specify a function symbol"))
+ (unless (fboundp fn)
+ (user-error "Symbol's function definition is void: %s" fn))
+ (list fn)))
;; We save describe-function-orig-buffer on the help xref stack, so
;; it is restored by the back/forward buttons. 'help-buffer'
;; expects (current-buffer) to be a help buffer when processing
--
2.9.3
^ permalink raw reply related [flat|nested] 7+ messages in thread
* bug#24221: 25.1.50; binding anonymous functions to keys cause help buffer navigation errors
2016-10-03 23:33 ` npostavs
@ 2016-10-22 2:48 ` npostavs
0 siblings, 0 replies; 7+ messages in thread
From: npostavs @ 2016-10-22 2:48 UTC (permalink / raw)
To: Drew Adams; +Cc: 24221, peder, Zachary Kanfer
tags 24221 fixed
close 24221 25.2
quit
npostavs@users.sourceforge.net writes:
>
> Here's a patch that moves the checks into the interactive form and
> updates the docstring:
Pushed as 24e4e4e8
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2016-10-22 2:48 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-08-14 0:59 bug#24221: 25.1.50; binding anonymous functions to keys cause help buffer navigation errors Zachary Kanfer
2016-08-28 20:07 ` Peder O. Klingenberg
2016-08-28 21:56 ` Drew Adams
2016-09-16 17:43 ` Drew Adams
2016-09-17 18:28 ` Drew Adams
2016-10-03 23:33 ` npostavs
2016-10-22 2:48 ` npostavs
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).