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).
This commit is contained in:
parent
ffcfb6d8b3
commit
fd844ea18d
1 changed files with 32 additions and 22 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue