diff options
| author | Stefan Monnier | 2019-11-16 14:39:00 +1300 |
|---|---|---|
| committer | Phil Sainty | 2019-11-18 21:25:36 +1300 |
| commit | 6b361d95302c23dc65468ff9f5828577625e0fe2 (patch) | |
| tree | ba821a64ff096793cba5a05971bc7f374028afc8 | |
| parent | 206f36b38cfe50e92acc8d48926d1e5e2dec5939 (diff) | |
| download | emacs-6b361d95302c23dc65468ff9f5828577625e0fe2.tar.gz emacs-6b361d95302c23dc65468ff9f5828577625e0fe2.zip | |
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 <psainty@orcon.net.nz>
| -rw-r--r-- | lisp/so-long.el | 53 | ||||
| -rw-r--r-- | 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 c7931e737cc..6928c902d12 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." | |||
| 889 | (help-map (make-sparse-keymap "Help"))) | 889 | (help-map (make-sparse-keymap "Help"))) |
| 890 | ;; `so-long-revert'. | 890 | ;; `so-long-revert'. |
| 891 | (define-key-after map [so-long-revert] | 891 | (define-key-after map [so-long-revert] |
| 892 | '(menu-item "Revert to normal" so-long-menu-item-revert | 892 | '(menu-item "Revert to normal" so-long-revert |
| 893 | :enable (and so-long-revert-function | 893 | :enable (and so-long-revert-function |
| 894 | so-long--active))) | 894 | so-long--active))) |
| 895 | ;; `so-long-menu-item-replace-action' over `so-long-action-alist'. | 895 | ;; `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." | |||
| 907 | (defalias sym | 907 | (defalias sym |
| 908 | (apply-partially #'so-long-menu-item-replace-action item) | 908 | (apply-partially #'so-long-menu-item-replace-action item) |
| 909 | (documentation #'so-long-menu-item-replace-action)) | 909 | (documentation #'so-long-menu-item-replace-action)) |
| 910 | (put sym 'interactive-form '(interactive)) | 910 | (put sym 'interactive-form '(interactive "@")) |
| 911 | ;; We use "@" as commands in the mode-line menu may be | ||
| 912 | ;; triggered by mouse when some other window is selected. | ||
| 911 | sym) | 913 | sym) |
| 912 | :enable (not (and so-long--active | 914 | :enable (not (and so-long--active |
| 913 | (eq ',actionfunc so-long-function) | 915 | (eq ',actionfunc so-long-function) |
| @@ -923,38 +925,19 @@ If RESET is non-nil, remove any existing values before storing the new ones." | |||
| 923 | '(menu-item "Customize" so-long-customize)) | 925 | '(menu-item "Customize" so-long-customize)) |
| 924 | map)) | 926 | map)) |
| 925 | 927 | ||
| 926 | (defun so-long-menu-click-window () | ||
| 927 | "Return the window for a click in the So Long menu. | ||
| 928 | |||
| 929 | Commands in the mode-line menu may be triggered by mouse when some other window | ||
| 930 | is selected, so we need to make sure we are acting on the correct buffer." | ||
| 931 | ;; Refer to (info "(elisp) Click Events") regarding the form of the mouse | ||
| 932 | ;; position list for clicks in the mode line. | ||
| 933 | (or (and (mouse-event-p last-nonmenu-event) | ||
| 934 | (windowp (car (cadr last-nonmenu-event))) ; cXXXr only available | ||
| 935 | (car (cadr last-nonmenu-event))) ; since Emacs 26.1 | ||
| 936 | (selected-window))) | ||
| 937 | |||
| 938 | (defun so-long-menu-item-revert () | ||
| 939 | "Invoke `so-long-revert'." | ||
| 940 | (interactive) | ||
| 941 | (with-selected-window (so-long-menu-click-window) | ||
| 942 | (so-long-revert))) | ||
| 943 | |||
| 944 | (defun so-long-menu-item-replace-action (replacement) | 928 | (defun so-long-menu-item-replace-action (replacement) |
| 945 | "Revert the current action and invoke the specified replacement. | 929 | "Revert the current action and invoke the specified replacement. |
| 946 | 930 | ||
| 947 | REPLACEMENT is a `so-long-action-alist' item." | 931 | REPLACEMENT is a `so-long-action-alist' item." |
| 948 | (interactive) | 932 | (interactive) |
| 949 | (with-selected-window (so-long-menu-click-window) | 933 | (when so-long--active |
| 950 | (when so-long--active | 934 | (so-long-revert)) |
| 951 | (so-long-revert)) | 935 | (cl-destructuring-bind (_key _label actionfunc revertfunc) |
| 952 | (cl-destructuring-bind (_key _label actionfunc revertfunc) | 936 | replacement |
| 953 | replacement | 937 | (setq so-long-function actionfunc) |
| 954 | (setq so-long-function actionfunc) | 938 | (setq so-long-revert-function revertfunc) |
| 955 | (setq so-long-revert-function revertfunc) | 939 | (setq this-command 'so-long) |
| 956 | (setq this-command 'so-long) | 940 | (so-long))) |
| 957 | (so-long)))) | ||
| 958 | 941 | ||
| 959 | ;;;###autoload | 942 | ;;;###autoload |
| 960 | (defun so-long-commentary () | 943 | (defun so-long-commentary () |
| @@ -1644,7 +1627,9 @@ automatically by `global-so-long-mode'). | |||
| 1644 | For the default action, reverting will restore the original major mode, and | 1627 | For the default action, reverting will restore the original major mode, and |
| 1645 | restore the minor modes and settings which were overridden when `so-long' was | 1628 | restore the minor modes and settings which were overridden when `so-long' was |
| 1646 | invoked." | 1629 | invoked." |
| 1647 | (interactive) | 1630 | (interactive "@") |
| 1631 | ;; We use "@" as commands in the mode-line menu may be triggered by mouse | ||
| 1632 | ;; when some other window is selected. | ||
| 1648 | (unless so-long--calling | 1633 | (unless so-long--calling |
| 1649 | (let ((so-long--calling t)) | 1634 | (let ((so-long--calling t)) |
| 1650 | (when so-long-revert-function | 1635 | (when so-long-revert-function |
| @@ -1653,10 +1638,6 @@ invoked." | |||
| 1653 | (let ((inhibit-read-only t)) | 1638 | (let ((inhibit-read-only t)) |
| 1654 | (run-hooks 'so-long-revert-hook))))) | 1639 | (run-hooks 'so-long-revert-hook))))) |
| 1655 | 1640 | ||
| 1656 | ;; Duplicate the `so-long-revert' documentation for the menu item. | ||
| 1657 | (put 'so-long-menu-item-revert 'function-documentation | ||
| 1658 | (documentation 'so-long-revert t)) | ||
| 1659 | |||
| 1660 | ;;;###autoload | 1641 | ;;;###autoload |
| 1661 | (defun so-long-enable () | 1642 | (defun so-long-enable () |
| 1662 | "Enable the so-long library's functionality. | 1643 | "Enable the so-long library's functionality. |
| @@ -1878,10 +1859,10 @@ If it appears in `%s', you should remove it." | |||
| 1878 | ; LocalWords: customize customized customizing Customization globalized amongst | 1859 | ; LocalWords: customize customized customizing Customization globalized amongst |
| 1879 | ; LocalWords: initialized profiler boolean minified pre redisplay config keymap | 1860 | ; LocalWords: initialized profiler boolean minified pre redisplay config keymap |
| 1880 | ; LocalWords: noerror selectable mapc sgml nxml hl flydiff defs arg Phil Sainty | 1861 | ; LocalWords: noerror selectable mapc sgml nxml hl flydiff defs arg Phil Sainty |
| 1881 | ; LocalWords: defadvice nadvice whitespace ie bos eos eobp origmode un Un cXXXr | 1862 | ; LocalWords: defadvice nadvice whitespace ie bos eos eobp origmode un Un setq |
| 1882 | ; LocalWords: docstring auf wiedersehen longlines alist autoload Refactored Inc | 1863 | ; LocalWords: docstring auf wiedersehen longlines alist autoload Refactored Inc |
| 1883 | ; LocalWords: MERCHANTABILITY RET REGEXP VAR ELPA WS mitigations EmacsWiki eval | 1864 | ; LocalWords: MERCHANTABILITY RET REGEXP VAR ELPA WS mitigations EmacsWiki eval |
| 1884 | ; LocalWords: setq rx filename filenames | 1865 | ; LocalWords: rx filename filenames |
| 1885 | 1866 | ||
| 1886 | ;; So long, farewell, auf wiedersehen, goodbye | 1867 | ;; So long, farewell, auf wiedersehen, goodbye |
| 1887 | ;; You have to go, this code is minified | 1868 | ;; 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 99af5e91ba0..5c885c4fd09 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 @@ | |||
| 261 | (ert-deftest so-long-tests-so-long-menu-item-replace-action () | 261 | (ert-deftest so-long-tests-so-long-menu-item-replace-action () |
| 262 | "Test using the `so-long-menu-item-replace-action' menu item." | 262 | "Test using the `so-long-menu-item-replace-action' menu item." |
| 263 | (with-temp-buffer | 263 | (with-temp-buffer |
| 264 | ;; Due to (with-selected-window (so-long-menu-click-window) ...) | ||
| 265 | ;; (used by `so-long-menu-item-replace-action'), our temp buffer | ||
| 266 | ;; must be in the selected window. | ||
| 267 | (set-window-buffer nil (current-buffer)) | ||
| 268 | (insert "#!emacs\n") | 264 | (insert "#!emacs\n") |
| 269 | (normal-mode) | 265 | (normal-mode) |
| 270 | (so-long-tests-remember) | 266 | (so-long-tests-remember) |
| @@ -278,7 +274,7 @@ | |||
| 278 | ;; After all actions have been used, revert to normal and assert | 274 | ;; After all actions have been used, revert to normal and assert |
| 279 | ;; that the most recent action to have been applied is the one | 275 | ;; that the most recent action to have been applied is the one |
| 280 | ;; we have just reverted. | 276 | ;; we have just reverted. |
| 281 | (so-long-menu-item-revert) | 277 | (so-long-revert) |
| 282 | (so-long-tests-assert-reverted action)))) | 278 | (so-long-tests-assert-reverted action)))) |
| 283 | 279 | ||
| 284 | (ert-deftest so-long-tests-major-mode () | 280 | (ert-deftest so-long-tests-major-mode () |