fix(default): search symbol at point from project root

...Rather than current directory.

While +default/search-project-for-symbol-at-point should operate out of
the current project's root, +default/search-notes-for-symbol-at-point
must operate out of org-directory, and no where else, even if
org-directory is not a valid project. 411ed0c8f8 was written to fix
that, but it indirectly broke
'+default/search-project-for-symbol-at-point' (causing it to always
resolve to the current directory, rather than the current project's
root).

Amend: 411ed0c8f8
Fix: #5831
This commit is contained in:
Henrik Lissner 2021-11-25 16:35:35 +01:00
parent c09777b36b
commit f0ba6c99b2

View file

@ -94,44 +94,47 @@ If prefix ARG is set, include ignored/hidden files."
(+default/search-project 'other))
;;;###autoload
(defun +default/search-project-for-symbol-at-point (&optional symbol arg)
(defun +default/search-project-for-symbol-at-point (symbol dir)
"Search current project for symbol at point.
If prefix ARG is set, prompt for a known project to search from."
(interactive
(list (rxt-quote-pcre (or (doom-thing-at-point-or-region) ""))
current-prefix-arg))
(let* ((projectile-project-root nil)
(dir (if arg
(let ((projectile-project-root nil))
(if current-prefix-arg
(if-let (projects (projectile-relevant-known-projects))
(completing-read "Search project: " projects nil t)
(user-error "There are no known projects"))
default-directory)))
(doom-project-root default-directory)))))
(cond ((featurep! :completion ivy)
(+ivy/project-search nil symbol dir))
((featurep! :completion helm)
(+helm/project-search nil symbol dir))
((featurep! :completion vertico)
(+vertico/project-search nil symbol dir))
((rgrep (regexp-quote symbol))))))
((rgrep (regexp-quote symbol)))))
;;;###autoload
(defun +default/search-notes-for-symbol-at-point (&optional symbol)
(defun +default/search-notes-for-symbol-at-point (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
(list (rxt-quote-pcre (or (doom-thing-at-point-or-region) ""))))
(require 'org)
(let ((default-directory org-directory))
(+default/search-project-for-symbol-at-point
nil symbol)))
symbol org-directory))
;;;###autoload
(defun +default/org-notes-search ()
(defun +default/org-notes-search (query)
"Perform a text search on `org-directory'."
(interactive)
(interactive
(list (if (doom-region-active-p)
(buffer-substring-no-properties
(doom-region-beginning)
(doom-region-end))
"")))
(require 'org)
(let ((default-directory org-directory))
(+default/search-project-for-symbol-at-point "")))
(+default/search-project-for-symbol-at-point
query org-directory))
;;;###autoload
(defun +default/org-notes-headlines ()