Skip to content

Commit

Permalink
magit-prompt-with-default: new function
Browse files Browse the repository at this point in the history
Split `magit-prompt-with-default' from `magit-builtin-completing-read'
so that it could also be used by other `completing-read' replacements
and wrappers.
  • Loading branch information
tarsius committed Feb 22, 2014
1 parent 50cb068 commit 5b64196
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions magit.el
Expand Up @@ -3749,12 +3749,9 @@ Read `completing-read' documentation for the meaning of the argument."
(defun magit-builtin-completing-read
(prompt choices &optional predicate require-match initial-input hist def)
"Magit wrapper for standard `completing-read' function."
(let ((reply (completing-read
(if (and def (> (length prompt) 2)
(string-equal ": " (substring prompt -2)))
(format "%s (default %s): " (substring prompt 0 -2) def)
prompt)
choices predicate require-match initial-input hist def)))
(let ((reply (completing-read (magit-prompt-with-default prompt def)
choices predicate require-match
initial-input hist def)))
(if (string= reply "")
(if require-match
(user-error "Nothing selected")
Expand Down Expand Up @@ -3786,6 +3783,12 @@ Read `completing-read' documentation for the meaning of the argument."
choices)))))
(iswitchb-read-buffer prompt (or initial-input def) require-match)))

(defun magit-prompt-with-default (prompt def)
(if (and def (> (length prompt) 2)
(string-equal ": " (substring prompt -2)))
(format "%s (default %s): " (substring prompt 0 -2) def)
prompt))

;;;;; Revision Completion

(defvar magit-read-rev-history nil
Expand Down

0 comments on commit 5b64196

Please sign in to comment.