[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/ivy-hydra 05d892d 282/395: counsel-grep/ag/rg/pt: use s
From: |
Basil L. Contovounesios |
Subject: |
[elpa] externals/ivy-hydra 05d892d 282/395: counsel-grep/ag/rg/pt: use subprocess instead of shell command |
Date: |
Thu, 25 Feb 2021 08:32:20 -0500 (EST) |
branch: externals/ivy-hydra
commit 05d892df0ea68a6e94d57bb783ce648192829a95
Author: Kien Nguyen <kien.n.quang@gmail.com>
Commit: Oleh Krehel <ohwoeowho@gmail.com>
counsel-grep/ag/rg/pt: use subprocess instead of shell command
Fixes #2552
---
counsel.el | 145 +++++++++++++++++++++++++++++++++++++++----------------------
1 file changed, 93 insertions(+), 52 deletions(-)
diff --git a/counsel.el b/counsel.el
index 2ad5fbf..87ca199 100644
--- a/counsel.el
+++ b/counsel.el
@@ -139,6 +139,34 @@ To skip the `executable-find' check, start the string with
a space."
(replace-regexp-in-string ; Insert dir before any trailing colon.
"\\(?:: ?\\)?\\'" dir (ivy-state-prompt ivy-last) t t))))
+(defalias 'counsel--flatten
+ ;; Added in Emacs 27.1
+ (if (fboundp 'flatten-tree)
+ #'flatten-tree
+ (lambda (tree)
+ (let (elems)
+ (while (consp tree)
+ (let ((elem (pop tree)))
+ (while (consp elem)
+ (push (cdr elem) tree)
+ (setq elem (car elem)))
+ (if elem (push elem elems))))
+ (if tree (push tree elems))
+ (nreverse elems))))
+ "Compatibility shim for `flatten-tree'.")
+
+(defun counsel--format (formatter &rest args)
+ "Like `format' but FORMATTER can be a list.
+When FORMATTER is a list, only `%s' is replaced with ARGS.
+
+Return a list or string depending on input."
+ (cond
+ ((listp formatter)
+ (counsel--flatten (mapcar
+ (lambda (it) (if (equal it "%s") (pop args) it))
+ formatter)))
+ (t (apply #'format formatter args))))
+
;;* Async Utility
(defvar counsel--async-time nil
"Store the time when a new process was started.
@@ -2967,10 +2995,16 @@ Return pair of corresponding strings (SWITCHES .
SEARCH-TERM)."
"Construct a complete `counsel-ag-command' as a string.
EXTRA-ARGS is a string of the additional arguments.
NEEDLE is the search string."
- (format counsel-ag-command
- (if (string-match " \\(--\\) " extra-args)
- (replace-match needle t t extra-args 1)
- (concat extra-args " " needle))))
+ (counsel--format counsel-ag-command
+ (if (listp counsel-ag-command)
+ (if (string-match " \\(--\\) " extra-args)
+ (counsel--format
+ (split-string (replace-match "%s" t t extra-args
1))
+ needle)
+ (nconc (split-string extra-args) needle))
+ (if (string-match " \\(--\\) " extra-args)
+ (replace-match needle t t extra-args 1)
+ (concat extra-args " " needle)))))
(defun counsel--grep-regex (str)
(counsel--elisp-to-pcre
@@ -3001,7 +3035,9 @@ NEEDLE is the search string."
" -s "))))
(counsel--async-command (counsel--format-ag-command
switches
- (shell-quote-argument regex)))
+ (funcall (if (listp counsel-ag-command)
#'identity
+ #'shell-quote-argument)
+ regex)))
nil))))
;;;###autoload
@@ -3017,31 +3053,31 @@ CALLER is passed to `ivy-read'."
(setq counsel-ag-command counsel-ag-base-command)
(setq counsel--regex-look-around counsel--grep-tool-look-around)
(counsel-require-program counsel-ag-command)
- (when current-prefix-arg
- (setq initial-directory
- (or initial-directory
- (counsel-read-directory-name (concat
- (car (split-string
counsel-ag-command))
- " in directory: "))))
- (setq extra-ag-args
- (or extra-ag-args
- (read-from-minibuffer (format
- "%s args: "
- (car (split-string
counsel-ag-command)))))))
- (setq counsel-ag-command (counsel--format-ag-command (or extra-ag-args "")
"%s"))
- (let ((default-directory (or initial-directory
- (counsel--git-root)
- default-directory)))
- (ivy-read (or ag-prompt
- (concat (car (split-string counsel-ag-command)) ": "))
- #'counsel-ag-function
- :initial-input initial-input
- :dynamic-collection t
- :keymap counsel-ag-map
- :history 'counsel-git-grep-history
- :action #'counsel-git-grep-action
- :require-match t
- :caller (or caller 'counsel-ag))))
+ (let ((prog-name (car (if (listp counsel-ag-command) counsel-ag-command
+ (split-string counsel-ag-command)))))
+ (when current-prefix-arg
+ (setq initial-directory
+ (or initial-directory
+ (counsel-read-directory-name (concat
+ prog-name
+ " in directory: "))))
+ (setq extra-ag-args
+ (or extra-ag-args
+ (read-from-minibuffer (format "%s args: " prog-name)))))
+ (setq counsel-ag-command (counsel--format-ag-command (or extra-ag-args "")
"%s"))
+ (let ((default-directory (or initial-directory
+ (counsel--git-root)
+ default-directory)))
+ (ivy-read (or ag-prompt
+ (concat prog-name ": "))
+ #'counsel-ag-function
+ :initial-input initial-input
+ :dynamic-collection t
+ :keymap counsel-ag-map
+ :history 'counsel-git-grep-history
+ :action #'counsel-git-grep-action
+ :require-match t
+ :caller (or caller 'counsel-ag)))))
(ivy-configure 'counsel-ag
:occur #'counsel-ag-occur
@@ -3167,20 +3203,16 @@ Note: don't use single quotes for the regex."
(defun counsel--rg-targets ()
"Return a list of files to operate on, based on `dired-mode' marks."
- (if (eq major-mode 'dired-mode)
- (let ((files
- (dired-get-marked-files 'no-dir nil nil t)))
- (if (and (null (cdr files))
- (not (when (string-match-p "\\*ivy-occur" (buffer-name))
- (dired-toggle-marks)
- (setq files (dired-get-marked-files 'no-dir))
- (dired-toggle-marks)
- t)))
- ""
- (concat
- " "
- (mapconcat #'shell-quote-argument (delq t files) " "))))
- ""))
+ (when (eq major-mode 'dired-mode)
+ (let ((files
+ (dired-get-marked-files 'no-dir nil nil t)))
+ (when (or (cdr files)
+ (when (string-match-p "\\*ivy-occur" (buffer-name))
+ (dired-toggle-marks)
+ (setq files (dired-get-marked-files 'no-dir))
+ (dired-toggle-marks)
+ t)))
+ (delq t files))))
;;;###autoload
(defun counsel-rg (&optional initial-input initial-directory extra-rg-args
rg-prompt)
@@ -3194,9 +3226,13 @@ Example input with inclusion and exclusion file patterns:
require i -- -g*.el"
(interactive)
(let ((counsel-ag-base-command
- (concat counsel-rg-base-command (counsel--rg-targets)))
+ (if (listp counsel-rg-base-command)
+ (append counsel-rg-base-command (counsel--rg-targets))
+ (concat counsel-rg-base-command " "
+ (mapconcat #'shell-quote-argument (counsel--rg-targets) "
"))))
(counsel--grep-tool-look-around
- (let ((rg (car (split-string counsel-rg-base-command)))
+ (let ((rg (car (if (listp counsel-rg-base-command)
counsel-rg-base-command
+ (split-string counsel-rg-base-command))))
(switch "--pcre2"))
(and (eq 0 (call-process rg nil nil nil switch "--pcre2-version"))
switch))))
@@ -3232,10 +3268,14 @@ substituted by the search regexp and file,
respectively. Neither
(or
(ivy-more-chars)
(let* ((regex (counsel--grep-regex string))
- (cmd (format counsel-grep-command (shell-quote-argument regex))))
+ (cmd (counsel--format
+ counsel-grep-command
+ (funcall (if (listp counsel-grep-command) #'identity
+ #'shell-quote-argument)
+ regex))))
(counsel--async-command
(if (ivy--case-fold-p regex)
- (progn
+ (if (listp cmd) (nconc (list (car cmd) "-i") (cdr cmd))
(string-match " " cmd)
(replace-match " -i " nil nil cmd))
cmd))
@@ -3304,10 +3344,11 @@ When non-nil, INITIAL-INPUT is the initial search
pattern."
(user-error "Current buffer is not visiting a file"))
(counsel-require-program counsel-grep-base-command)
(setq counsel-grep-command
- (format counsel-grep-base-command
- "%s" (shell-quote-argument
- (file-name-nondirectory
- buffer-file-name))))
+ (counsel--format counsel-grep-base-command "%s"
+ (funcall (if (listp counsel-grep-base-command)
#'identity
+ #'shell-quote-argument)
+ (file-name-nondirectory
+ buffer-file-name))))
(let ((default-directory (file-name-directory buffer-file-name))
(init-point (point))
res)
- [elpa] externals/ivy-hydra 1deef76 394/395: Bump version to point release 0.13.2, (continued)
- [elpa] externals/ivy-hydra 1deef76 394/395: Bump version to point release 0.13.2, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 4235010 387/395: Re-revert last change to ivy-update-candidates, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra d8ed11e 388/395: Make ivy-switch-buffer-kill respect current predicate, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra c1a61dc 084/395: ivy-test.el (ivy-empty-directory-open): Test opening empty directory, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 316d4dd 232/395: counsel-kmacro: Create actions for cycling the ring and setting a saved counter value., Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 38c90e8 196/395: ivy.el (ivy-switch-buffer-transformer): Move ivy-remote logic here, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra fff899a 237/395: counsel.el (counsel--sync-sentinel-on-exit): Try not to reset index to 0, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra a2c86c0 273/395: ivy.el (ivy-completion-in-region): Fixup, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra da0b272 281/395: ivy.el (ivy--call-marked): Handle alists, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra a37ec22 279/395: Revert "ivy.el (ivy--update-minibuffer): don't filter while there's input", Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 05d892d 282/395: counsel-grep/ag/rg/pt: use subprocess instead of shell command,
Basil L. Contovounesios <=
- [elpa] externals/ivy-hydra b173441 326/395: Fix for ivy-immediate-done with counsel-M-x, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra d539306 307/395: Revert "ivy.el (ivy-display-style): Remove", Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 1095e42 298/395: ivy.el (ivy-alt-done-functions-alist): Add, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 7774867 335/395: Guard against null Org heading, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 7b9391f 320/395: ivy-avy.el: Fix typo, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 6bfada5 359/395: ivy.el: Use ivy--completing-fname-p more, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 7e4c567 350/395: Makefile: Make plain.el load counsel instead of here, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 5db2513 341/395: Recognize remote executables in Emacs >= 27.1., Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra 92c91ca 342/395: counsel.el (counsel-org-capture): Display descriptions from prefix keys, Basil L. Contovounesios, 2021/02/25
- [elpa] externals/ivy-hydra accc0fe 339/395: counsel.el (counsel-compile--probe-make-targets): fail more gracefully, Basil L. Contovounesios, 2021/02/25