[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 05a4e59 147/399: Do not use invalid :preselect as a regexp
From: |
Oleh Krehel |
Subject: |
[elpa] master 05a4e59 147/399: Do not use invalid :preselect as a regexp |
Date: |
Sat, 20 Jul 2019 14:57:12 -0400 (EDT) |
branch: master
commit 05a4e59bf418f9a421b9446b143a7ad071eda6eb
Author: Basil L. Contovounesios <address@hidden>
Commit: Basil L. Contovounesios <address@hidden>
Do not use invalid :preselect as a regexp
* doc/ivy.org (Optional arguments for ivy-read):
* ivy.el (ivy-read): Extend :preselect documentation.
(ivy--preselect-index, ivy--recompute-index): Do not use preselect
as a regexp if invalid.
(ivy--legal-regex-p): Rename to...
(ivy--regex-p): ...this. Return nil regardless of the type of
error.
(ivy--regex-or-literal): Use it.
Fixes #2002
---
doc/ivy.org | 10 +++++++---
ivy.el | 33 +++++++++++++++------------------
2 files changed, 22 insertions(+), 21 deletions(-)
diff --git a/doc/ivy.org b/doc/ivy.org
index f3b5a3b..6ea4bf4 100644
--- a/doc/ivy.org
+++ b/doc/ivy.org
@@ -1118,13 +1118,17 @@ features such as multi-actions, non-exiting actions,
=ivy-occur= and
- =history= ::
Name of the symbol to store history. See =completing-read=.
- =preselect= ::
- When set to a string value, select the first candidate matching
- this value.
+ Determines which one of the candidates to initially select.
When set to an integer value, select the candidate with that
index value.
- Every time the input becomes empty, the item corresponding to to
+ When set to any other non-nil value, select the first candidate
+ matching this value. Comparison is first done with =equal=.
+ If this fails, and when applicable, match =preselect= as a
+ regular expression.
+
+ Every time the input becomes empty, the item corresponding to
=preselect= is selected.
- =keymap= ::
A keymap to be composed with =ivy-minibuffer-map=. This keymap
diff --git a/ivy.el b/ivy.el
index fb67ebd..c15e7fa 100644
--- a/ivy.el
+++ b/ivy.el
@@ -1808,8 +1808,13 @@ history.
KEYMAP is composed with `ivy-minibuffer-map'.
-If PRESELECT is not nil, then select the corresponding candidate
-out of the ones that match the INITIAL-INPUT.
+PRESELECT, when non-nil, determines which one of the candidates
+matching INITIAL-INPUT to select initially. An integer stands
+for the position of the desired candidate in the collection,
+counting from zero. Otherwise, use the first occurrence of
+PRESELECT in the collection. Comparison is first done with
+`equal'. If that fails, and when applicable, match PRESELECT as
+a regular expression.
DEF is for compatibility with `completing-read'.
@@ -2378,12 +2383,8 @@ Minibuffer bindings:
(cond ((integerp preselect)
preselect)
((cl-position preselect candidates :test #'equal))
- ((stringp preselect)
- (let ((re preselect))
- (cl-position-if
- (lambda (x)
- (string-match-p re x))
- candidates)))))
+ ((ivy--regex-p preselect)
+ (cl-position preselect candidates :test #'string-match-p))))
;;* Implementation
;;** Regex
@@ -2484,17 +2485,13 @@ When GREEDY is non-nil, join words in a greedy way."
(if greedy ".*" ".*?")))))
ivy--regex-hash)))))
-(defun ivy--legal-regex-p (str)
- "Return t if STR is valid regular expression."
- (condition-case nil
- (progn
- (string-match-p str "")
- t)
- (invalid-regexp nil)))
+(defun ivy--regex-p (object)
+ "Return OBJECT if it is a valid regular expression, else nil."
+ (ignore-errors (string-match-p object "") object))
(defun ivy--regex-or-literal (str)
- "If STR isn't a legal regex, escape it."
- (if (ivy--legal-regex-p str) str (regexp-quote str)))
+ "If STR isn't a legal regexp, escape it."
+ (or (ivy--regex-p str) (regexp-quote str)))
(defun ivy--split-negation (str)
"Split STR into text before and after ! delimiter.
@@ -3264,7 +3261,7 @@ RE-STR is the regexp, CANDS are the current candidates."
(and (integerp preselect)
(= ivy--index preselect))
(equal current preselect)
- (and (stringp preselect)
+ (and (ivy--regex-p preselect)
(stringp current)
(string-match-p preselect current))))
ivy--old-cands
- [elpa] master fa2e02d 137/399: ivy-overlay.el (ivy-cursor): Customize for dark background, (continued)
- [elpa] master fa2e02d 137/399: ivy-overlay.el (ivy-cursor): Customize for dark background, Oleh Krehel, 2019/07/20
- [elpa] master 8edde1c 135/399: swiper.el (swiper-isearch): Change prompt, Oleh Krehel, 2019/07/20
- [elpa] master 66961f8 138/399: swiper.el (swiper-isearch-action): Add a cursor overlay, Oleh Krehel, 2019/07/20
- [elpa] master ce31009 144/399: swiper.el (swiper-isearch-function): Use text with faces, Oleh Krehel, 2019/07/20
- [elpa] master 8229304 141/399: ivy.el: Add display transformer for counsel-dired, Oleh Krehel, 2019/07/20
- [elpa] master fef96f4 139/399: counsel.el (counsel--find-file-1): Extract, Oleh Krehel, 2019/07/20
- [elpa] master 3b40e99 142/399: swiper.el (swiper-isearch-action): Fix fake cursor at eol, Oleh Krehel, 2019/07/20
- [elpa] master eaba38a 145/399: counsel.el (counsel-dired-jump-args): Fix for OSX, Oleh Krehel, 2019/07/20
- [elpa] master 7c9d960 143/399: swiper.el (swiper--add-cursor-overlay): Extract, Oleh Krehel, 2019/07/20
- [elpa] master 9988904 150/399: counsel.el (counsel--switch-buffer-update-fn): Fix for when find-file fails, Oleh Krehel, 2019/07/20
- [elpa] master 05a4e59 147/399: Do not use invalid :preselect as a regexp,
Oleh Krehel <=
- [elpa] master 3ab3d5f 152/399: swiper.el (swiper-isearch): Check executing-kbd-macro, Oleh Krehel, 2019/07/20
- [elpa] master 302d23f 149/399: counsel.el: Fix org-version testing, Oleh Krehel, 2019/07/20
- [elpa] master cd41f70 153/399: ivy-test.el: Add inhibit-message, Oleh Krehel, 2019/07/20
- [elpa] master 1df4ccf 154/399: ivy.el (ivy-occur-revert-buffer): Add swiper-isearch, Oleh Krehel, 2019/07/20
- [elpa] master 4f1bbc1 151/399: swiper.el (swiper-isearch-function): Full point history for DEL, Oleh Krehel, 2019/07/20
- [elpa] master 0bf94f8 156/399: ivy.el (ivy--occur-press-update-window): Add swiper-isearch, Oleh Krehel, 2019/07/20
- [elpa] master 0d2ab52 157/399: swiper.el (swiper--isearch-occur-cands): Faster version, Oleh Krehel, 2019/07/20
- [elpa] master 1bf56c3 165/399: swiper.el (swiper--query-replace-setup): Fix for ivy--regex-ignore-order, Oleh Krehel, 2019/07/20
- [elpa] master 4492054 167/399: ivy.el (ivy--recompute-index): Speed up, Oleh Krehel, 2019/07/20
- [elpa] master 11b0007 158/399: swiper.el (swiper--action): Simplify, Oleh Krehel, 2019/07/20