emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 3367682 6/7: lisp/so-long.el: Refactor menu action commands


From: Phil
Subject: master 3367682 6/7: lisp/so-long.el: Refactor menu action commands
Date: Mon, 18 Nov 2019 03:42:02 -0500 (EST)

branch: master
commit 33676820bdb0fac8ebd43ab098ad13d8098f3586
Author: Phil Sainty <address@hidden>
Commit: Phil Sainty <address@hidden>

    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.
---
 lisp/so-long.el                          | 35 ++++++++++++--------------------
 test/lisp/so-long-tests/so-long-tests.el | 14 +++++++------
 2 files changed, 21 insertions(+), 28 deletions(-)

diff --git a/lisp/so-long.el b/lisp/so-long.el
index e80abc7..33b7155 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."
           `(menu-item
             ,label
             ,(let ((sym (make-symbol "so-long-menu-item-replace-action")))
-               ;; Using a symbol here, so that `describe-key' on the menu item
-               ;; produces the `so-long-menu-item-replace-action' 
documentation.
-               (defalias sym
-                 (apply-partially #'so-long-menu-item-replace-action item)
-                 (documentation #'so-long-menu-item-replace-action))
-               (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.
+               ;; We make a symbol so that `describe-key' on the menu item
+               ;; produces something more descriptive than byte code.  There is
+               ;; no interned `so-long-menu-item-replace-action' which might
+               ;; make this slightly confusing -- but only in the rare 
situation
+               ;; when someone uses `describe-key' on one of these menu items,
+               ;; and then wants to find more information.  We mitigate this by
+               ;; making the following docstring very clear.
+               (defalias sym (lambda () (interactive "@") (so-long key))
+                 ;; We use "@" as commands in the mode-line menu may be
+                 ;; triggered by mouse when some other window is selected.
+                 "Revert the current action and invoke the chosen replacement.
+
+This commmand calls `so-long' with the selected action as an argument.")
                sym)
             :enable (not (and so-long--active
                               (eq ',actionfunc so-long-function)
@@ -925,20 +930,6 @@ 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-item-replace-action (replacement)
-  "Revert the current action and invoke the specified replacement.
-
-REPLACEMENT is a `so-long-action-alist' item."
-  (interactive)
-  (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 ()
   "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 5c885c4..ae83442 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 @@
       (so-long-tests-assert-and-revert (or action 'so-long-mode)))))
 
 (ert-deftest so-long-tests-so-long-menu-item-replace-action ()
-  "Test using the `so-long-menu-item-replace-action' menu item."
+  "Test using the `so-long-menu' action commands."
   (with-temp-buffer
     (insert "#!emacs\n")
     (normal-mode)
     (so-long-tests-remember)
     (insert (make-string (1+ so-long-threshold) ?x))
-    (let (action)
+    (let ((menu (so-long-menu))
+          action
+          command)
       (dolist (item so-long-action-alist)
-        ;; n.b. Any existing action is first reverted.
-        (so-long-menu-item-replace-action item)
-        (setq action (car item))
+        (setq action (car item)
+              command (lookup-key menu (vector action)))
+        (funcall command)
         (so-long-tests-assert-active action))
       ;; 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-revert)
+      (funcall (lookup-key menu [so-long-revert]))
       (so-long-tests-assert-reverted action))))
 
 (ert-deftest so-long-tests-major-mode ()



reply via email to

[Prev in Thread] Current Thread [Next in Thread]