all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: 19915@debbugs.gnu.org
Subject: 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:14:44 -0800 (PST)	[thread overview]
Message-ID: <66d452bd-fa38-40e7-b16e-8fe4756d5fab@default> (raw)

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@gnu.org-20141020195941-icp42t8ttcnud09g
Windowing system distributor `Microsoft Corp.', version 6.1.7601
Configured using:
 `configure --enable-checking=yes,glyphs CPPFLAGS=-DGLYPH_DEBUG=1'





             reply	other threads:[~2015-02-21 20:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-21 20:14 Drew Adams [this message]
2015-02-21 20:30 ` bug#19915: 25.0.50; defadvice for `org-store-link' makes code fail because of `org-called-interactively-p' Drew Adams
2018-01-03 17:09   ` Nicolas Goaziou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=66d452bd-fa38-40e7-b16e-8fe4756d5fab@default \
    --to=drew.adams@oracle.com \
    --cc=19915@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.