[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 6b361d9 4/7: lisp/so-long.el: Use (interactive "@") for menu comm
From: |
Phil |
Subject: |
master 6b361d9 4/7: lisp/so-long.el: Use (interactive "@") for menu commands |
Date: |
Mon, 18 Nov 2019 03:42:02 -0500 (EST) |
branch: master
commit 6b361d95302c23dc65468ff9f5828577625e0fe2
Author: Stefan Monnier <address@hidden>
Commit: Phil Sainty <address@hidden>
lisp/so-long.el: Use (interactive "@") for menu commands
* lisp/so-long.el (so-long-menu, so-long-menu-item-replace-action)
(so-long-revert): Use interactive code "@", replacing all uses of
`so-long-menu-click-window'. This approach leaves the window selected
afterwards, whereas the old code did not; but that is not a problem.
(so-long-menu-click-window, so-long-menu-item-revert): Remove the
deprecated functions.
* test/lisp/so-long-tests/so-long-tests.el
(so-long-tests-so-long-menu-item-replace-action): Update the test.
Co-authored-by: Phil Sainty <address@hidden>
---
lisp/so-long.el | 53 ++++++++++----------------------
test/lisp/so-long-tests/so-long-tests.el | 6 +---
2 files changed, 18 insertions(+), 41 deletions(-)
diff --git a/lisp/so-long.el b/lisp/so-long.el
index c7931e7..6928c90 100644
--- a/lisp/so-long.el
+++ b/lisp/so-long.el
@@ -889,7 +889,7 @@ If RESET is non-nil, remove any existing values before
storing the new ones."
(help-map (make-sparse-keymap "Help")))
;; `so-long-revert'.
(define-key-after map [so-long-revert]
- '(menu-item "Revert to normal" so-long-menu-item-revert
+ '(menu-item "Revert to normal" so-long-revert
:enable (and so-long-revert-function
so-long--active)))
;; `so-long-menu-item-replace-action' over `so-long-action-alist'.
@@ -907,7 +907,9 @@ If RESET is non-nil, remove any existing values before
storing the new ones."
(defalias sym
(apply-partially #'so-long-menu-item-replace-action item)
(documentation #'so-long-menu-item-replace-action))
- (put sym 'interactive-form '(interactive))
+ (put sym 'interactive-form '(interactive "@"))
+ ;; We use "@" as commands in the mode-line menu may be
+ ;; triggered by mouse when some other window is selected.
sym)
:enable (not (and so-long--active
(eq ',actionfunc so-long-function)
@@ -923,38 +925,19 @@ If RESET is non-nil, remove any existing values before
storing the new ones."
'(menu-item "Customize" so-long-customize))
map))
-(defun so-long-menu-click-window ()
- "Return the window for a click in the So Long menu.
-
-Commands in the mode-line menu may be triggered by mouse when some other window
-is selected, so we need to make sure we are acting on the correct buffer."
- ;; Refer to (info "(elisp) Click Events") regarding the form of the mouse
- ;; position list for clicks in the mode line.
- (or (and (mouse-event-p last-nonmenu-event)
- (windowp (car (cadr last-nonmenu-event))) ; cXXXr only available
- (car (cadr last-nonmenu-event))) ; since Emacs 26.1
- (selected-window)))
-
-(defun so-long-menu-item-revert ()
- "Invoke `so-long-revert'."
- (interactive)
- (with-selected-window (so-long-menu-click-window)
- (so-long-revert)))
-
(defun so-long-menu-item-replace-action (replacement)
"Revert the current action and invoke the specified replacement.
REPLACEMENT is a `so-long-action-alist' item."
(interactive)
- (with-selected-window (so-long-menu-click-window)
- (when so-long--active
- (so-long-revert))
- (cl-destructuring-bind (_key _label actionfunc revertfunc)
- replacement
- (setq so-long-function actionfunc)
- (setq so-long-revert-function revertfunc)
- (setq this-command 'so-long)
- (so-long))))
+ (when so-long--active
+ (so-long-revert))
+ (cl-destructuring-bind (_key _label actionfunc revertfunc)
+ replacement
+ (setq so-long-function actionfunc)
+ (setq so-long-revert-function revertfunc)
+ (setq this-command 'so-long)
+ (so-long)))
;;;###autoload
(defun so-long-commentary ()
@@ -1644,7 +1627,9 @@ automatically by `global-so-long-mode').
For the default action, reverting will restore the original major mode, and
restore the minor modes and settings which were overridden when `so-long' was
invoked."
- (interactive)
+ (interactive "@")
+ ;; We use "@" as commands in the mode-line menu may be triggered by mouse
+ ;; when some other window is selected.
(unless so-long--calling
(let ((so-long--calling t))
(when so-long-revert-function
@@ -1653,10 +1638,6 @@ invoked."
(let ((inhibit-read-only t))
(run-hooks 'so-long-revert-hook)))))
-;; Duplicate the `so-long-revert' documentation for the menu item.
-(put 'so-long-menu-item-revert 'function-documentation
- (documentation 'so-long-revert t))
-
;;;###autoload
(defun so-long-enable ()
"Enable the so-long library's functionality.
@@ -1878,10 +1859,10 @@ If it appears in `%s', you should remove it."
; LocalWords: customize customized customizing Customization globalized
amongst
; LocalWords: initialized profiler boolean minified pre redisplay config
keymap
; LocalWords: noerror selectable mapc sgml nxml hl flydiff defs arg Phil
Sainty
-; LocalWords: defadvice nadvice whitespace ie bos eos eobp origmode un Un
cXXXr
+; LocalWords: defadvice nadvice whitespace ie bos eos eobp origmode un Un setq
; LocalWords: docstring auf wiedersehen longlines alist autoload Refactored
Inc
; LocalWords: MERCHANTABILITY RET REGEXP VAR ELPA WS mitigations EmacsWiki
eval
-; LocalWords: setq rx filename filenames
+; LocalWords: rx filename filenames
;; So long, farewell, auf wiedersehen, goodbye
;; You have to go, this code is minified
diff --git a/test/lisp/so-long-tests/so-long-tests.el
b/test/lisp/so-long-tests/so-long-tests.el
index 99af5e9..5c885c4 100644
--- a/test/lisp/so-long-tests/so-long-tests.el
+++ b/test/lisp/so-long-tests/so-long-tests.el
@@ -261,10 +261,6 @@
(ert-deftest so-long-tests-so-long-menu-item-replace-action ()
"Test using the `so-long-menu-item-replace-action' menu item."
(with-temp-buffer
- ;; Due to (with-selected-window (so-long-menu-click-window) ...)
- ;; (used by `so-long-menu-item-replace-action'), our temp buffer
- ;; must be in the selected window.
- (set-window-buffer nil (current-buffer))
(insert "#!emacs\n")
(normal-mode)
(so-long-tests-remember)
@@ -278,7 +274,7 @@
;; After all actions have been used, revert to normal and assert
;; that the most recent action to have been applied is the one
;; we have just reverted.
- (so-long-menu-item-revert)
+ (so-long-revert)
(so-long-tests-assert-reverted action))))
(ert-deftest so-long-tests-major-mode ()
- master updated (952bd20 -> ccb8bbd), Phil, 2019/11/18
- master bf7934a 2/7: ; * lisp/so-long.el: Use function quoting in example configuration, Phil, 2019/11/18
- master 6b361d9 4/7: lisp/so-long.el: Use (interactive "@") for menu commands,
Phil <=
- master 83c50cc 5/7: * lisp/so-long.el (so-long): Firstly revert the existing action, if any, Phil, 2019/11/18
- master 6218714 1/7: ; * lisp/so-long.el: Delete redundant :group declarations, Phil, 2019/11/18
- master 206f36b 3/7: ; * lisp/so-long.el: Use declare-function nearer the code that needs it, Phil, 2019/11/18
- master 3367682 6/7: lisp/so-long.el: Refactor menu action commands, Phil, 2019/11/18
- master ccb8bbd 7/7: Merge branch 'scratch/so-long-updates', Phil, 2019/11/18