From 28c7b82eb5430af794191e37e1adba6f7728ac62 Mon Sep 17 00:00:00 2001 From: jao Date: Sun, 23 Nov 2025 16:06:44 +0000 Subject: org-notes: search for individual terms in input string --- lib/doc/jao-org-notes.el | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'lib/doc/jao-org-notes.el') diff --git a/lib/doc/jao-org-notes.el b/lib/doc/jao-org-notes.el index bd45723..af8f10a 100644 --- a/lib/doc/jao-org-notes.el +++ b/lib/doc/jao-org-notes.el @@ -45,7 +45,8 @@ (default-directory (if (file-directory-p d) (expand-file-name d) default-directory)) (ts (mapconcat #'identity (split-string str "[:,]+" t) ":|")) - (rgx (format "^#.(title: .*%s|(tags:.*(%s:)))" str ts))) + (s (mapconcat #'identity (cons str (split-string str nil t)) "|")) + (rgx (format "^#.(title: .*(%s)|(tags:.*(%s:)))" s ts))) (jao-org-notes--rg-cmd rgx "-m" "2"))) (defun jao-org-notes--clean-match (m) @@ -122,7 +123,8 @@ (defvar jao-org-notes--tag-history nil) (defun jao-org-notes--read-tags () - (let* ((tags (completing-read-multiple "Tags: " jao-org-notes--tags nil nil nil + (let* ((tags (completing-read-multiple "Tags: " + jao-org-notes--tags nil nil nil 'jao-org-notes--tag-history))) (setq jao-org-notes--tags (seq-union jao-org-notes--tags tags #'string=)) tags)) @@ -142,7 +144,8 @@ (let* ((file-name (or file-name buffer-file-name)) (bn (file-name-base file-name)) (rx (format "%s\\.org$" (regexp-quote bn))) - (pred (lambda () (string-prefix-p jao-org-notes-dir buffer-file-name)))) + (pred (lambda () + (string-prefix-p jao-org-notes-dir buffer-file-name)))) (save-some-buffers nil pred) (or (car (directory-files-recursively jao-org-notes-dir rx)) (let* ((d (completing-read "Notes subdir: " (jao-org-notes-cats) nil t)) @@ -150,9 +153,17 @@ (expand-file-name (concat d bn ".org") jao-org-notes-dir))))) (defun jao-org-notes-open () - "Search for a note file, matching tags and titles with completion." + "Search for a note file, matching tags and titles with completion. + +If the search string starts with a folder name followed by a +slash (e.g. `emacs/foo'), the search is performed only in the given +notes folder (when it exists). + +Search terms that start with a colon are interpreted as tags, and can +appear in any order in the tags list. +" (interactive) - (when-let (f (jao-org-notes--consult-rg "Search notes: ")) + (when-let (f (jao-org-notes--consult-rg "Search tags and titles: ")) (find-file f))) (defun jao-org-notes-consult-tags () @@ -214,7 +225,7 @@ ;;;###autoload (defun jao-org-notes-setup (mnemonic) - "Set up the notes system, providing a mnemonic character for its org template." + "Set up the notes system, providing a mnemonic char for its org template." (setq org-capture-templates (add-to-list 'org-capture-templates (jao-org-notes--template mnemonic)) -- cgit v1.2.3