diff options
| author | Ryan | 2013-09-20 15:59:42 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2013-09-20 15:59:42 -0400 |
| commit | 31dca772aded1c089b135d6335e4e444fd63078a (patch) | |
| tree | fc0b81bb9e78daae93cca7ef169d366e47afe17a | |
| parent | 1e835c22e8ec9e387b4275196103d4d6d0617899 (diff) | |
| download | emacs-31dca772aded1c089b135d6335e4e444fd63078a.tar.gz emacs-31dca772aded1c089b135d6335e4e444fd63078a.zip | |
* 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
| -rw-r--r-- | lisp/ChangeLog | 5 | ||||
| -rw-r--r-- | lisp/subr.el | 8 | ||||
| -rw-r--r-- | test/ChangeLog | 6 | ||||
| -rw-r--r-- | test/automated/advice-tests.el | 32 |
4 files changed, 48 insertions, 3 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index f32363a16a0..75aea560203 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,8 @@ | |||
| 1 | 2013-09-20 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | * subr.el (internal--call-interactively): New const. | ||
| 4 | (called-interactively-p): Use it (bug#3984). | ||
| 5 | |||
| 1 | 2013-09-20 Xue Fuqiao <xfq.free@gmail.com> | 6 | 2013-09-20 Xue Fuqiao <xfq.free@gmail.com> |
| 2 | 7 | ||
| 3 | * vc/pcvs.el (cvs-mode-ignore): | 8 | * 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 | |||
| 4246 | if those frames don't seem special and otherwise, it should return | 4246 | if those frames don't seem special and otherwise, it should return |
| 4247 | the number of frames to skip (minus 1).") | 4247 | the number of frames to skip (minus 1).") |
| 4248 | 4248 | ||
| 4249 | (defconst internal--call-interactively (symbol-function 'call-interactively)) | ||
| 4250 | |||
| 4249 | (defun called-interactively-p (&optional kind) | 4251 | (defun called-interactively-p (&optional kind) |
| 4250 | "Return t if the containing function was called by `call-interactively'. | 4252 | "Return t if the containing function was called by `call-interactively'. |
| 4251 | If KIND is `interactive', then only return t if the call was made | 4253 | If KIND is `interactive', then only return t if the call was made |
| @@ -4318,9 +4320,9 @@ command is called from a keyboard macro?" | |||
| 4318 | (pcase (cons frame nextframe) | 4320 | (pcase (cons frame nextframe) |
| 4319 | ;; No subr calls `interactive-p', so we can rule that out. | 4321 | ;; No subr calls `interactive-p', so we can rule that out. |
| 4320 | (`((,_ ,(pred (lambda (f) (subrp (indirect-function f)))) . ,_) . ,_) nil) | 4322 | (`((,_ ,(pred (lambda (f) (subrp (indirect-function f)))) . ,_) . ,_) nil) |
| 4321 | ;; Somehow, I sometimes got `command-execute' rather than | 4323 | ;; In case #<subr call-interactively> without going through the |
| 4322 | ;; `call-interactively' on my stacktrace !? | 4324 | ;; `call-interactively' symbol (bug#3984). |
| 4323 | ;;(`(,_ . (t command-execute . ,_)) t) | 4325 | (`(,_ . (t ,(pred (eq internal--call-interactively)) . ,_)) t) |
| 4324 | (`(,_ . (t call-interactively . ,_)) t))))) | 4326 | (`(,_ . (t call-interactively . ,_)) t))))) |
| 4325 | 4327 | ||
| 4326 | (defun interactive-p () | 4328 | (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 @@ | |||
| 1 | 2013-09-20 Ryan <rct@thompsonclan.org> (tiny change) | ||
| 2 | |||
| 3 | * automated/advice-tests.el (advice-test-called-interactively-p-around) | ||
| 4 | (advice-test-called-interactively-p-filter-args) | ||
| 5 | (advice-test-called-interactively-p-around): New tests. | ||
| 6 | |||
| 1 | 2013-09-16 Glenn Morris <rgm@gnu.org> | 7 | 2013-09-16 Glenn Morris <rgm@gnu.org> |
| 2 | 8 | ||
| 3 | * automated/eshell.el (eshell-match-result): | 9 | * 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 @@ | |||
| 130 | (cons (cons 2 (called-interactively-p)) (apply f args)))) | 130 | (cons (cons 2 (called-interactively-p)) (apply f args)))) |
| 131 | (should (equal (call-interactively 'sm-test7) '((2 . t) (1 . t) 11)))) | 131 | (should (equal (call-interactively 'sm-test7) '((2 . t) (1 . t) 11)))) |
| 132 | 132 | ||
| 133 | (ert-deftest advice-test-called-interactively-p-around () | ||
| 134 | "Check interaction between around advice and called-interactively-p. | ||
| 135 | |||
| 136 | This tests the currently broken case of the innermost advice to a | ||
| 137 | function being an around advice." | ||
| 138 | :expected-result :failed | ||
| 139 | (defun sm-test7.2 () (interactive) (cons 1 (called-interactively-p))) | ||
| 140 | (advice-add 'sm-test7.2 :around | ||
| 141 | (lambda (f &rest args) | ||
| 142 | (list (cons 1 (called-interactively-p)) (apply f args)))) | ||
| 143 | (should (equal (sm-test7.2) '((1 . nil) (1 . nil)))) | ||
| 144 | (should (equal (call-interactively 'sm-test7.2) '((1 . t) (1 . t))))) | ||
| 145 | |||
| 146 | (ert-deftest advice-test-called-interactively-p-filter-args () | ||
| 147 | "Check interaction between filter-args advice and called-interactively-p." | ||
| 148 | :expected-result :failed | ||
| 149 | (defun sm-test7.3 () (interactive) (cons 1 (called-interactively-p))) | ||
| 150 | (advice-add 'sm-test7.3 :filter-args #'list) | ||
| 151 | (should (equal (sm-test7.3) '(1 . nil))) | ||
| 152 | (should (equal (call-interactively 'sm-test7.3) '(1 . t)))) | ||
| 153 | |||
| 154 | (ert-deftest advice-test-call-interactively () | ||
| 155 | "Check interaction between advice on call-interactively and called-interactively-p." | ||
| 156 | (defun sm-test7.4 () (interactive) (cons 1 (called-interactively-p))) | ||
| 157 | (let ((old (symbol-function 'call-interactively))) | ||
| 158 | (unwind-protect | ||
| 159 | (progn | ||
| 160 | (advice-add 'call-interactively :before #'ignore) | ||
| 161 | (should (equal (sm-test7.4) '(1 . nil))) | ||
| 162 | (should (equal (call-interactively 'sm-test7.4) '(1 . t)))) | ||
| 163 | (fset 'call-interactively old)))) | ||
| 164 | |||
| 133 | (ert-deftest advice-test-interactive () | 165 | (ert-deftest advice-test-interactive () |
| 134 | "Check handling of interactive spec." | 166 | "Check handling of interactive spec." |
| 135 | (defun sm-test8 (a) (interactive "p") a) | 167 | (defun sm-test8 (a) (interactive "p") a) |