completion/ivy: use region is active & fix regex quoting

Fixes #1930
This commit is contained in:
Henrik Lissner 2019-10-22 11:27:07 -04:00
parent 6e6672b135
commit f79d191701
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 12 additions and 6 deletions

View file

@ -366,14 +366,14 @@ order.
(let ((query (buffer-substring-no-properties beg end))) (let ((query (buffer-substring-no-properties beg end)))
;; Escape characters that are special to ivy searches ;; Escape characters that are special to ivy searches
(replace-regexp-in-string "[! |]" (lambda (substr) (replace-regexp-in-string "[! |]" (lambda (substr)
(cond ((and (featurep! +fuzzy) (cond ((and (string= substr " ")
(string= substr " ")) (not (featurep! +fuzzy)))
" ") " ")
((and (string= substr "|") ((and (string= substr "|")
(eq engine 'rg)) (eq engine 'rg))
"\\\\\\\\|") "\\\\\\\\|")
((concat "\\\\" substr)))) ((concat "\\\\" substr))))
(regexp-quote query)))))))) (rxt-quote-pcre query))))))))
(prompt (prompt
(format "%s%%s %s" (format "%s%%s %s"
(symbol-name engine) (symbol-name engine)

View file

@ -270,7 +270,13 @@ If prefix ARG is set, prompt for a known project to search from."
"Conduct a text search in the current project for symbol at point. "Conduct a text search in the current project for symbol at point.
If prefix ARG is set, prompt for a known project to search from." If prefix ARG is set, prompt for a known project to search from."
(interactive (interactive
(list current-prefix-arg (or (thing-at-point 'symbol t) ""))) (list current-prefix-arg
(or (and (use-region-p)
(rxt-quote-pcre
(buffer-substring-no-properties (region-beginning)
(region-end))))
(rxt-quote-pcre (thing-at-point 'symbol t))
"")))
(let ((default-directory (let ((default-directory
(if arg (if arg
(if-let* ((projects (projectile-relevant-known-projects))) (if-let* ((projects (projectile-relevant-known-projects)))
@ -279,9 +285,9 @@ If prefix ARG is set, prompt for a known project to search from."
(user-error "There are no known projects")) (user-error "There are no known projects"))
default-directory))) default-directory)))
(cond ((featurep! :completion ivy) (cond ((featurep! :completion ivy)
(+ivy/project-search nil (rxt-quote-pcre symbol))) (+ivy/project-search nil symbol))
((featurep! :completion helm) ((featurep! :completion helm)
(+helm/project-search nil (rxt-quote-pcre symbol))) (+helm/project-search nil symbol))
((rgrep (regexp-quote symbol)))))) ((rgrep (regexp-quote symbol))))))
;;;###autoload ;;;###autoload