[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/transient 626d105: transient--read-number-N: Return emp
From: |
Jonas Bernoulli |
Subject: |
[elpa] externals/transient 626d105: transient--read-number-N: Return empty string instead of nil |
Date: |
Sat, 14 Aug 2021 03:26:01 -0400 (EDT) |
branch: externals/transient
commit 626d105ecfb44ab9e1a4bf1fccb9340d6488b631
Author: Jonas Bernoulli <jonas@bernoul.li>
Commit: Jonas Bernoulli <jonas@bernoul.li>
transient--read-number-N: Return empty string instead of nil
This affects `transient-read-number-N+' and `transient-read-number-N',
which are only intended for use as `:reader' of infix commands and are
called by `transient-infix-read' which understand how to treat nil and
the empty string depending on the values of other slots.
For empty input return the empty string instead of nil, informing
`transient-infix-read' that what is being returned is the empty value
of the argument and not the instruction to altogether turn off the
argument. This makes it trivial to support options that can be off,
on, or have a numeric value:
(transient-define-argument magit-diff:-C ()
:description "Detect copies"
:class 'transient-option
:argument "-C"
+ :allow-empty t
:reader 'transient-read-number-N+)
---
lisp/transient.el | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/lisp/transient.el b/lisp/transient.el
index 4984977..a9e026e 100644
--- a/lisp/transient.el
+++ b/lisp/transient.el
@@ -2606,13 +2606,12 @@ stand-alone command."
(cl-block nil
(while t
(let ((str (read-from-minibuffer prompt initial-input nil nil
history)))
- (cond ((string-equal str "")
- (cl-return nil))
- ((string-match-p (if include-zero
- "\\`\\(0\\|[1-9][0-9]*\\)\\'"
- "\\`[1-9][0-9]*\\'")
- str)
- (cl-return str))))
+ (when (or (string-equal str "")
+ (string-match-p (if include-zero
+ "\\`\\(0\\|[1-9][0-9]*\\)\\'"
+ "\\`[1-9][0-9]*\\'")
+ str))
+ (cl-return str)))
(message "Please enter a natural number (%s zero)."
(if include-zero "including" "excluding"))
(sit-for 1)))))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [elpa] externals/transient 626d105: transient--read-number-N: Return empty string instead of nil,
Jonas Bernoulli <=