Skip to content

Commit

Permalink
magit-slow-confirm: new option
Browse files Browse the repository at this point in the history
Re #2752.
  • Loading branch information
tarsius committed Oct 9, 2016
1 parent 52d812b commit fe56d4e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lisp/git-rebase.el
Expand Up @@ -419,7 +419,7 @@ running 'man git-rebase' at the command line) for details."
(setq save-place nil)))

(defun git-rebase-cancel-confirm (force)
(or (not (buffer-modified-p)) force (y-or-n-p "Abort this rebase? ")))
(or (not (buffer-modified-p)) force (magit-y-or-n-p "Abort this rebase? ")))

(defun git-rebase-autostash-save ()
(--when-let (magit-file-line (magit-git-dir "rebase-merge/autostash"))
Expand Down
22 changes: 19 additions & 3 deletions lisp/magit-utils.el
Expand Up @@ -192,6 +192,15 @@ Global settings:
(const stage-all-changes) (const unstage-all-changes)
(const safe-with-wip))))

(defcustom magit-slow-confirm nil
"Whether to ask user \"y or n\" or \"yes or no\" questions.
When this is nil (the default), then `y-or-n-p' is used when the
user has to confirm a potentially destructive action. When this
is non-nil, then `yes-or-no-p' is used instead."
:package-version '(magit . "2.9.0")
:group 'magit-commands
:type 'boolean)

(defcustom magit-no-message nil
"A list of messages Magit should not display.
Expand Down Expand Up @@ -367,6 +376,13 @@ This is similar to `read-string', but
',(mapcar 'car clauses))
,@(--map `(,(car it) ,@(cddr it)) clauses)))

(defun magit-y-or-n-p (prompt)
"Ask user a \"y or n\" or a \"yes or no\" question.
Also see option `magit-slow-confirm'."
(if magit-slow-confirm
(yes-or-no-p prompt)
(y-or-n-p prompt)))

(cl-defun magit-confirm (action &optional prompt prompt-n (items nil sitems))
(declare (indent defun))
(setq prompt-n (format (concat (or prompt-n prompt) "? ") (length items))
Expand All @@ -384,9 +400,9 @@ This is similar to `read-string', but
unstage-all-changes))))))
(or (not sitems) items))
((not sitems)
(y-or-n-p prompt))
(magit-y-or-n-p prompt))
((= (length items) 1)
(and (y-or-n-p prompt) items))
(and (magit-y-or-n-p prompt) items))
((> (length items) 1)
(let ((buffer (get-buffer-create " *Magit Confirm*")))
(with-current-buffer buffer
Expand All @@ -395,7 +411,7 @@ This is similar to `read-string', but
'((window-height . fit-window-to-buffer)))
(lambda (window _value)
(with-selected-window window
(unwind-protect (and (y-or-n-p prompt-n) items)
(unwind-protect (and (magit-y-or-n-p prompt-n) items)
(when (window-live-p window)
(quit-restore-window window 'kill)))))
(dolist (item items)
Expand Down

0 comments on commit fe56d4e

Please sign in to comment.