From: Ryan Date: Fri, 20 Sep 2013 19:59:42 +0000 (-0400) Subject: * lisp/subr.el (internal--call-interactively): New const. X-Git-Tag: emacs-24.3.90~173^2^2~42^2~45^2~387^2~1496 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=31dca772aded1c089b135d6335e4e444fd63078a;p=emacs.git * lisp/subr.el (internal--call-interactively): New const. (called-interactively-p): Use it. * test/automated/advice-tests.el (advice-test-called-interactively-p-around) (advice-test-called-interactively-p-filter-args) (advice-test-called-interactively-p-around): New tests. Fixes: debbugs:3984 --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index f32363a16a0..75aea560203 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,8 @@ +2013-09-20 Stefan Monnier + + * subr.el (internal--call-interactively): New const. + (called-interactively-p): Use it (bug#3984). + 2013-09-20 Xue Fuqiao * vc/pcvs.el (cvs-mode-ignore): diff --git a/lisp/subr.el b/lisp/subr.el index b903ef1ea96..43be9f529be 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -4246,6 +4246,8 @@ I is the index of the frame after FRAME2. It should return nil if those frames don't seem special and otherwise, it should return the number of frames to skip (minus 1).") +(defconst internal--call-interactively (symbol-function 'call-interactively)) + (defun called-interactively-p (&optional kind) "Return t if the containing function was called by `call-interactively'. If KIND is `interactive', then only return t if the call was made @@ -4318,9 +4320,9 @@ command is called from a keyboard macro?" (pcase (cons frame nextframe) ;; No subr calls `interactive-p', so we can rule that out. (`((,_ ,(pred (lambda (f) (subrp (indirect-function f)))) . ,_) . ,_) nil) - ;; Somehow, I sometimes got `command-execute' rather than - ;; `call-interactively' on my stacktrace !? - ;;(`(,_ . (t command-execute . ,_)) t) + ;; In case # without going through the + ;; `call-interactively' symbol (bug#3984). + (`(,_ . (t ,(pred (eq internal--call-interactively)) . ,_)) t) (`(,_ . (t call-interactively . ,_)) t))))) (defun interactive-p () diff --git a/test/ChangeLog b/test/ChangeLog index 000f8e257f1..14d819c7f77 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,9 @@ +2013-09-20 Ryan (tiny change) + + * automated/advice-tests.el (advice-test-called-interactively-p-around) + (advice-test-called-interactively-p-filter-args) + (advice-test-called-interactively-p-around): New tests. + 2013-09-16 Glenn Morris * automated/eshell.el (eshell-match-result): diff --git a/test/automated/advice-tests.el b/test/automated/advice-tests.el index 424f447ae4b..bdb0eb09b40 100644 --- a/test/automated/advice-tests.el +++ b/test/automated/advice-tests.el @@ -130,6 +130,38 @@ (cons (cons 2 (called-interactively-p)) (apply f args)))) (should (equal (call-interactively 'sm-test7) '((2 . t) (1 . t) 11)))) +(ert-deftest advice-test-called-interactively-p-around () + "Check interaction between around advice and called-interactively-p. + +This tests the currently broken case of the innermost advice to a +function being an around advice." + :expected-result :failed + (defun sm-test7.2 () (interactive) (cons 1 (called-interactively-p))) + (advice-add 'sm-test7.2 :around + (lambda (f &rest args) + (list (cons 1 (called-interactively-p)) (apply f args)))) + (should (equal (sm-test7.2) '((1 . nil) (1 . nil)))) + (should (equal (call-interactively 'sm-test7.2) '((1 . t) (1 . t))))) + +(ert-deftest advice-test-called-interactively-p-filter-args () + "Check interaction between filter-args advice and called-interactively-p." + :expected-result :failed + (defun sm-test7.3 () (interactive) (cons 1 (called-interactively-p))) + (advice-add 'sm-test7.3 :filter-args #'list) + (should (equal (sm-test7.3) '(1 . nil))) + (should (equal (call-interactively 'sm-test7.3) '(1 . t)))) + +(ert-deftest advice-test-call-interactively () + "Check interaction between advice on call-interactively and called-interactively-p." + (defun sm-test7.4 () (interactive) (cons 1 (called-interactively-p))) + (let ((old (symbol-function 'call-interactively))) + (unwind-protect + (progn + (advice-add 'call-interactively :before #'ignore) + (should (equal (sm-test7.4) '(1 . nil))) + (should (equal (call-interactively 'sm-test7.4) '(1 . t)))) + (fset 'call-interactively old)))) + (ert-deftest advice-test-interactive () "Check handling of interactive spec." (defun sm-test8 (a) (interactive "p") a)