GNU bug report logs - #24221
25.1.50; binding anonymous functions to keys cause help buffer navigation errors

Previous Next

Package: emacs;

Reported by: Zachary Kanfer <zkanfer <at> gmail.com>

Date: Sun, 14 Aug 2016 01:01:01 UTC

Severity: normal

Tags: fixed, patch

Found in version 25.1.50

Fixed in version 25.2

Done: npostavs <at> users.sourceforge.net

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 24221 in the body.
You can then email your comments to 24221 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#24221; Package emacs. (Sun, 14 Aug 2016 01:01:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Zachary Kanfer <zkanfer <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sun, 14 Aug 2016 01:01:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Zachary Kanfer <zkanfer <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 25.1.50; binding anonymous functions to keys cause help buffer
 navigation errors
Date: Sat, 13 Aug 2016 20:59:37 -0400
[Message part 1 (text/plain, inline)]
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))
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#24221; Package emacs. (Sun, 28 Aug 2016 20:09:01 GMT) Full text and rfc822 format available.

Message #8 received at 24221 <at> debbugs.gnu.org (full text, mbox):

From: peder <at> klingenberg.no (Peder O. Klingenberg)
To: Zachary Kanfer <zkanfer <at> gmail.com>
Cc: 24221 <at> debbugs.gnu.org
Subject: Re: bug#24221: 25.1.50;
 binding anonymous functions to keys cause help buffer navigation
 errors
Date: Sun, 28 Aug 2016 22:07:57 +0200
Zachary Kanfer <zkanfer <at> 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.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#24221; Package emacs. (Sun, 28 Aug 2016 21:57:01 GMT) Full text and rfc822 format available.

Message #11 received at 24221 <at> debbugs.gnu.org (full text, mbox):

From: Drew Adams <drew.adams <at> oracle.com>
To: peder <at> klingenberg.no, Zachary Kanfer <zkanfer <at> gmail.com>
Cc: 24221 <at> debbugs.gnu.org
Subject: RE: bug#24221: 25.1.50; binding anonymous functions to keys cause
 help buffer navigation errors
Date: Sun, 28 Aug 2016 14:56:11 -0700 (PDT)
> > 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.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#24221; Package emacs. (Fri, 16 Sep 2016 17:44:01 GMT) Full text and rfc822 format available.

Message #14 received at 24221 <at> debbugs.gnu.org (full text, mbox):

From: Drew Adams <drew.adams <at> oracle.com>
To: peder <at> klingenberg.no, Zachary Kanfer <zkanfer <at> gmail.com>
Cc: 24221 <at> debbugs.gnu.org
Subject: RE: bug#24221: 25.1.50; binding anonymous functions to keys cause
 help buffer navigation errors
Date: Fri, 16 Sep 2016 10:43:46 -0700 (PDT)
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.)




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#24221; Package emacs. (Sat, 17 Sep 2016 18:29:01 GMT) Full text and rfc822 format available.

Message #17 received at 24221 <at> debbugs.gnu.org (full text, mbox):

From: Drew Adams <drew.adams <at> oracle.com>
To: peder <at> klingenberg.no, Zachary Kanfer <zkanfer <at> gmail.com>
Cc: 24221 <at> debbugs.gnu.org
Subject: RE: bug#24221: 25.1.50; binding anonymous functions to keys cause
 help buffer navigation errors
Date: Sat, 17 Sep 2016 11:28:47 -0700 (PDT)
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 ...)
    ...)




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#24221; Package emacs. (Mon, 03 Oct 2016 23:34:03 GMT) Full text and rfc822 format available.

Message #20 received at 24221 <at> debbugs.gnu.org (full text, mbox):

From: npostavs <at> users.sourceforge.net
To: Drew Adams <drew.adams <at> oracle.com>
Cc: 24221 <at> debbugs.gnu.org, peder <at> klingenberg.no,
 Zachary Kanfer <zkanfer <at> gmail.com>
Subject: Re: bug#24221: 25.1.50;
 binding anonymous functions to keys cause help buffer navigation
 errors
Date: Mon, 03 Oct 2016 19:33:50 -0400
[Message part 1 (text/plain, inline)]
tags 24221 patch
quit

Drew Adams <drew.adams <at> 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:

[v1-0001-Let-describe-function-work-for-lambda-again.patch (text/plain, inline)]
From 7dffe1868222f33c8845cac7b5e46836149c72f8 Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs <at> 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


Added tag(s) patch. Request was from npostavs <at> users.sourceforge.net to control <at> debbugs.gnu.org. (Mon, 03 Oct 2016 23:34:03 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#24221; Package emacs. (Sat, 22 Oct 2016 02:48:02 GMT) Full text and rfc822 format available.

Message #25 received at 24221 <at> debbugs.gnu.org (full text, mbox):

From: npostavs <at> users.sourceforge.net
To: Drew Adams <drew.adams <at> oracle.com>
Cc: 24221 <at> debbugs.gnu.org, peder <at> klingenberg.no,
 Zachary Kanfer <zkanfer <at> gmail.com>
Subject: Re: bug#24221: 25.1.50;
 binding anonymous functions to keys cause help buffer navigation
 errors
Date: Fri, 21 Oct 2016 22:48:05 -0400
tags 24221 fixed
close 24221 25.2
quit

npostavs <at> users.sourceforge.net writes:

>
> Here's a patch that moves the checks into the interactive form and
> updates the docstring:

Pushed as 24e4e4e8




Added tag(s) fixed. Request was from npostavs <at> users.sourceforge.net to control <at> debbugs.gnu.org. (Sat, 22 Oct 2016 02:48:03 GMT) Full text and rfc822 format available.

bug marked as fixed in version 25.2, send any further explanations to 24221 <at> debbugs.gnu.org and Zachary Kanfer <zkanfer <at> gmail.com> Request was from npostavs <at> users.sourceforge.net to control <at> debbugs.gnu.org. (Sat, 22 Oct 2016 02:48:03 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 19 Nov 2016 12:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 8 years and 270 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.