aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhil Sainty2019-11-16 15:48:44 +1300
committerPhil Sainty2019-11-18 21:25:36 +1300
commit33676820bdb0fac8ebd43ab098ad13d8098f3586 (patch)
treea4e00fdc443747599ed042e863756a81f331bd64
parent83c50cc6efacf701ba64c2f4175ece7ebff9b338 (diff)
downloademacs-33676820bdb0fac8ebd43ab098ad13d8098f3586.tar.gz
emacs-33676820bdb0fac8ebd43ab098ad13d8098f3586.zip
lisp/so-long.el: Refactor menu action commands
* lisp/so-long.el (so-long-menu): Call `so-long' with an ACTION argument instead of using `so-long-menu-item-replace-action'. (so-long-menu-item-replace-action): Remove the deprecated function. * test/lisp/so-long-tests/so-long-tests.el (so-long-tests-so-long-menu-item-replace-action): Update the test.
-rw-r--r--lisp/so-long.el35
-rw-r--r--test/lisp/so-long-tests/so-long-tests.el14
2 files changed, 21 insertions, 28 deletions
diff --git a/lisp/so-long.el b/lisp/so-long.el
index e80abc76a53..33b7155d044 100644
--- a/lisp/so-long.el
+++ b/lisp/so-long.el
@@ -902,14 +902,19 @@ If RESET is non-nil, remove any existing values before storing the new ones."
902 `(menu-item 902 `(menu-item
903 ,label 903 ,label
904 ,(let ((sym (make-symbol "so-long-menu-item-replace-action"))) 904 ,(let ((sym (make-symbol "so-long-menu-item-replace-action")))
905 ;; Using a symbol here, so that `describe-key' on the menu item 905 ;; We make a symbol so that `describe-key' on the menu item
906 ;; produces the `so-long-menu-item-replace-action' documentation. 906 ;; produces something more descriptive than byte code. There is
907 (defalias sym 907 ;; no interned `so-long-menu-item-replace-action' which might
908 (apply-partially #'so-long-menu-item-replace-action item) 908 ;; make this slightly confusing -- but only in the rare situation
909 (documentation #'so-long-menu-item-replace-action)) 909 ;; when someone uses `describe-key' on one of these menu items,
910 (put sym 'interactive-form '(interactive "@")) 910 ;; and then wants to find more information. We mitigate this by
911 ;; We use "@" as commands in the mode-line menu may be 911 ;; making the following docstring very clear.
912 ;; triggered by mouse when some other window is selected. 912 (defalias sym (lambda () (interactive "@") (so-long key))
913 ;; We use "@" as commands in the mode-line menu may be
914 ;; triggered by mouse when some other window is selected.
915 "Revert the current action and invoke the chosen replacement.
916
917This commmand calls `so-long' with the selected action as an argument.")
913 sym) 918 sym)
914 :enable (not (and so-long--active 919 :enable (not (and so-long--active
915 (eq ',actionfunc so-long-function) 920 (eq ',actionfunc so-long-function)
@@ -925,20 +930,6 @@ If RESET is non-nil, remove any existing values before storing the new ones."
925 '(menu-item "Customize" so-long-customize)) 930 '(menu-item "Customize" so-long-customize))
926 map)) 931 map))
927 932
928(defun so-long-menu-item-replace-action (replacement)
929 "Revert the current action and invoke the specified replacement.
930
931REPLACEMENT is a `so-long-action-alist' item."
932 (interactive)
933 (when so-long--active
934 (so-long-revert))
935 (cl-destructuring-bind (_key _label actionfunc revertfunc)
936 replacement
937 (setq so-long-function actionfunc)
938 (setq so-long-revert-function revertfunc)
939 (setq this-command 'so-long)
940 (so-long)))
941
942;;;###autoload 933;;;###autoload
943(defun so-long-commentary () 934(defun so-long-commentary ()
944 "View the so-long documentation in `outline-mode'." 935 "View the so-long documentation in `outline-mode'."
diff --git a/test/lisp/so-long-tests/so-long-tests.el b/test/lisp/so-long-tests/so-long-tests.el
index 5c885c4fd09..ae834421667 100644
--- a/test/lisp/so-long-tests/so-long-tests.el
+++ b/test/lisp/so-long-tests/so-long-tests.el
@@ -259,22 +259,24 @@
259 (so-long-tests-assert-and-revert (or action 'so-long-mode))))) 259 (so-long-tests-assert-and-revert (or action 'so-long-mode)))))
260 260
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' action commands."
263 (with-temp-buffer 263 (with-temp-buffer
264 (insert "#!emacs\n") 264 (insert "#!emacs\n")
265 (normal-mode) 265 (normal-mode)
266 (so-long-tests-remember) 266 (so-long-tests-remember)
267 (insert (make-string (1+ so-long-threshold) ?x)) 267 (insert (make-string (1+ so-long-threshold) ?x))
268 (let (action) 268 (let ((menu (so-long-menu))
269 action
270 command)
269 (dolist (item so-long-action-alist) 271 (dolist (item so-long-action-alist)
270 ;; n.b. Any existing action is first reverted. 272 (setq action (car item)
271 (so-long-menu-item-replace-action item) 273 command (lookup-key menu (vector action)))
272 (setq action (car item)) 274 (funcall command)
273 (so-long-tests-assert-active action)) 275 (so-long-tests-assert-active action))
274 ;; After all actions have been used, revert to normal and assert 276 ;; After all actions have been used, revert to normal and assert
275 ;; that the most recent action to have been applied is the one 277 ;; that the most recent action to have been applied is the one
276 ;; we have just reverted. 278 ;; we have just reverted.
277 (so-long-revert) 279 (funcall (lookup-key menu [so-long-revert]))
278 (so-long-tests-assert-reverted action)))) 280 (so-long-tests-assert-reverted action))))
279 281
280(ert-deftest so-long-tests-major-mode () 282(ert-deftest so-long-tests-major-mode ()