From fd844ea18d4d5b33e4c872eed5897048b56b1dad Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Mon, 26 Jul 2021 22:44:51 -0400 Subject: [PATCH] fix(vertico): escape perl syntax in selection + Escape any special regexp characters in the active selection. + Change the async split character (#) to the first of %, @, !, &, or / that is absent in the active selection (falling back to % otherwise) (since consult doesn't recognize escaping for these characters). --- .../completion/vertico/autoload/vertico.el | 54 +++++++++++-------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/modules/completion/vertico/autoload/vertico.el b/modules/completion/vertico/autoload/vertico.el index f7c139356..ecaacd7cd 100644 --- a/modules/completion/vertico/autoload/vertico.el +++ b/modules/completion/vertico/autoload/vertico.el @@ -30,30 +30,40 @@ orderless." (setq deactivate-mark t) (let* ((project-root (or (doom-project-root) default-directory)) (directory (or in project-root)) - (args (split-string - (string-trim - (concat (if all-files "-uu") - (unless recursive "--maxdepth 1") - "--null --line-buffered --color=always --max-columns=500 --no-heading --line-number" - " --hidden -g !.git " - (mapconcat #'shell-quote-argument args " "))) - " ")) - (prompt (or prompt - (format "rg [%s]: " - (cond ((equal directory default-directory) - "./") - ((equal directory project-root) - (projectile-project-name)) - ((file-relative-name directory project-root)))))) + (args + (split-string + (string-trim + (concat (if all-files "-uu") + (unless recursive "--maxdepth 1") + "--null --line-buffered --color=always --max-columns=500 --no-heading --line-number" + " --hidden -g !.git " + (mapconcat #'shell-quote-argument args " "))) + " ")) + (prompt (if (stringp prompt) (string-trim prompt) "Search")) (query (or query (when (doom-region-active-p) - (replace-regexp-in-string - "[! |]" (lambda (substr) - (cond ((string= substr " ") " ") - ((string= substr "|") "\\\\\\\\|") - ((concat "\\\\" substr)))) - (rxt-quote-pcre (doom-thing-at-point-or-region)))))) - (ripgrep-command (mapconcat #'identity `("rg" ,@args "." "-e ARG OPTS" ) " "))) + (rxt-quote-pcre (doom-thing-at-point-or-region))))) + (ripgrep-command (string-join `("rg" ,@args "." "-e ARG OPTS" ) " ")) + (consult-async-split-style consult-async-split-style) + (consult-async-split-styles-alist consult-async-split-styles-alist)) + ;; Change the split style if the initial query contains the separator. + (when query + (cl-destructuring-bind (&key type separator initial) + (consult--async-split-style) + (pcase type + (`separator + (replace-regexp-in-string (regexp-quote (char-to-string separator)) + (concat "\\" separator) + query t t)) + (`perl + (when (string-match-p initial query) + (setf (alist-get 'perlalt consult-async-split-styles-alist) + `(:initial ,(or (cl-loop for char in (list "%" "@" "!" "&" "/" ";") + unless (string-match-p char query) + return char) + "%") + :type perl) + consult-async-split-style 'perlalt)))))) (consult--grep prompt ripgrep-command directory query))) ;;;###autoload