diff --git a/modules/config/default/autoload/search.el b/modules/config/default/autoload/search.el index 66ecb9758..20faf7cd3 100644 --- a/modules/config/default/autoload/search.el +++ b/modules/config/default/autoload/search.el @@ -24,25 +24,37 @@ If prefix ARG is set, prompt for a directory to search from." ;;;###autoload (defun +default/search-buffer () "Conduct a text search on the current buffer. -If a selection is active, pre-fill the prompt with it." + +If a selection is active and multi-line, perform a search restricted to that +region. + +If a selection is active and not multi-line, use the selection as the initial +input and search the whole buffer for it." (interactive) - (cond ((or (featurep! :completion helm) - (featurep! :completion ivy)) - (call-interactively - (if (region-active-p) - #'swiper-isearch-thing-at-point - #'swiper-isearch))) - ((featurep! :completion vertico) - (if (region-active-p) - (let ((start (region-beginning)) - (end (region-end))) - (deactivate-mark) - (consult-line - (replace-regexp-in-string - " " "\\\\ " - (rxt-quote-pcre - (buffer-substring-no-properties start end))))) - (call-interactively #'consult-line))))) + (let (start end multiline-p) + (save-restriction + (when (region-active-p) + (setq start (region-beginning) + end (region-end) + multiline-p (/= (line-number-at-pos start) + (line-number-at-pos end))) + (deactivate-mark) + (when multiline-p + (narrow-to-region start end))) + (cond ((or (featurep! :completion helm) + (featurep! :completion ivy)) + (call-interactively + (if (and start end (not multiline-p)) + #'swiper-isearch-thing-at-point + #'swiper-isearch))) + ((featurep! :completion vertico) + (if (and start end (not multiline-p)) + (consult-line + (replace-regexp-in-string + " " "\\\\ " + (rxt-quote-pcre + (buffer-substring-no-properties start end)))) + (call-interactively #'consult-line))))))) ;;;###autoload (defun +default/search-project (&optional arg)