diff options
| author | Jonas Bernoulli <jonas@bernoul.li> | 2025-08-01 21:34:59 +0200 |
|---|---|---|
| committer | Jonas Bernoulli <jonas@bernoul.li> | 2025-08-01 21:34:59 +0200 |
| commit | c52abfd66e863ff34fea13e93f83280e5051d843 (patch) | |
| tree | d8cf027ab954f3a8a9a696a4f22088f6e8c828c5 /lisp | |
| parent | 102317db1551709dd12a11faa8b2de0afc31309b (diff) | |
magit-completing-read: Support requiring non-empty input
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/git-commit.el | 2 | ||||
| -rw-r--r-- | lisp/magit-base.el | 7 | ||||
| -rw-r--r-- | lisp/magit-files.el | 20 | ||||
| -rw-r--r-- | lisp/magit-git.el | 31 | ||||
| -rw-r--r-- | lisp/magit-gitignore.el | 2 | ||||
| -rw-r--r-- | lisp/magit-log.el | 17 | ||||
| -rw-r--r-- | lisp/magit-merge.el | 2 | ||||
| -rw-r--r-- | lisp/magit-patch.el | 5 | ||||
| -rw-r--r-- | lisp/magit-push.el | 4 | ||||
| -rw-r--r-- | lisp/magit-repos.el | 2 | ||||
| -rw-r--r-- | lisp/magit-transient.el | 9 |
11 files changed, 50 insertions, 51 deletions
diff --git a/lisp/git-commit.el b/lisp/git-commit.el index 6c5975f..140e058 100644 --- a/lisp/git-commit.el +++ b/lisp/git-commit.el @@ -947,7 +947,7 @@ completion candidates. The input must have the form \"NAME <EMAIL>\"." (sort (delete-dups (magit-git-lines "log" "-n9999" "--format=%aN <%ae>")) #'string<) - nil nil nil 'git-commit-read-ident-history))) + nil 'any nil 'git-commit-read-ident-history))) (save-match-data (if (string-match "\\`\\([^<]+\\) *<\\([^>]+\\)>\\'" str) (list (save-match-data (string-trim (match-str 1 str))) diff --git a/lisp/magit-base.el b/lisp/magit-base.el index b49f2a7..b8d50a9 100644 --- a/lisp/magit-base.el +++ b/lisp/magit-base.el @@ -576,6 +576,10 @@ acts similarly to `completing-read', except for the following: - If REQUIRE-MATCH is nil and the user exits without a choice, then nil is returned instead of an empty string. +- If REQUIRE-MATCH is `any', then do not require a match but + do require non-empty input (or non-nil DEFAULT, since that + is substituted for empty input). + - If REQUIRE-MATCH is non-nil and the user exits without a choice, `user-error' is raised. @@ -614,7 +618,8 @@ acts similarly to `completing-read', except for the following: (reply (funcall magit-completing-read-function (magit--format-prompt prompt def) collection predicate - require-match initial-input hist def))) + (if (eq require-match 'any) nil require-match) + initial-input hist def))) (setq this-command command) ;; Note: Avoid `string=' to support `helm-comp-read-use-marked'. (if (equal reply "") diff --git a/lisp/magit-files.el b/lisp/magit-files.el index a7abb08..b1836dc 100644 --- a/lisp/magit-files.el +++ b/lisp/magit-files.el @@ -68,17 +68,15 @@ the line and column corresponding to that location." (defun magit-find-file-read-args (prompt) (let ((pseudo-revs '("{worktree}" "{index}"))) - (if-let ((rev (magit-completing-read "Find file from revision" - (append pseudo-revs - (magit-list-refnames nil t)) - nil nil nil 'magit-revision-history - (or (magit-branch-or-commit-at-point) - (magit-get-current-branch))))) - (list rev (magit-read-file-from-rev (if (member rev pseudo-revs) - "HEAD" - rev) - prompt)) - (user-error "Nothing selected")))) + (let ((rev (magit-completing-read "Find file from revision" + (append pseudo-revs + (magit-list-refnames nil t)) + nil 'any nil 'magit-revision-history + (or (magit-branch-or-commit-at-point) + (magit-get-current-branch))))) + (list rev + (magit-read-file-from-rev (if (member rev pseudo-revs) "HEAD" rev) + prompt))))) (defun magit-find-file--internal (rev file fn) (let ((buf (magit-find-file-noselect rev file)) diff --git a/lisp/magit-git.el b/lisp/magit-git.el index 22a31db..44b135b 100644 --- a/lisp/magit-git.el +++ b/lisp/magit-git.el @@ -2662,10 +2662,9 @@ and this option only controls what face is used.") (when (and commit-at-point (not branch-at-point)) (setq choices (cons commit-at-point choices))) (minibuffer-with-setup-hook #'magit--minibuf-default-add-commit - (or (magit-completing-read - prompt choices nil nil nil 'magit-revision-history - (or branch-at-point commit-at-point secondary-default current)) - (user-error "Nothing selected"))))) + (magit-completing-read + prompt choices nil 'any nil 'magit-revision-history + (or branch-at-point commit-at-point secondary-default current))))) (defun magit-read-range-or-commit (prompt &optional secondary-default) (magit-read-range @@ -2686,7 +2685,7 @@ and this option only controls what face is used.") (magit-completing-read-multiple (concat prompt ": ") (magit-list-refnames) - nil nil nil 'magit-revision-history default nil t))) + nil 'any nil 'magit-revision-history default nil t))) (defun magit-read-remote-branch (prompt &optional remote default local-branch require-match) @@ -2699,7 +2698,8 @@ and this option only controls what face is used.") (magit-list-remotes)))) (magit-list-remote-branch-names remote t) :test #'equal) - nil require-match nil 'magit-revision-history default))) + nil (or require-match 'any) + nil 'magit-revision-history default))) (if (or remote (string-match "\\`\\([^/]+\\)/\\(.+\\)" choice)) choice (user-error "`%s' doesn't have the form REMOTE/BRANCH" choice)))) @@ -2708,7 +2708,8 @@ and this option only controls what face is used.") (magit-completing-read prompt (prog2 (message "Determining available refs...") (magit-remote-list-refs remote) - (message "Determining available refs...done")))) + (message "Determining available refs...done")) + nil 'any)) (defun magit-read-local-branch (prompt &optional secondary-default) (magit-completing-read prompt (magit-list-local-branch-names) @@ -2724,10 +2725,9 @@ and this option only controls what face is used.") (when commit (push commit choices)) (minibuffer-with-setup-hook #'magit--minibuf-default-add-commit - (or (magit-completing-read prompt choices - nil nil nil 'magit-revision-history - (or (magit-local-branch-at-point) commit)) - (user-error "Nothing selected"))))) + (magit-completing-read prompt choices + nil 'any nil 'magit-revision-history + (or (magit-local-branch-at-point) commit))))) (defun magit-read-local-branch-or-ref (prompt &optional secondary-default) (magit-completing-read prompt (nconc (magit-list-local-branch-names) @@ -2762,9 +2762,8 @@ and this option only controls what face is used.") secondary-default (magit-get-previous-branch)))) (minibuffer-with-setup-hook #'magit--minibuf-default-add-commit - (or (magit-completing-read prompt (delete exclude (magit-list-refnames)) - nil nil nil 'magit-revision-history default) - (user-error "Nothing selected"))))) + (magit-completing-read prompt (delete exclude (magit-list-refnames)) + nil 'any nil 'magit-revision-history default)))) (defun magit-read-other-local-branch (prompt &optional exclude secondary-default) @@ -2827,7 +2826,7 @@ out. Only existing branches can be selected." (nconc (list "HEAD") (magit-list-refnames) (directory-files (magit-gitdir) nil "_HEAD\\'")) - nil nil nil 'magit-revision-history + nil 'any nil 'magit-revision-history (or default (magit--default-starting-point))) (user-error "Nothing selected"))) @@ -2875,7 +2874,7 @@ out. Only existing branches can be selected." (magit-completing-read prompt (nconc (magit-list-remotes) (list "https://" "git://" "git@")) - nil nil nil nil + nil 'any nil nil (or default (magit-remote-at-point) (magit-get-remote)))) diff --git a/lisp/magit-gitignore.el b/lisp/magit-gitignore.el index 4f8baf9..62b0ef5 100644 --- a/lisp/magit-gitignore.el +++ b/lisp/magit-gitignore.el @@ -138,7 +138,7 @@ Rules that are defined in that file affect all local repositories." (unless (member default choices) (setq default nil)))) (magit-completing-read "File or pattern to ignore" - choices nil nil nil nil default))) + choices nil 'any nil nil default))) ;;; Skip Worktree Commands diff --git a/lisp/magit-log.el b/lisp/magit-log.el index 66b30a3..c82cc95 100644 --- a/lisp/magit-log.el +++ b/lisp/magit-log.el @@ -651,7 +651,7 @@ commits before and half after." (split-string (magit-completing-read-multiple "Log rev,s: " (magit-list-refnames nil t) - nil nil nil 'magit-revision-history + nil 'any nil 'magit-revision-history (or (magit-branch-or-commit-at-point) (and (not use-current) (magit-get-previous-branch))) @@ -953,14 +953,13 @@ nothing else. If invoked outside any log buffer, then display the log buffer of the current repository first; creating it if necessary." (interactive - (list (or (magit-completing-read - "In log, jump to" - (magit-list-refnames nil t) - nil nil nil 'magit-revision-history - (or (and-let* ((rev (magit-commit-at-point))) - (magit-rev-fixup-target rev)) - (magit-get-current-branch))) - (user-error "Nothing selected")))) + (list (magit-completing-read + "In log, jump to" + (magit-list-refnames nil t) + nil 'any nil 'magit-revision-history + (or (and-let* ((rev (magit-commit-at-point))) + (magit-rev-fixup-target rev)) + (magit-get-current-branch))))) (with-current-buffer (cond ((derived-mode-p 'magit-log-mode) (current-buffer)) diff --git a/lisp/magit-merge.el b/lisp/magit-merge.el index 28a702c..47865af 100644 --- a/lisp/magit-merge.el +++ b/lisp/magit-merge.el @@ -241,7 +241,7 @@ then also remove the respective remote branch." "During a conflict checkout and stage side, or restore conflict." (interactive (let ((file (magit-completing-read "Checkout file" - (magit-tracked-files) nil nil nil + (magit-tracked-files) nil 'any nil 'magit-read-file-hist (magit-current-file)))) (cond ((member file (magit-unmerged-files)) diff --git a/lisp/magit-patch.el b/lisp/magit-patch.el index 8b55299..4c1b44f 100644 --- a/lisp/magit-patch.el +++ b/lisp/magit-patch.el @@ -150,9 +150,8 @@ which creates patches for all commits that are reachable from :reader #'magit-format-patch-select-base) (defun magit-format-patch-select-base (prompt initial-input history) - (or (magit-completing-read prompt (cons "auto" (magit-list-refnames)) - nil nil initial-input history "auto") - (user-error "Nothing selected"))) + (magit-completing-read prompt (cons "auto" (magit-list-refnames)) + nil 'any initial-input history "auto")) (transient-define-argument magit-format-patch:--reroll-count () :description "Reroll count" diff --git a/lisp/magit-push.el b/lisp/magit-push.el index 9fc944e..4b8f221 100644 --- a/lisp/magit-push.el +++ b/lisp/magit-push.el @@ -134,7 +134,7 @@ the upstream." :test #'equal)) (upstream (magit-completing-read (format "Set upstream of %s and push there" branch) - branches nil nil nil 'magit-revision-history + branches nil 'any nil 'magit-revision-history (or (car (member (magit-remote-branch-at-point) branches)) (car (member "origin/master" branches))))) (upstream* (or (magit-get-tracked upstream) @@ -218,7 +218,7 @@ is used." (magit-completing-read-multiple "Push refspec,s: " (cons "HEAD" (magit-list-local-branch-names)) - nil nil nil 'magit-push-refspecs-history) + nil 'any nil 'magit-push-refspecs-history) (magit-push-arguments))) (run-hooks 'magit-credential-hook) (magit-run-git-async "push" "-v" args remote refspecs)) diff --git a/lisp/magit-repos.el b/lisp/magit-repos.el index dcf6808..497df49 100644 --- a/lisp/magit-repos.el +++ b/lisp/magit-repos.el @@ -492,7 +492,7 @@ instead." (if-let ((repos (and (not read-directory-name) magit-repository-directories (magit-repos-alist)))) - (let ((reply (magit-completing-read "Git repository" repos))) + (let ((reply (magit-completing-read "Git repository" repos nil 'any))) (file-name-as-directory (or (cdr (assoc reply repos)) (if (file-directory-p reply) diff --git a/lisp/magit-transient.el b/lisp/magit-transient.el index 55dc374..ad7135b 100644 --- a/lisp/magit-transient.el +++ b/lisp/magit-transient.el @@ -118,11 +118,10 @@ nil nil initial-input history)) (defun magit-transient-read-revision (prompt initial-input history) - (or (magit-completing-read prompt (cons "HEAD" (magit-list-refnames)) - nil nil initial-input history - (or (magit-branch-or-commit-at-point) - (magit-get-current-branch))) - (user-error "Nothing selected"))) + (magit-completing-read prompt (cons "HEAD" (magit-list-refnames)) + nil 'any initial-input history + (or (magit-branch-or-commit-at-point) + (magit-get-current-branch)))) ;;;; Set |
