From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: raman@google.com (T.V Raman) Newsgroups: gmane.emacs.devel Subject: RE: Brittleness of called-interactively-p Date: Thu, 16 Jul 2015 10:58:53 -0700 Message-ID: <21927.61661.861463.374658@retriever.mtv.corp.google.com> References: <871tgeufzt.fsf@gmail.com> <87r3odtngi.fsf@gmail.com> <87380st7c1.fsf@gmail.com> <56ffd903-483b-49cf-acf1-f17c1231537e@default> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1437069546 10270 80.91.229.3 (16 Jul 2015 17:59:06 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 16 Jul 2015 17:59:06 +0000 (UTC) Cc: dpaduchikh@gmail.com, emacs-devel@gnu.org, monnier@IRO.UMontreal.CA, raman@google.com To: drew.adams@oracle.com Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jul 16 19:59:02 2015 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZFnQz-0005Tu-Jv for ged-emacs-devel@m.gmane.org; Thu, 16 Jul 2015 19:59:01 +0200 Original-Received: from localhost ([::1]:41366 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZFnQz-0000nj-26 for ged-emacs-devel@m.gmane.org; Thu, 16 Jul 2015 13:59:01 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39022) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZFnQw-0000ne-57 for emacs-devel@gnu.org; Thu, 16 Jul 2015 13:58:59 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZFnQu-0000GW-QE for emacs-devel@gnu.org; Thu, 16 Jul 2015 13:58:58 -0400 Original-Received: from mail-ig0-x22d.google.com ([2607:f8b0:4001:c05::22d]:35202) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZFnQu-0000Fq-JP for emacs-devel@gnu.org; Thu, 16 Jul 2015 13:58:56 -0400 Original-Received: by igcqs7 with SMTP id qs7so19875923igc.0 for ; Thu, 16 Jul 2015 10:58:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:mime-version:content-type:content-transfer-encoding:message-id :date:to:cc:subject:in-reply-to:references; bh=2obVVbgV76mXZenfTR3emVDgdUMTFdXG/SvCqVyc03k=; b=jhtLOpftrtP5qpm+hXev5BurzAdmcTH1Sucp6hOHE7R6u1uD6l7b+nNeUBHIn3yP3B Biq/qPsjSs29UC1k7p16HCyiNRn0y3kyi4u2dkf8r05MJCY504ZdqufjB3wJtclWjsWc kbCfnEDJlf9vr8f4FPM/7bPWRUOGWk7UV0SlH5OB6RIAjGdwgvpsz8vXDCSI3edTGGoi mSeT9CCr9W1p6G/nOz92KKKZEx+7W9tDCllnaWScepJjyctuRedmVV1g3sZ9l7QYVxUh q7ij4vQ/iHmcmkkObDx5enAp4xWH6OOdi15qeDHP8mxsz4bA89aVzpp6xlBNvlLVkASs K3Nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:mime-version:content-type :content-transfer-encoding:message-id:date:to:cc:subject:in-reply-to :references; bh=2obVVbgV76mXZenfTR3emVDgdUMTFdXG/SvCqVyc03k=; b=VDOjT7SZX4pWpk3xr7Em1lSWAlgxGK/B8MYMAuVOtwkPjjwm+GFpatFTuyKxn9HIGs 8KGQ3gxOKowf99h3IeVMH/18//G+4PiVRkXvXJwqh1dawTyLhH9qlNyR/vZ3PV9NlwVs X8vE/IdI2btV0PmcoAs2WbOPBveu+DvMcbMg3NE2quqsY3/1R8GyG4H0p/7V1kJxO5Ks 4UfVL4pf+XYP9VSee27Ul6g09cYBoYIYAm7fxJUEiimk5UZdmiXeYzh9df1B0oKOqgkl DGwJ/GbuAj1t68xJzJ3OgF0sj30quV3su7NwyaPADi1Cxm/7KIMpOQEdkC5rd8q75FQ0 y97w== X-Gm-Message-State: ALoCoQkbjuiBeAsN/dPEuCkgmwiFuOi4skfqzJb4hFYJ+s9eIR99yhqASe/upb/BvHnsOGc+qRuH X-Received: by 10.50.108.98 with SMTP id hj2mr283345igb.52.1437069535892; Thu, 16 Jul 2015 10:58:55 -0700 (PDT) Original-Received: from retriever.mtv.corp.google.com ([172.27.71.174]) by smtp.gmail.com with ESMTPSA id m92sm5460961ioi.41.2015.07.16.10.58.54 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Jul 2015 10:58:54 -0700 (PDT) Original-Received: by retriever.mtv.corp.google.com (Postfix, from userid 13930) id 076A21A1819; Thu, 16 Jul 2015 10:58:53 -0700 (PDT) In-Reply-To: <56ffd903-483b-49cf-acf1-f17c1231537e@default> X-Mailer: VM 8.1.1 under 25.0.50.1 (x86_64-unknown-linux-gnu) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4001:c05::22d X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:187906 Archived-At: 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. -- --