From: Phil Sainty <psainty@orcon.net.nz>
Date: Sat, 16 Nov 2019 13:11:20 +0000 (+1300)
Subject: * lisp/so-long.el (so-long): Firstly revert the existing action, if any
X-Git-Tag: emacs-27.0.90~579^2~1
X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=83c50cc6efacf701ba64c2f4175ece7ebff9b338;p=emacs.git

* lisp/so-long.el (so-long): Firstly revert the existing action, if any

This makes `so-long' consistent with the action commands in the menu.

If multiple actions were to be layered on top of one another, we would
lose the ability to revert to the normal state.  Custom actions
combining multiple other actions can be defined if necessary.
---

diff --git a/lisp/so-long.el b/lisp/so-long.el
index 6928c902d12..e80abc76a53 100644
--- a/lisp/so-long.el
+++ b/lisp/so-long.el
@@ -1576,8 +1576,12 @@ This command is called automatically when long lines are detected, when
 
 The effects of the action can be undone by calling `so-long-revert'.
 
-If ACTION is provided, it is used instead of `so-long-action'.  With a prefix
-argument, select the action to use interactively."
+If ACTION is provided, it is used instead of `so-long-action'.
+
+With a prefix argument, select the action to use interactively.
+
+If an action was already active in the buffer, it will be reverted before
+invoking the new action."
   (interactive
    (list (and current-prefix-arg
               (intern
@@ -1587,6 +1591,10 @@ argument, select the action to use interactively."
   ;; Ensure that `so-long-deferred' only triggers `so-long' once (at most).
   (remove-hook 'window-configuration-change-hook #'so-long :local)
   (unless so-long--calling
+    ;; Revert the existing action, if any.
+    (when so-long--active
+      (so-long-revert))
+    ;; Invoke the new action.
     (let ((so-long--calling t))
       (so-long--ensure-enabled)
       ;; ACTION takes precedence if supplied.