branch: elpa/magit
commit a673ca3b4b63595c3e0f5293d943f995f2f8cb5b
Author: Jonas Bernoulli <[email protected]>
Commit: Jonas Bernoulli <[email protected]>

    magit-wip-mode: Remove all the sub-modes
---
 docs/magit.org     |  72 ---------------------------------
 docs/magit.texi    |  73 ---------------------------------
 lisp/magit-base.el |  12 +++---
 lisp/magit-log.el  |   3 +-
 lisp/magit-mode.el |   4 +-
 lisp/magit-wip.el  | 116 +++++++----------------------------------------------
 6 files changed, 24 insertions(+), 256 deletions(-)

diff --git a/docs/magit.org b/docs/magit.org
index ee360e66457..23584e0b002 100644
--- a/docs/magit.org
+++ b/docs/magit.org
@@ -7672,11 +7672,6 @@ different wip refs for subsequent changes.
   Setting this variable directly does not take effect; either use the
   Custom interface to do so or call the respective mode function.
 
-  For historic reasons this mode is implemented on top of four other
-  ~magit-wip-*~ modes, which can also be used individually, if you want
-  finer control over when the wip refs are updated; but that is
-  discouraged.  See [[*Legacy Wip Modes]].
-
 To view the log for a branch and its wip refs use the commands
 ~magit-wip-log~ and ~magit-wip-log-current~.  You should use ~--graph~ when
 using these commands.
@@ -7802,73 +7797,6 @@ commit does not change the fork-point of the working 
tree wip ref.  The
 fork-points are not adjusted until there actually is a change that
 should be committed to the respective wip ref.
 
-*** Legacy Wip Modes
-
-It is recommended that you use the mode ~magit-wip-mode~ (which see) and
-ignore the existence of the following modes, which are preserved for
-historic reasons.
-
-Setting the following variables directly does not take effect; either
-use the Custom interface to do so or call the respective mode
-functions.
-
-- User Option: magit-wip-after-save-mode ::
-
-  When this mode is enabled, then saving a buffer that visits a file
-  tracked in a Git repository causes its current state to be committed
-  to the working tree wip ref for the current branch.
-
-- User Option: magit-wip-after-apply-mode ::
-
-  When this mode is enabled, then applying (i.e., staging, unstaging,
-  discarding, reversing, and regularly applying) a change to a file
-  tracked in a Git repository causes its current state to be committed
-  to the index and/or working tree wip refs for the current branch.
-
-If you only ever edit files using Emacs and only ever interact with
-Git using Magit, then the above two modes should be enough to protect
-each and every change from accidental loss.  In practice nobody does
-that.  Two additional modes exists that do commit to the wip refs
-before making changes that could cause the loss of earlier changes.
-
-- User Option: magit-wip-before-change-mode ::
-
-  When this mode is enabled, then certain commands commit the existing
-  changes to the files they are about to make changes to.
-
-- User Option: magit-wip-initial-backup-mode ::
-
-  When this mode is enabled, then the current version of a file is
-  committed to the worktree wip ref before the buffer visiting that
-  file is saved for the first time since the buffer was created.
-
-  This backs up the same version of the file that ~backup-buffer~ would
-  save.  While ~backup-buffer~ uses a backup file, this mode uses the
-  same worktree wip ref as used by the other Magit Wip modes.  Like
-  ~backup-buffer~, it only does this once; unless you kill the buffer
-  and visit the file again only one backup will be created per Emacs
-  session.
-
-  This mode ignores the variables that affect ~backup-buffer~ and can be
-  used along-side that function, which is recommended because it only
-  backs up files that are tracked in a Git repository.
-
-- User Option: magit-wip-after-save-local-mode-lighter ::
-
-  Mode-line lighter for ~magit-wip-after-save-local-mode~.
-
-- User Option: magit-wip-after-apply-mode-lighter ::
-
-  Mode-line lighter for ~magit-wip-after-apply-mode~.
-
-- User Option: magit-wip-before-change-mode-lighter ::
-
-  Mode-line lighter for ~magit-wip-before-change-mode~.
-
-- User Option: magit-wip-initial-backup-mode-lighter ::
-
-  Mode-line lighter for ~magit-wip-initial-backup-mode~.
-
 ** Commands for Buffers Visiting Files
 
 By default Magit defines a few global key bindings.  These bindings
diff --git a/docs/magit.texi b/docs/magit.texi
index 9ac1a390bd9..425cce15902 100644
--- a/docs/magit.texi
+++ b/docs/magit.texi
@@ -9244,11 +9244,6 @@ dataloss would be a possibility otherwise).
 
 Setting this variable directly does not take effect; either use the
 Custom interface to do so or call the respective mode function.
-
-For historic reasons this mode is implemented on top of four other
-@code{magit-wip-*} modes, which can also be used individually, if you want
-finer control over when the wip refs are updated; but that is
-discouraged.  See @ref{Legacy Wip Modes}.
 @end defopt
 
 To view the log for a branch and its wip refs use the commands
@@ -9382,74 +9377,6 @@ commit does not change the fork-point of the working 
tree wip ref.  The
 fork-points are not adjusted until there actually is a change that
 should be committed to the respective wip ref.
 
-@anchor{Legacy Wip Modes}
-@subsection Legacy Wip Modes
-
-It is recommended that you use the mode @code{magit-wip-mode} (which see) and
-ignore the existence of the following modes, which are preserved for
-historic reasons.
-
-Setting the following variables directly does not take effect; either
-use the Custom interface to do so or call the respective mode
-functions.
-
-@defopt magit-wip-after-save-mode
-When this mode is enabled, then saving a buffer that visits a file
-tracked in a Git repository causes its current state to be committed
-to the working tree wip ref for the current branch.
-@end defopt
-
-@defopt magit-wip-after-apply-mode
-When this mode is enabled, then applying (i.e., staging, unstaging,
-discarding, reversing, and regularly applying) a change to a file
-tracked in a Git repository causes its current state to be committed
-to the index and/or working tree wip refs for the current branch.
-@end defopt
-
-If you only ever edit files using Emacs and only ever interact with
-Git using Magit, then the above two modes should be enough to protect
-each and every change from accidental loss.  In practice nobody does
-that.  Two additional modes exists that do commit to the wip refs
-before making changes that could cause the loss of earlier changes.
-
-@defopt magit-wip-before-change-mode
-When this mode is enabled, then certain commands commit the existing
-changes to the files they are about to make changes to.
-@end defopt
-
-@defopt magit-wip-initial-backup-mode
-When this mode is enabled, then the current version of a file is
-committed to the worktree wip ref before the buffer visiting that
-file is saved for the first time since the buffer was created.
-
-This backs up the same version of the file that @code{backup-buffer} would
-save.  While @code{backup-buffer} uses a backup file, this mode uses the
-same worktree wip ref as used by the other Magit Wip modes.  Like
-@code{backup-buffer}, it only does this once; unless you kill the buffer
-and visit the file again only one backup will be created per Emacs
-session.
-
-This mode ignores the variables that affect @code{backup-buffer} and can be
-used along-side that function, which is recommended because it only
-backs up files that are tracked in a Git repository.
-@end defopt
-
-@defopt magit-wip-after-save-local-mode-lighter
-Mode-line lighter for @code{magit-wip-after-save-local-mode}.
-@end defopt
-
-@defopt magit-wip-after-apply-mode-lighter
-Mode-line lighter for @code{magit-wip-after-apply-mode}.
-@end defopt
-
-@defopt magit-wip-before-change-mode-lighter
-Mode-line lighter for @code{magit-wip-before-change-mode}.
-@end defopt
-
-@defopt magit-wip-initial-backup-mode-lighter
-Mode-line lighter for @code{magit-wip-initial-backup-mode}.
-@end defopt
-
 @node Commands for Buffers Visiting Files
 @section Commands for Buffers Visiting Files
 
diff --git a/lisp/magit-base.el b/lisp/magit-base.el
index 99566a83044..37b0759d985 100644
--- a/lisp/magit-base.el
+++ b/lisp/magit-base.el
@@ -333,11 +333,11 @@ Global settings:
   for confirmation for any of these actions, you are still better
   of adding all of the respective symbols individually.
 
-  When `magit-wip-before-change-mode' is enabled then these actions
-  can fairly easily be undone: `discard', `reverse',
-  `stage-all-changes', and `unstage-all-changes'.  If and only if
-  this mode is enabled, then `safe-with-wip' has the same effect
-  as adding all of these symbols individually."
+  When `magit-wip-mode' is enabled then these actions can fairly
+  easily be undone: `discard', `reverse', `stage-all-changes', and
+  `unstage-all-changes'.  If and only if this mode is enabled, then
+  `safe-with-wip' has the same effect as adding all of these symbols
+  individually."
   :package-version '(magit . "2.1.0")
   :group 'magit-essentials
   :group 'magit-commands
@@ -799,7 +799,7 @@ ACTION is a member of option `magit-slow-confirm'."
     (y-or-n-p prompt)))
 
 (defvar magit--no-confirm-alist
-  '((safe-with-wip magit-wip-before-change-mode
+  '((safe-with-wip magit-wip-mode
                    discard reverse stage-all-changes unstage-all-changes)))
 
 (cl-defun magit-confirm ( action &optional prompt prompt-n noabort
diff --git a/lisp/magit-log.el b/lisp/magit-log.el
index 286b02c948b..c6bcdd9390c 100644
--- a/lisp/magit-log.el
+++ b/lisp/magit-log.el
@@ -31,7 +31,6 @@
 (require 'magit-core)
 (require 'magit-diff)
 
-(declare-function magit--any-wip-mode-enabled-p "magit-wip" ())
 (declare-function magit-blob-visit "magit-files" (rev file))
 (declare-function magit-cherry-apply "magit-sequence" (commit &optional args))
 (declare-function magit-insert-head-branch-header "magit-status"
@@ -536,7 +535,7 @@ commits before and half after."
     ("r" "current"           magit-reflog-current)
     ("O" "other"             magit-reflog-other)
     ("H" "HEAD"              magit-reflog-head)]
-   [:if magit--any-wip-mode-enabled-p
+   [:if-mode magit-wip-mode
     :description "Wiplog"
     ("i" "index"             magit-wip-log-index)
     ("w" "worktree"          magit-wip-log-worktree)]
diff --git a/lisp/magit-mode.el b/lisp/magit-mode.el
index 1d0634687b9..3cb0d4b15f7 100644
--- a/lisp/magit-mode.el
+++ b/lisp/magit-mode.el
@@ -47,7 +47,7 @@
 (declare-function elp-restore-all "elp" ())
 
 (defvar magit--wip-inhibit-autosave)
-(defvar magit-wip-after-save-mode)
+(defvar magit-wip-mode)
 (declare-function magit-wip-get-ref "magit-wip" ())
 (declare-function magit-wip-commit-worktree "magit-wip" (ref files msg))
 
@@ -1331,7 +1331,7 @@ argument (the prefix) non-nil means save all with no 
questions."
            (lambda ()
              (and (funcall magit-save-repository-buffers-predicate topdir)
                   (prog1 t
-                    (when magit-wip-after-save-mode
+                    (when magit-wip-mode
                       (push (expand-file-name buffer-file-name) saved))))))
         (when saved
           (let ((default-directory topdir))
diff --git a/lisp/magit-wip.el b/lisp/magit-wip.el
index 446318a9c83..eed16d5f512 100644
--- a/lisp/magit-wip.el
+++ b/lisp/magit-wip.el
@@ -72,46 +72,30 @@ is used as `branch-ref'."
   :group 'magit-wip
   :type 'string)
 
-;;; Modes
+;;; Mode
 
 (defvar magit--wip-inhibit-autosave nil)
 
 ;;;###autoload
 (define-minor-mode magit-wip-mode
-  "Save uncommitted changes to work-in-progress refs.
-
-Whenever appropriate (i.e., when dataloss would be a possibility
-otherwise) this mode causes uncommitted changes to be committed
-to dedicated work-in-progress refs.
-
-For historic reasons this mode is implemented on top of four
-other `magit-wip-*' modes, which can also be used individually,
-if you want finer control over when the wip refs are updated;
-but that is discouraged."
+  "Automatically save uncommitted changes to work-in-progress refs."
   :package-version '(magit . "2.90.0")
   :lighter magit-wip-mode-lighter
   :global t
-  (let ((arg (if magit-wip-mode 1 -1)))
-    (magit-wip-after-save-mode arg)
-    (magit-wip-after-apply-mode arg)
-    (magit-wip-before-change-mode arg)
-    (magit-wip-initial-backup-mode arg)))
-
-;;;###autoload
-(define-minor-mode magit-wip-after-save-mode
-  "Commit to work-in-progress refs when saving file-visiting buffers."
-  :package-version '(magit . "2.1.0")
-  :group 'magit-wip
-  :global t
-  (if magit-wip-after-save-mode
-      (add-hook  'after-save-hook #'magit-wip-commit-buffer-file 90)
-    (remove-hook 'after-save-hook #'magit-wip-commit-buffer-file)))
+  (cond
+   (magit-wip-mode
+    (add-hook 'after-save-hook #'magit-wip-commit-buffer-file)
+    (add-hook 'magit-after-apply-functions #'magit-wip-commit)
+    (add-hook 'magit-before-change-functions #'magit-wip-commit)
+    (add-hook 'before-save-hook #'magit-wip-commit-initial-backup))
+   (t
+    (remove-hook 'after-save-hook #'magit-wip-commit-buffer-file)
+    (remove-hook 'magit-after-apply-functions #'magit-wip-commit)
+    (remove-hook 'magit-before-change-functions #'magit-wip-commit)
+    (remove-hook 'before-save-hook #'magit-wip-commit-initial-backup))))
 
 (defun magit-wip-commit-buffer-file (&optional msg)
-  "Commit visited file to a worktree work-in-progress ref.
-
-Also see `magit-wip-after-save-mode' which calls this function
-automatically whenever a buffer visiting a tracked file is saved."
+  "Commit visited file to a worktree work-in-progress ref."
   (interactive (list "save %s snapshot"))
   (when (and (not magit--wip-inhibit-autosave)
              buffer-file-name
@@ -123,89 +107,20 @@ automatically whenever a buffer visiting a tracked file 
is saved."
      (format (or msg "autosave %s after save")
              (magit-file-relative-name buffer-file-name)))))
 
-;;;###autoload
-(define-minor-mode magit-wip-after-apply-mode
-  "Commit to work-in-progress refs.
-
-After applying a change using any \"apply variant\"
-command (apply, stage, unstage, discard, and reverse) commit the
-affected files to the current wip refs.  For each branch there
-may be two wip refs; one contains snapshots of the files as found
-in the worktree and the other contains snapshots of the entries
-in the index."
-  :package-version '(magit . "2.1.0")
-  :group 'magit-wip
-  :global t
-  (if magit-wip-after-apply-mode
-      (add-hook  'magit-after-apply-functions #'magit-wip-commit)
-    (remove-hook 'magit-after-apply-functions #'magit-wip-commit)))
-
 (defun magit-run-after-apply-functions (files task)
   (run-hook-with-args 'magit-after-apply-functions
                       (ensure-list files)
                       (format " after %s" task)))
 
-;;;###autoload
-(define-minor-mode magit-wip-before-change-mode
-  "Commit to work-in-progress refs before certain destructive changes.
-
-Before invoking a revert command or an \"apply variant\"
-command (apply, stage, unstage, discard, and reverse) commit the
-affected tracked files to the current wip refs.  For each branch
-there may be two wip refs; one contains snapshots of the files
-as found in the worktree and the other contains snapshots of the
-entries in the index.
-
-Only changes to files which could potentially be affected by the
-command which is about to be called are committed."
-  :package-version '(magit . "2.1.0")
-  :group 'magit-wip
-  :global t
-  (if magit-wip-before-change-mode
-      (add-hook  'magit-before-change-functions #'magit-wip-commit)
-    (remove-hook 'magit-before-change-functions #'magit-wip-commit)))
-
 (defun magit-run-before-change-functions (files task)
   (run-hook-with-args 'magit-before-change-functions
                       (ensure-list files)
                       (format " before %s" task)))
 
-(define-minor-mode magit-wip-initial-backup-mode
-  "Before saving a buffer for the first time, commit to a wip ref."
-  :package-version '(magit . "2.90.0")
-  :group 'magit-wip
-  :global t
-  (if magit-wip-initial-backup-mode
-      (add-hook  'before-save-hook #'magit-wip-commit-initial-backup)
-    (remove-hook 'before-save-hook #'magit-wip-commit-initial-backup)))
-
-(defun magit--any-wip-mode-enabled-p ()
-  "Return non-nil if any global wip mode is enabled."
-  (or magit-wip-mode
-      magit-wip-after-save-mode
-      magit-wip-after-apply-mode
-      magit-wip-before-change-mode
-      magit-wip-initial-backup-mode))
-
 (defvar-local magit-wip-buffer-backed-up nil)
 (put 'magit-wip-buffer-backed-up 'permanent-local t)
 
-;;;###autoload
 (defun magit-wip-commit-initial-backup ()
-  "Before saving, commit current file to a worktree wip ref.
-
-The user has to add this function to `before-save-hook'.
-
-Commit the current state of the visited file before saving the
-current buffer to that file.  This backs up the same version of
-the file as `backup-buffer' would, but stores the backup in the
-worktree wip ref, which is also used by the various Magit Wip
-modes, instead of in a backup file as `backup-buffer' would.
-
-This function ignores the variables that affect `backup-buffer'
-and can be used along-side that function, which is recommended
-because this function only backs up files that are tracked in
-a Git repository."
   (when (and (not magit-wip-buffer-backed-up)
              buffer-file-name
              (magit-inside-worktree-p t)
@@ -325,8 +240,7 @@ commit message."
               "HEAD")))
 
 (defun magit-wip-maybe-add-commit-hook ()
-  (when (and magit-wip-merge-branch
-             (magit--any-wip-mode-enabled-p))
+  (when (and magit-wip-mode magit-wip-merge-branch)
     (add-hook 'git-commit-post-finish-hook #'magit-wip-commit nil t)))
 
 ;;; Log

Reply via email to