GNU bug report logs - #20600
24.5.3: add-hook - wrong arguments error

Previous Next

Package: emacs;

Reported by: Andreas Röhler <andreas.roehler <at> easy-emacs.de>

Date: Mon, 18 May 2015 05:35:02 UTC

Severity: wishlist

Tags: notabug, wontfix

Found in version 24.5.3

Done: Glenn Morris <rgm <at> gnu.org>

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 20600 in the body.
You can then email your comments to 20600 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#20600; Package emacs. (Mon, 18 May 2015 05:35:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Andreas Röhler <andreas.roehler <at> easy-emacs.de>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Mon, 18 May 2015 05:35:03 GMT) Full text and rfc822 format available.

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

From: Andreas Röhler <andreas.roehler <at> easy-emacs.de>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.5.3: add-hook - wrong arguments error
Date: Mon, 18 May 2015 07:34:42 +0200
[Message part 1 (text/plain, inline)]
||after-change-functions|  wrongly accepts functions with three args only
 
Issue is explained in docstring of workaround below.
If the function to be hooked in --save-buffer-- doesn't require args, add-hook resp. after-change-functions should not.

(defun my-instant-save-buffer (eins zwei drei)
  "To be hooked into list `after-change-functions'

`after-change-functions' expects functions receiving three arguments.
Arguments are ignored here, but slots needed by add-hook"
  (save-buffer))

(add-hook 'after-change-functions 'my-instant-save-buffer)|

[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#20600; Package emacs. (Mon, 18 May 2015 11:55:02 GMT) Full text and rfc822 format available.

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

From: Artur Malabarba <bruce.connor.am <at> gmail.com>
To: Andreas Röhler <andreas.roehler <at> easy-emacs.de>
Cc: 20600 <at> debbugs.gnu.org
Subject: Re: bug#20600: 24.5.3: add-hook - wrong arguments error
Date: Mon, 18 May 2015 12:54:25 +0100
[Message part 1 (text/plain, inline)]
The function you present is not a workaround, it's the right way to do this.

Still, it sounds like it might be useful for run-hooks to properly handle
functions whose arity is less than the expected arity.
Does anyone foresee any issues with that?
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#20600; Package emacs. (Mon, 18 May 2015 14:26:02 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: bruce.connor.am <at> gmail.com
Cc: andreas.roehler <at> easy-emacs.de, 20600 <at> debbugs.gnu.org
Subject: Re: bug#20600: 24.5.3: add-hook - wrong arguments error
Date: Mon, 18 May 2015 17:25:24 +0300
> Date: Mon, 18 May 2015 12:54:25 +0100
> From: Artur Malabarba <bruce.connor.am <at> gmail.com>
> Cc: 20600 <at> debbugs.gnu.org
> 
> Still, it sounds like it might be useful for run-hooks to properly handle
> functions whose arity is less than the expected arity.
> Does anyone foresee any issues with that?

To tell you the truth, I don't see the problem.  Is the problem the
need to specify a couple of arguments that will be left unused when
the function is called?  If so, we do it all over the place; we even
have a special convention for that.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#20600; Package emacs. (Mon, 18 May 2015 15:39:02 GMT) Full text and rfc822 format available.

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

From: Artur Malabarba <bruce.connor.am <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: Andreas Röhler <andreas.roehler <at> easy-emacs.de>,
 20600 <at> debbugs.gnu.org
Subject: Re: bug#20600: 24.5.3: add-hook - wrong arguments error
Date: Mon, 18 May 2015 16:38:42 +0100
> To tell you the truth, I don't see the problem.  Is the problem the
> need to specify a couple of arguments that will be left unused when
> the function is called?  If so, we do it all over the place; we even
> have a special convention for that.

I don't see a problem either, I'm just suggesting an improvement on run-hooks.
The improvement would reduce the number of times you have to define a
wrapper around a function just to use it in a hook, by just not
passing to the function more arguments than it accepts.

Although, to be honest, I don't know how often that would be useful.
Even in the case originally mentioned above it would actually *not*
useful, because `save-buffer` *does* take an optional argument so the
wrapper around it would still be necessary.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#20600; Package emacs. (Mon, 18 May 2015 16:48:02 GMT) Full text and rfc822 format available.

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

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Artur Malabarba <bruce.connor.am <at> gmail.com>
Cc: Andreas Röhler <andreas.roehler <at> easy-emacs.de>,
 20600 <at> debbugs.gnu.org
Subject: Re: bug#20600: 24.5.3: add-hook - wrong arguments error
Date: Mon, 18 May 2015 12:47:08 -0400
> Still, it sounds like it might be useful for run-hooks to properly handle
> functions whose arity is less than the expected arity.

I have no idea what kind of "properly handle" you're thinking of.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#20600; Package emacs. (Mon, 18 May 2015 17:30:05 GMT) Full text and rfc822 format available.

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

From: Artur Malabarba <bruce.connor.am <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 20600 <at> debbugs.gnu.org
Subject: Re: bug#20600: 24.5.3: add-hook - wrong arguments error
Date: Mon, 18 May 2015 18:29:25 +0100
2015-05-18 17:47 GMT+01:00 Stefan Monnier

>> Still, it sounds like it might be useful for run-hooks to properly handle
>> functions whose arity is less than the expected arity.
>
> I have no idea what kind of "properly handle" you're thinking of.

(add-hook '1-arity-functions 'some-zero-arity-function)
(run-hooks '1-arity-functions some-arg)

Here, it will throw an error because run-hooks will try to call
(some-zero-arity-function some-arg). That's all fine and well
documented, I'm just saying it may be more convenient if run-hooks
took care to check that some-zero-arity-function has zero arity and
invoked it without arguments.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#20600; Package emacs. (Mon, 18 May 2015 17:50:08 GMT) Full text and rfc822 format available.

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

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Artur Malabarba <bruce.connor.am <at> gmail.com>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 20600 <at> debbugs.gnu.org
Subject: Re: bug#20600: 24.5.3: add-hook - wrong arguments error
Date: Mon, 18 May 2015 13:49:49 -0400
> The improvement would reduce the number of times you have to define a
> wrapper around a function just to use it in a hook, by just not
> passing to the function more arguments than it accepts.

Sounds dangerous and rarely useful.


        Stefan




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#20600; Package emacs. (Mon, 18 May 2015 18:23:03 GMT) Full text and rfc822 format available.

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

From: Artur Malabarba <bruce.connor.am <at> gmail.com>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 20600 <at> debbugs.gnu.org
Subject: Re: bug#20600: 24.5.3: add-hook - wrong arguments error
Date: Mon, 18 May 2015 19:22:36 +0100
> Sounds dangerous and rarely useful.

Ok thanks. That's what I wanted to know. :-)




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#20600; Package emacs. (Tue, 19 May 2015 08:19:02 GMT) Full text and rfc822 format available.

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

From: Andreas Röhler <andreas.roehler <at> easy-emacs.de>
To: bug-gnu-emacs <at> gnu.org
Subject: Re: bug#20600: 24.5.3: add-hook - wrong arguments error
Date: Tue, 19 May 2015 10:17:51 +0200
Am 18.05.2015 um 19:29 schrieb Artur Malabarba:
> 2015-05-18 17:47 GMT+01:00 Stefan Monnier
>

Thanks all! Seems indeed rather a matter of understanding than a bug.
Can live with it.

close #20600




Added tag(s) notabug and wontfix. Request was from Glenn Morris <rgm <at> gnu.org> to control <at> debbugs.gnu.org. (Tue, 19 May 2015 17:37:01 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 20600 <at> debbugs.gnu.org and Andreas Röhler <andreas.roehler <at> easy-emacs.de> Request was from Glenn Morris <rgm <at> gnu.org> to control <at> debbugs.gnu.org. (Tue, 19 May 2015 17:37:02 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. (Wed, 17 Jun 2015 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 10 years and 10 days ago.

Previous Next


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