2019-12-23 17:20:19 -05:00
|
|
|
;;; config/default/autoload/search.el -*- lexical-binding: t; -*-
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +default/search-cwd (&optional arg)
|
|
|
|
"Conduct a text search in files under the current folder.
|
|
|
|
If prefix ARG is set, prompt for a directory to search from."
|
|
|
|
(interactive "P")
|
|
|
|
(let ((default-directory
|
|
|
|
(if arg
|
|
|
|
(read-directory-name "Search directory: ")
|
|
|
|
default-directory)))
|
|
|
|
(call-interactively
|
2021-07-09 20:16:11 +03:00
|
|
|
(cond ((featurep! :completion ivy) #'+ivy/project-search-from-cwd)
|
|
|
|
((featurep! :completion helm) #'+helm/project-search-from-cwd)
|
2021-07-09 20:28:40 +03:00
|
|
|
((featurep! :completion vertico) #'+vertico/project-search-from-cwd)
|
2019-12-23 17:20:19 -05:00
|
|
|
(#'rgrep)))))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +default/search-other-cwd ()
|
|
|
|
"Conduct a text search in another directory."
|
|
|
|
(interactive)
|
|
|
|
(+default/search-cwd 'other))
|
|
|
|
|
|
|
|
;;;###autoload
|
2020-07-31 02:41:44 -04:00
|
|
|
(defun +default/search-buffer ()
|
|
|
|
"Conduct a text search on the current buffer.
|
2021-09-15 01:20:31 +02:00
|
|
|
|
|
|
|
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."
|
2020-07-31 02:41:44 -04:00
|
|
|
(interactive)
|
2021-09-15 01:20:31 +02:00
|
|
|
(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)))))))
|
2020-07-31 12:55:29 +07:00
|
|
|
|
2020-07-31 02:41:44 -04:00
|
|
|
;;;###autoload
|
2019-12-23 17:20:19 -05:00
|
|
|
(defun +default/search-project (&optional arg)
|
|
|
|
"Conduct a text search in the current project root.
|
2020-09-19 14:38:53 -04:00
|
|
|
If prefix ARG is set, include ignored/hidden files."
|
2019-12-23 17:20:19 -05:00
|
|
|
(interactive "P")
|
2020-04-30 19:01:10 -04:00
|
|
|
(let* ((projectile-project-root nil)
|
|
|
|
(disabled-command-function nil)
|
2020-09-19 14:38:53 -04:00
|
|
|
(current-prefix-arg (unless (eq arg 'other) arg))
|
2019-12-23 17:20:19 -05:00
|
|
|
(default-directory
|
2020-09-19 14:38:53 -04:00
|
|
|
(if (eq arg 'other)
|
2019-12-23 17:20:19 -05:00
|
|
|
(if-let (projects (projectile-relevant-known-projects))
|
2020-05-26 14:02:06 -04:00
|
|
|
(completing-read "Search project: " projects nil t)
|
2019-12-23 17:20:19 -05:00
|
|
|
(user-error "There are no known projects"))
|
|
|
|
default-directory)))
|
|
|
|
(call-interactively
|
2021-07-09 20:16:11 +03:00
|
|
|
(cond ((featurep! :completion ivy) #'+ivy/project-search)
|
|
|
|
((featurep! :completion helm) #'+helm/project-search)
|
2021-07-09 20:28:40 +03:00
|
|
|
((featurep! :completion vertico) #'+vertico/project-search)
|
2019-12-23 17:20:19 -05:00
|
|
|
(#'projectile-ripgrep)))))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +default/search-other-project ()
|
|
|
|
"Conduct a text search in a known project."
|
|
|
|
(interactive)
|
|
|
|
(+default/search-project 'other))
|
|
|
|
|
|
|
|
;;;###autoload
|
2020-01-03 02:39:47 -05:00
|
|
|
(defun +default/search-project-for-symbol-at-point (&optional symbol arg)
|
2019-12-25 21:04:52 -05:00
|
|
|
"Search current project for symbol at point.
|
2019-12-23 17:20:19 -05:00
|
|
|
If prefix ARG is set, prompt for a known project to search from."
|
|
|
|
(interactive
|
2020-01-03 02:39:47 -05:00
|
|
|
(list (rxt-quote-pcre (or (doom-thing-at-point-or-region) ""))
|
|
|
|
current-prefix-arg))
|
2020-04-30 19:01:10 -04:00
|
|
|
(let* ((projectile-project-root nil)
|
|
|
|
(default-directory
|
|
|
|
(if arg
|
|
|
|
(if-let (projects (projectile-relevant-known-projects))
|
2020-05-26 14:02:06 -04:00
|
|
|
(completing-read "Search project: " projects nil t)
|
2020-04-30 19:01:10 -04:00
|
|
|
(user-error "There are no known projects"))
|
|
|
|
default-directory)))
|
2019-12-23 17:20:19 -05:00
|
|
|
(cond ((featurep! :completion ivy)
|
|
|
|
(+ivy/project-search nil symbol))
|
|
|
|
((featurep! :completion helm)
|
|
|
|
(+helm/project-search nil symbol))
|
2021-07-09 20:16:11 +03:00
|
|
|
((featurep! :completion vertico)
|
2021-07-09 20:28:40 +03:00
|
|
|
(+vertico/project-search nil symbol))
|
2019-12-23 17:20:19 -05:00
|
|
|
((rgrep (regexp-quote symbol))))))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +default/search-notes-for-symbol-at-point (&optional symbol)
|
|
|
|
"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."
|
|
|
|
(interactive
|
2020-01-03 02:39:47 -05:00
|
|
|
(list (rxt-quote-pcre (or (doom-thing-at-point-or-region) ""))))
|
2019-12-23 17:20:19 -05:00
|
|
|
(require 'org)
|
|
|
|
(let ((default-directory org-directory))
|
|
|
|
(+default/search-project-for-symbol-at-point
|
|
|
|
nil symbol)))
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +default/org-notes-search ()
|
|
|
|
"Perform a text search on `org-directory'."
|
|
|
|
(interactive)
|
|
|
|
(require 'org)
|
|
|
|
(let ((default-directory org-directory))
|
2020-01-03 02:39:47 -05:00
|
|
|
(+default/search-project-for-symbol-at-point "")))
|
2019-12-23 17:20:19 -05:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun +default/org-notes-headlines ()
|
|
|
|
"Jump to an Org headline in `org-agenda-files'."
|
|
|
|
(interactive)
|
|
|
|
(doom-completing-read-org-headings
|
|
|
|
"Jump to org headline: " org-agenda-files 3 t))
|