Note: replies redirected to xemacs-patches.
Michael Kifer pointed out that advice does not work properly in
keyboard macros, see issue556.  This is because `(interactive-p)'
evaluates to nil when in a keyboard macro.  What we really want in
this case is what GNU calls `called-interactively-p', maybe.
I'm not entirely sure whether that is really appropriate, since
`called-interactively-p' can be true in batch-mode!  In fact, this
patch implements `called-interactively-p' in terms of `interactive-p',
and it will be false in batch-mode.
This patch fixes it locally to advice, and after light testing I think
it should be applied.
However, in the longer run we should define `call-interactively' in
the core (at least in 21.5), and move the compatibility definition to
a package.  APEL would be a possibility, but APEL is a real horror
because it does compilation conditional on the Emacs compiling it.  I
think a portability library should focus on correctness first, so I
strongly dislike requiring APEL.  I thought about creating a better
portability library, but that seems unlikely to happen very quickly.
Unless there's an objection, I'll commit in a day or so.
Index: ChangeLog
===================================================================
RCS file: /pack/xemacscvs/XEmacs/packages/xemacs-packages/xemacs-base/ChangeLog,v
retrieving revision 1.215
diff -u -r1.215 ChangeLog
--- ChangeLog	13 Jan 2009 17:25:21 -0000	1.215
+++ ChangeLog	19 Aug 2009 06:12:49 -0000
@@ -0,0 +1,11 @@
+2009-08-19  Stephen J. Turnbull  <stephen(a)xemacs.org>
+
+	Conditionally define and use `called-interactively-p'.
+
+	* advice.el (called-interactively-p): defun if not fboundp.
+	(car): Use it in example.
+	(ad-enable-regexp):
+	(ad-disable-regexp):
+	(ad-make-advised-definition):
+	Use it instead of `interactive-p'.
+
Index: advice.el
===================================================================
RCS file: /pack/xemacscvs/XEmacs/packages/xemacs-packages/xemacs-base/advice.el,v
retrieving revision 1.2
diff -u -r1.2 advice.el
--- advice.el	18 Dec 2007 20:54:52 -0000	1.2
+++ advice.el	19 Aug 2009 06:12:50 -0000
@@ -218,7 +218,7 @@
 ;;  "Make `car' an interactive function."
 ;;   (interactive "xCar of list: ")
 ;;   ad-do-it
-;;   (if (interactive-p)
+;;   (if (called-interactively-p)
 ;;       (message "%s" ad-return-value)))
 
 
@@ -1825,8 +1825,18 @@
 (defmacro ad-xemacs-p ()
   ;;Expands into Non-nil constant if we run XEmacs.
   ;;Unselected conditional code will be optimized away during compilation.
-  (string-match "XEmacs" emacs-version))
+  (or (featurep 'xemacs) (string-match "XEmacs" emacs-version)))
 
+;; #### This compatibility kludge should be moved into a `future' package.
+(unless (fboundp 'called-interactively-p)
+  (defsubst called-interactively-p ()
+    "Non-nil if this function was invoked with `call-interactively'.
+`call-interactively' is implicitly applied when a function is invoked as a
+command, as well as the occasional explicit use by commands which delegate
+argument gathering to other functions.
+  This implementation is a kludge; semantics are different in batch-mode,
+and may subtly differ in an interactive session."
+    (or (interactive-p) executing-kbd-macro)))
 
 ;; @@ Variable definitions:
 ;; ========================
@@ -2379,7 +2389,7 @@
   (interactive
    (list (ad-read-regexp "Enable advices via regexp: ")))
   (let ((matched-advices (ad-enable-regexp-internal regexp 'any t)))
-    (if (interactive-p)
+    (if (called-interactively-p)
 	(message "%d matching advices enabled" matched-advices))
     matched-advices))
 
@@ -2389,7 +2399,7 @@
   (interactive
    (list (ad-read-regexp "Disable advices via regexp: ")))
   (let ((matched-advices (ad-enable-regexp-internal regexp 'any nil)))
-    (if (interactive-p)
+    (if (called-interactively-p)
 	(message "%d matching advices disabled" matched-advices))
     matched-advices))
 
@@ -3105,7 +3115,7 @@
 			  (not advised-interactive-form))
 		     ;; Check whether we were called interactively
 		     ;; in order to do proper prompting:
-		     (` (if (interactive-p)
+		     (` (if (called-interactively-p)
 			    (call-interactively '(, origname))
 			  (, (ad-make-mapped-call
 			      orig-arglist advised-arglist origname)))))
_______________________________________________
XEmacs-Patches mailing list
XEmacs-Patches(a)xemacs.org
http://calypso.tux.org/cgi-bin/mailman/listinfo/xemacs-patches