GNU bug report logs - #19915
25.0.50; defadvice for `org-store-link' makes code fail because of `org-called-interactively-p'

Previous Next

Package: org-mode;

Reported by: Drew Adams <drew.adams <at> oracle.com>

Date: Sat, 21 Feb 2015 20:15:02 UTC

Severity: normal

Found in version 25.0.50

Done: Nicolas Goaziou <mail <at> nicolasgoaziou.fr>

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 19915 in the body.
You can then email your comments to 19915 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#19915; Package emacs. (Sat, 21 Feb 2015 20:15:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Drew Adams <drew.adams <at> oracle.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sat, 21 Feb 2015 20:15:02 GMT) Full text and rfc822 format available.

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

From: Drew Adams <drew.adams <at> oracle.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 25.0.50; defadvice for `org-store-link' makes code fail because of
 `org-called-interactively-p'
Date: Sat, 21 Feb 2015 12:14:44 -0800 (PST)
In an attempt to work around bug #19914, I tried advising
`org-store-link', as follows:

(defadvice org-store-link (before foo activate) "Reset `foo' to nil."
  (setq foo nil)) ; A defvar'd variable.

With that advice, this part of the `org-store-link' code fails:

 ;; Return the link
 (if (not (and (or (org-called-interactively-p 'any)
                   executing-kbd-macro) link))
     (or agenda-link (and link (org-make-link-string link desc)))
   (push (list link desc) org-stored-links)
   (message "Stored: %s" (or desc link))
   (when custom-id
     (setq link (concat "file:" (abbreviate-file-name
                                 (buffer-file-name)) "::#" custom-id))
     (push (list link desc) org-stored-links))
   (car org-stored-links))

The call to `org-called-interactively-p' returns nil, when it should
return non-nil (I invoked `org-store-link' interactively).  The result
is that `org-stored-links' is not updated.  If I unadvise the function
then there is no such problem.

The doc string of `called-interactively-p', which is used by
`org-called-interactively-p', says this, which seems relevant here:

  This function is very brittle, it may fail to return the intended
  result when the code is debugged, advised, or instrumented in some
                                    ^^^^^^^
  form.  Some macros and special forms (such as `condition-case') may
  also sometimes wrap their bodies in a `lambda', so any call to
  `called-interactively-p' from those bodies will indicate whether that
  lambda (rather than the surrounding function) was called
  interactively.

The Org code should presumably be changed following this part of that
doc string:

  Instead of using this function, it is cleaner and more reliable to
  give your function an extra optional argument whose `interactive' spec
  specifies non-nil unconditionally ("p" is a good way to do this), or
  via (not (or executing-kbd-macro noninteractive)).

The Org code uses `org-called-interactively-p' all over the place, it
seems.  Dunno whether other occurrences are as problematic as this one.

In GNU Emacs 25.0.50.1 (i686-pc-mingw32)
 of 2014-10-20 on LEG570
Bzr revision: 118168 rgm <at> gnu.org-20141020195941-icp42t8ttcnud09g
Windowing system distributor `Microsoft Corp.', version 6.1.7601
Configured using:
 `configure --enable-checking=yes,glyphs CPPFLAGS=-DGLYPH_DEBUG=1'




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19915; Package emacs. (Sat, 21 Feb 2015 20:31:03 GMT) Full text and rfc822 format available.

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

From: Drew Adams <drew.adams <at> oracle.com>
To: 19915 <at> debbugs.gnu.org
Subject: RE: bug#19915: 25.0.50; defadvice for `org-store-link' makes code
 fail because of `org-called-interactively-p'
Date: Sat, 21 Feb 2015 12:30:23 -0800 (PST)
And yes, `advice-add' does not have the same problem.

But it is a shame to limit users to recent Emacs versions
just because Org uses `called-interactively' instead of
adding an argument that indicates whether the command is
called interactively (as Emacs recommends).




Reply sent to Nicolas Goaziou <mail <at> nicolasgoaziou.fr>:
You have taken responsibility. (Wed, 03 Jan 2018 17:10:02 GMT) Full text and rfc822 format available.

Notification sent to Drew Adams <drew.adams <at> oracle.com>:
bug acknowledged by developer. (Wed, 03 Jan 2018 17:10:03 GMT) Full text and rfc822 format available.

Message #13 received at 19915-done <at> debbugs.gnu.org (full text, mbox):

From: Nicolas Goaziou <mail <at> nicolasgoaziou.fr>
To: Drew Adams <drew.adams <at> oracle.com>
Cc: 19915-done <at> debbugs.gnu.org
Subject: Re: bug#19915: 25.0.50;
 defadvice for `org-store-link' makes code fail because of
 `org-called-interactively-p'
Date: Wed, 03 Jan 2018 18:09:55 +0100
Hello,

Drew Adams <drew.adams <at> oracle.com> writes:

> And yes, `advice-add' does not have the same problem.
>
> But it is a shame to limit users to recent Emacs versions
> just because Org uses `called-interactively' instead of
> adding an argument that indicates whether the command is
> called interactively (as Emacs recommends).

I removed call to `called-interactively-p' in `org-store-link' (in
development version).

Thank you.

Regards,

-- 
Nicolas Goaziou                                                0x80A93738




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

This bug report was last modified 7 years and 196 days ago.

Previous Next


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