branch: externals/ivy-hydra
commit 328da1f95ce5f3386b63b28ca41a48bd88cf4144
Author: Oleh Krehel <[email protected]>
Commit: Oleh Krehel <[email protected]>
counsel.el (counsel-rg): Split command args in a more familiar way
* counsel.el (counsel--split-command-args): Update.
* ivy-test.el (counsel--split-command-args): Add test.
Before:
-g*.el -- require i
After:
require i -- -g*.el
The advantage is that we usually first input the search string and
only then the command args.
Fixes #2356
Re #1559
---
counsel.el | 18 +++++++-----------
ivy-test.el | 8 ++++++++
2 files changed, 15 insertions(+), 11 deletions(-)
diff --git a/counsel.el b/counsel.el
index 6b7c290..153a049 100644
--- a/counsel.el
+++ b/counsel.el
@@ -2834,20 +2834,16 @@ regex string."
(defvar counsel--regex-look-around nil)
-(defconst counsel--command-args-separator "-- ")
+(defconst counsel--command-args-separator " -- ")
(defun counsel--split-command-args (arguments)
"Split ARGUMENTS into its switches and search-term parts.
Return pair of corresponding strings (SWITCHES . SEARCH-TERM)."
- (let ((switches "")
- (search-term arguments))
- (when (string-prefix-p "-" arguments)
- (let ((index (string-match counsel--command-args-separator arguments)))
- (when index
- (setq search-term
- (substring arguments (+ (length
counsel--command-args-separator) index)))
- (setq switches (substring arguments 0 index)))))
- (cons switches search-term)))
+ (if (string-match counsel--command-args-separator arguments)
+ (cons
+ (substring arguments (match-end 0))
+ (substring arguments 0 (match-beginning 0)))
+ (cons "" arguments)))
(defun counsel--format-ag-command (extra-args needle)
"Construct a complete `counsel-ag-command' as a string.
@@ -3071,7 +3067,7 @@ EXTRA-RG-ARGS string, if non-nil, is appended to
`counsel-rg-base-command'.
RG-PROMPT, if non-nil, is passed as `ivy-read' prompt argument.
Example input with inclusion and exclusion file patterns:
- -g*.py -g!*test* -- ..."
+ require i -- -g*.el"
(interactive)
(let ((counsel-ag-base-command
(concat counsel-rg-base-command (counsel--rg-targets)))
diff --git a/ivy-test.el b/ivy-test.el
index 37b7ee1..1497fcd 100644
--- a/ivy-test.el
+++ b/ivy-test.el
@@ -1499,6 +1499,14 @@ a buffer visiting a file."
:dir ivy-empty))
ivy-empty)))
+(ert-deftest counsel--split-command-args ()
+ (should (equal
+ (counsel--split-command-args "require -- -g*.el")
+ '("-g*.el" . "require")))
+ (should (equal
+ (counsel--split-command-args "counsel--format")
+ '("" . "counsel--format"))))
+
(defun ivy-test-run-tests ()
(let ((test-sets
'(