unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: raman@google.com (T.V Raman)
To: drew.adams@oracle.com
Cc: dpaduchikh@gmail.com, emacs-devel@gnu.org,
	monnier@IRO.UMontreal.CA, raman@google.com
Subject: RE: Brittleness of called-interactively-p
Date: Thu, 16 Jul 2015 10:58:53 -0700	[thread overview]
Message-ID: <21927.61661.861463.374658@retriever.mtv.corp.google.com> (raw)
In-Reply-To: <56ffd903-483b-49cf-acf1-f17c1231537e@default>


Apologies, the emacspeak implementation of  ems-interactive-p is in 
lisp/emacspeak-load-path.el it's fairly short and I'll append it here.

Re what failed with called-interactive-p -- from memory,  things like
ruby-mode that use backward-sexp internally during editting started
entering a recursive loop in that the emacspeak advice kept triggering
(and itself called backward-sexp again ) -- that was technically not
supposed to happen since the  advice was guarded by a
called-interactively-p check.

(defvar ems-called-interactively-p nil
  "Flag recording interactive calls.")

;; Record interactive calls:

(defsubst ems-record-interactive-p (f)
  "Predicate to test if we need to record interactive calls of
this function. Memoizes result for future use by placing a
property 'emacspeak on the function."
  (cond
   ((not (symbolp f)) nil)
   ((get f 'emacspeak) t)
   ((ad-find-some-advice f 'any  "emacspeak")
    (put f 'emacspeak t))
   ((string-match "^\\(dt\\|emacspea\\)k" (symbol-name f))
    (put f 'emacspeak t))
   (t nil)))

(defadvice call-interactively (around emacspeak  pre act comp)
  "Set emacspeak  interactive flag if there is an advice."
  (let ((ems-called-interactively-p ems-called-interactively-p))
    (when (ems-record-interactive-p (ad-get-arg 0))
      (setq ems-called-interactively-p (ad-get-arg 0)))
    ad-do-it))

(defsubst ems-interactive-p ()
  "Check our interactive flag.
Return T if set and we are called from the advice for the current
interactive command. Turn off the flag once used."
  (when ems-called-interactively-p      ; interactive call
    (let ((caller (second (backtrace-frame 1)))
          (caller-advice (ad-get-advice-info-field ems-called-interactively-p  'advicefunname))
          (result nil))
      (setq result
            (or (eq caller caller-advice) ; called from our advice
                (eq ems-called-interactively-p caller ))) ; called from call-interactively
      (when result
        (setq ems-called-interactively-p nil) ; turn off now that we used  it
        result))))

Drew Adams writes:
 > > Speaking from the perspective of developing Emacspeak:
 > > 
 > > Emacspeak uses the "is this an interactive call" heavily  -- it provides
 > > spoken feedback only if the call is interactive.
 > > 
 > > I originally implemented emacspeak starting in late 1994 and used the
 > > test (when (interactive-p)...) in all my code.
 > > 
 > > When interactive-p was deprecated and we moved to the new
 > > called-interactive-p -- I was unable to get the behavior I wanted using
 > > (called-interactive-p 'interactive) as  the test;  --  the code ended up
 > > chasing its tail given the heavy use of advice.
 > > 
 > > I worked around the problem by defining my own version of the
 > > interactive test -- see http://github.com/tvraman/emacspeak --
 > > specifically the implementation of function ems-interactive-p.
 > 
 > You might want to say which of the many (!) files in that directory
 > contains the definition of `ems-interactive-p'.  And perhaps tell us
 > why you mention it and, in particular, what is the "behavior [you]
 > wanted", and why.  You mention that `called-interactively-p' doesn't
 > work well enough for you when advice is involved, but some more info
 > about `ems-interactive-p' might be helpful.
 > 
 > FWIW, I still use `interactive-p' in much of my code, because the code
 > needs to work also with older Emacs versions.  And because I have never
 > noticed any problem, for this code anyway, with `interactive-p'.
 > 
 > What's more, the doc for `interactive-p' does not really tell you how
 > to replace it - it just says to use `called-interactively-p', without
 > any mention of which argument gives you the behavior you had previously
 > with `interactive-p' or similar-but-somehow-improved behavior.
 > 
 > `interactive-p' was indeed used heavily, over decades.  And it is no
 > doubt still in use quite a bit.  Too bad there is next-to-no guidance
 > on how to use `called-interactively-p' to replace it.

-- 

-- 



  reply	other threads:[~2015-07-16 17:58 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-12  5:00 Brittleness of called-interactively-p Dmitri Paduchikh
2015-07-12 13:53 ` Stefan Monnier
2015-07-12 15:17   ` Dmitri Paduchikh
2015-07-12 23:26     ` Stefan Monnier
2015-07-13 15:17       ` Dmitri Paduchikh
2015-07-14 23:24         ` Stefan Monnier
2015-07-16 15:57           ` raman
2015-07-16 17:36             ` Drew Adams
2015-07-16 17:58               ` T.V Raman [this message]
2015-07-17  1:55                 ` Richard Stallman
2015-07-17  4:52                   ` Dmitri Paduchikh
2015-07-17 13:36                     ` Dmitri Paduchikh
     [not found]                       ` <jwvpp3qp9dn.fsf-monnier+emacs@gnu.org>
2015-07-18  5:16                         ` Dmitri Paduchikh
2015-07-17 18:15                     ` raman
2015-07-17 18:14                   ` raman
2015-07-17 19:31                     ` Drew Adams
2015-07-17 23:25                       ` raman
2015-07-18  1:47                         ` Drew Adams
2015-07-20 12:19                       ` Andreas Röhler
2015-07-16 22:55             ` Stefan Monnier
2015-07-17 18:10               ` raman
2015-07-18  0:57                 ` Stefan Monnier
2015-07-18  4:39               ` Dmitri Paduchikh
2015-07-20 12:22                 ` Andreas Röhler
2015-07-20 22:23                 ` Stefan Monnier
2015-08-06 22:30         ` Stefan Monnier
2015-08-06 22:33         ` Stefan Monnier
2015-08-07 13:35           ` Dmitri Paduchikh
2015-08-07 17:18             ` Stefan Monnier
2015-07-18 22:29   ` raman
2015-07-12 21:59 ` Richard Stallman
2015-07-13 15:17   ` Dmitri Paduchikh
2015-07-13 23:03     ` Richard Stallman
2015-08-06 22:36     ` Stefan Monnier
2015-07-17 20:35 ` Przemysław Wojnowski

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=21927.61661.861463.374658@retriever.mtv.corp.google.com \
    --to=raman@google.com \
    --cc=dpaduchikh@gmail.com \
    --cc=drew.adams@oracle.com \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@IRO.UMontreal.CA \
    /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 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).