From 466cac11553f585b78690f39ff72fe7127fec7a1 Mon Sep 17 00:00:00 2001 From: jao Date: Thu, 27 Nov 2025 11:59:55 +0000 Subject: jao-org-notes: better ripgrep --- custom/jao-custom-org.el | 20 ++++++++++---------- init.el | 3 ++- lib/doc/jao-org-notes.el | 33 +++++++++++++++++++++------------ 3 files changed, 33 insertions(+), 23 deletions(-) diff --git a/custom/jao-custom-org.el b/custom/jao-custom-org.el index 37045c5..cbab422 100644 --- a/custom/jao-custom-org.el +++ b/custom/jao-custom-org.el @@ -102,16 +102,16 @@ (setq-local cursor-in-non-selected-windows nil line-spacing 0.2)))) -(add-to-list 'display-buffer-alist - '((major-mode . org-agenda-mode) - (display-buffer-reuse-window) - (window-parameters (mode-line-format . none)) - (body-function . jao-org-agenda-hook))) - -(add-to-list 'display-buffer-alist - '("inbox\\.org" - (display-buffer-reuse-window) - (window-parameters (mode-line-format . none)))) +;; (add-to-list 'display-buffer-alist +;; '((major-mode . org-agenda-mode) +;; (display-buffer-reuse-window) +;; (window-parameters (mode-line-format . none)) +;; (body-function . jao-org-agenda-hook))) + +;; (add-to-list 'display-buffer-alist +;; '("inbox\\.org" +;; (display-buffer-reuse-window) +;; (window-parameters (mode-line-format . none)))) ;;; Capture templates (setq org-capture-templates diff --git a/init.el b/init.el index eb880c8..041bb34 100644 --- a/init.el +++ b/init.el @@ -1944,7 +1944,8 @@ ("n" "create new note" jao-org-notes-create) ("/" "open note" jao-org-notes-open) ("\\" "open note by tags" jao-org-notes-consult-tags) - ("N" "ripgrep notes" jao-org-notes-consult-ripgrep)] + ("N" "ripgrep all notes" jao-org-notes-consult-ripgrep) + ("C" "ripgrep category" jao-org-notes-consult-ripgrep-category)] ["Documents" ("d" "go to doc" jao-select-pdf) ("o" "open doc" jao-open-doc) diff --git a/lib/doc/jao-org-notes.el b/lib/doc/jao-org-notes.el index dde2b8c..4b45eab 100644 --- a/lib/doc/jao-org-notes.el +++ b/lib/doc/jao-org-notes.el @@ -35,7 +35,7 @@ (defun jao-org-notes--rg-cmd (rgx &rest args) `("rg" "--null" "--line-buffered" "--color=never" "--max-columns=250" - "--type=org" "--line-number" "--no-heading" "--smart-case" + "--type=org" "--line-number" "--no-heading" "--smart-case" "--follow" ,@args ,default-directory "-e" ,rgx)) (defun jao-org-notes--rg-title-or-tags (str) @@ -93,7 +93,7 @@ :history '(:input jao-org-notes--grep-history)))) (defun jao-org-notes-cats () - (seq-difference (directory-files jao-org-notes-dir) '("." ".." "attic"))) + (directory-files jao-org-notes-dir nil "^[^.]")) (defun jao-org-notes--cat () (let* ((cat (completing-read "Top level category: " (jao-org-notes-cats)))) @@ -166,16 +166,27 @@ appear in any order in the tags list. (when-let (f (jao-org-notes--consult-rg "Search tags and titles: ")) (find-file f))) +(defvar jao-org-notes-consult-ripgrep-args + (format "%s -L" consult-ripgrep-args)) + +(defun jao-org-notes-consult-ripgrep (&optional ask initial) + "Search over notes in given notes categories (or all of them), using rg." + (interactive "P") + (let ((cat (when ask (completing-read "Category: " (jao-org-notes-cats)))) + (consult-ripgrep-args jao-org-notes-consult-ripgrep-args)) + (consult-ripgrep (expand-file-name (or cat "") jao-org-notes-dir) initial))) + +(defun jao-org-notes-consult-ripgrep-category (&optional initial) + "Search over notes in a given notes category." + (interactive "P") + (jao-org-notes-consult-ripgrep t initial)) + (defun jao-org-notes-consult-tags () "Search for a note file, matching all tags with completion." (interactive) (let* ((tags (jao-org-notes--read-tags)) (init (concat "^..tags: " (mapconcat #'identity tags " ")))) - (consult-ripgrep jao-org-notes-dir init))) - -(defun jao-org-notes-consult-ripgrep (&optional initial cat) - (interactive) - (consult-ripgrep (expand-file-name (or cat "") jao-org-notes-dir) initial)) + (jao-org-notes-consult-ripgrep init))) (defun jao-org-notes-create (&optional title) "Create a new note file, matching tags and titles with completion." @@ -220,16 +231,14 @@ appear in any order in the tags list. (interactive) (message "%d notes, %d tags in %s" (length (jao-org-notes-list)) - (length jao-org--notes-tags) + (length jao-org-notes--tags) jao-org-notes-dir)) ;;;###autoload (defun jao-org-notes-setup (mnemonic) "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)) - jao-org-notes--tags (jao-org-notes-all-tags)) + (add-to-list 'org-capture-templates (jao-org-notes--template mnemonic)) + (setq jao-org-notes--tags (jao-org-notes-all-tags)) (when (fboundp 'org-capture-upgrade-templates) (org-capture-upgrade-templates org-capture-templates))) -- cgit v1.2.3