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