commandp

View: New views
4 Messages — Rating Filter:   Alert me  

commandp

by Katsumi Yamaoka :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

In the latest Emacs trunk the built-in function `commandp' returns
t or nil while it returned an interactive form or nil formerly.
Because of this, `defadvice' makes interactive Lisp functions non-
interactive.  See the `ad-interactive-form' function.  Here is
an example of what it causes:

(defun foo ()
  (interactive)
  (message "Hello"))
 => foo

(commandp 'foo)
 => t

(let ((ad-default-compilation-action 'never))
  (defadvice foo (around testing activate)
    "testing"
    (message "Good-bye")))
 => foo

(commandp 'foo)
 => nil

(pp (symbol-function 'foo))
 => (lambda nil
      "$ad-doc: foo$"
      t
      (let (ad-return-value)
        (message "Good-bye")
        ad-return-value))

Regards,


_______________________________________________
emacs-pretest-bug mailing list
emacs-pretest-bug@...
http://lists.gnu.org/mailman/listinfo/emacs-pretest-bug

Re: commandp

by Stefan Monnier :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> In the latest Emacs trunk the built-in function `commandp' returns
> t or nil while it returned an interactive form or nil formerly.

Actually formerly it returned either nil or non-nil, where the non-nil value
was sometimes t and other times the interactive form.

> Because of this, `defadvice' makes interactive Lisp functions non-
> interactive.  See the `ad-interactive-form' function.

Looks like a bug in advice.el.  I've just installed the patch below which
should hopefully fix it.


        Stefan


--- advice.el 14 jui 2007 15:01:36 -0400 1.51
+++ advice.el 26 jui 2007 14:43:27 -0400
@@ -2473,10 +2473,6 @@
       (setq definition (indirect-function definition)))
   (and (subrp definition) (eq (cdr (subr-arity definition)) 'unevalled)))
 
-(defmacro ad-interactive-p (definition)
-  ;;"non-nil if DEFINITION can be called interactively."
-  (list 'commandp definition))
-
 (defmacro ad-subr-p (definition)
   ;;"non-nil if DEFINITION is a subr."
   (list 'subrp definition))
@@ -2590,22 +2586,13 @@
     (natnump docstring))
  docstring)))
 
-(defun ad-interactive-form (definition)
-  "Return the interactive form of DEFINITION."
-  (cond ((ad-compiled-p definition)
- (and (commandp definition)
-      (list 'interactive (aref (ad-compiled-code definition) 5))))
- ((or (ad-advice-p definition)
-     (ad-lambda-p definition))
- (commandp (ad-lambda-expression definition)))))
-
 (defun ad-body-forms (definition)
   "Return the list of body forms of DEFINITION."
   (cond ((ad-compiled-p definition)
  nil)
  ((consp definition)
  (nthcdr (+ (if (ad-docstring definition) 1 0)
-    (if (ad-interactive-form definition) 1 0))
+    (if (interactive-form definition) 1 0))
  (cdr (cdr (ad-lambda-expression definition)))))))
 
 ;; Matches the docstring of an advised definition.
@@ -3037,7 +3024,7 @@
      (ad-get-enabled-advices function 'around)
      (ad-get-enabled-advices function 'after)))
     (let ((interactive-form
-   (ad-interactive-form (ad-advice-definition advice))))
+   (interactive-form (ad-advice-definition advice))))
       (if interactive-form
   ;; We found the first one, use it:
   (ad-do-return interactive-form)))))
@@ -3051,7 +3038,7 @@
    (ad-has-redefining-advice function))
       (let* ((origdef (ad-real-orig-definition function))
      (origname (ad-get-advice-info-field function 'origname))
-     (orig-interactive-p (ad-interactive-p origdef))
+     (orig-interactive-p (commandp origdef))
      (orig-subr-p (ad-subr-p origdef))
      (orig-special-form-p (ad-special-form-p origdef))
      (orig-macro-p (ad-macro-p origdef))
@@ -3063,15 +3050,11 @@
      (interactive-form
       (cond (orig-macro-p nil)
     (advised-interactive-form)
-    ((ad-interactive-form origdef)
+    ((interactive-form origdef)
+     (interactive-form
      (if (and (symbolp function) (get function 'elp-info))
- (interactive-form (aref (get function 'elp-info) 2))
-       (ad-interactive-form origdef)))
-    ;; Otherwise we must have a subr: make it interactive if
-    ;; we have to and initialize required arguments in case
-    ;; it is called interactively:
-    (orig-interactive-p
-     (interactive-form origdef))))
+                          (aref (get function 'elp-info) 2)
+                        origdef)))))
      (orig-form
       (cond ((or orig-special-form-p orig-macro-p)
      ;; Special forms and macros will be advised into macros.
@@ -3294,8 +3277,8 @@
       t
     (ad-arglist original-definition function))
   (if (eq (ad-definition-type original-definition) 'function)
-      (equal (ad-interactive-form original-definition)
-     (ad-interactive-form cached-definition))))))
+      (equal (interactive-form original-definition)
+     (interactive-form cached-definition))))))
 
 (defun ad-get-cache-class-id (function class)
   "Return the part of FUNCTION's cache id that identifies CLASS."
@@ -3342,8 +3325,8 @@
        (ad-arglist cached-definition))
  (setq code 'interactive-form-mismatch)
  (or (null (nth 5 cache-id))
-    (equal (ad-interactive-form original-definition)
-   (ad-interactive-form cached-definition)))
+    (equal (interactive-form original-definition)
+   (interactive-form cached-definition)))
  (setq code 'verified))))
     code))
 


_______________________________________________
emacs-pretest-bug mailing list
emacs-pretest-bug@...
http://lists.gnu.org/mailman/listinfo/emacs-pretest-bug

Re: commandp

by Richard Stallman :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks for fixing it.


_______________________________________________
emacs-pretest-bug mailing list
emacs-pretest-bug@...
http://lists.gnu.org/mailman/listinfo/emacs-pretest-bug

Re: commandp

by Katsumi Yamaoka :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

>>>>> Stefan Monnier wrote:

> Actually formerly it returned either nil or non-nil, where the non-nil value
> was sometimes t and other times the interactive form.

>> Because of this, `defadvice' makes interactive Lisp functions non-
>> interactive.  See the `ad-interactive-form' function.

> Looks like a bug in advice.el.  I've just installed the patch below which
> should hopefully fix it.

Thank you for the fix.  It looks better than to make the return
value of `commandp' too implicative.


_______________________________________________
emacs-pretest-bug mailing list
emacs-pretest-bug@...
http://lists.gnu.org/mailman/listinfo/emacs-pretest-bug