summaryrefslogtreecommitdiffhomepage
path: root/lib/org
diff options
context:
space:
mode:
Diffstat (limited to 'lib/org')
-rw-r--r--lib/org/jao-org-notes.el81
1 files changed, 42 insertions, 39 deletions
diff --git a/lib/org/jao-org-notes.el b/lib/org/jao-org-notes.el
index 3a7d7fe..8cd71b8 100644
--- a/lib/org/jao-org-notes.el
+++ b/lib/org/jao-org-notes.el
@@ -20,7 +20,8 @@
;;; Commentary:
-;; A note per file
+;; An org note per file, with consultable title and tags and a
+;; backlinks approximation.
;;; Code:
@@ -29,6 +30,40 @@
(defvar jao-org-notes-dir (expand-file-name "notes" org-directory))
+(defvar jao-org-notes--rg
+ (concat "rg --null --line-buffered --color=ansi --max-columns=250"
+ " --no-heading --line-number --smart-case"
+ " . -e \"^(#.(title|(file|roam_)tags): .*)ARG\" OPTS"))
+
+(defun jao-org-notes--clean-match (m)
+ (cons (replace-regexp-in-string ":[0-9]+:#\\+\\(roam_\\|file\\)?\\(title\\|tags\\):"
+ " (\\2)"
+ (car m))
+ (cdr m)))
+
+(defun jao-org-notes--matches (lines)
+ (let ((ms (consult--grep-matches lines)))
+ (mapcar #'jao-org-notes--clean-match ms)))
+
+(defun jao-org-notes--lookup (_ cands cand)
+ (or (cadr (assoc cand cands)) cand))
+
+(defvar jao-org-notes--grep-history nil)
+
+(defun jao-org--grep (prompt &optional cat no-req)
+ (let ((default-directory (expand-file-name (or cat "") jao-org-notes-dir)))
+ (consult--read
+ (consult--async-command jao-org-notes--rg
+ (consult--async-transform jao-org-notes--matches))
+ :prompt prompt
+ :lookup #'jao-org-notes--lookup
+ :initial consult-async-default-split
+ :add-history (concat consult-async-default-split (thing-at-point 'symbol))
+ :require-match (not no-req)
+ :category 'jao-org-notes-lookup
+ :history '(:input jao-org-notes--grep-history)
+ :sort nil)))
+
(defun jao-org-notes--cat ()
(let* ((cats (seq-difference (directory-files jao-org-notes-dir)
'("." ".." "attic")))
@@ -38,8 +73,9 @@
(t (jao-roam--cat)))))
(defun jao-org-notes--insert-title ()
- (let ((cat (jao-org-notes--cat))
- (title (read-string "Title: ")))
+ (let* ((cat (jao-org-notes--cat))
+ (title (file-name-base (jao-org--grep "Title: " cat t)))
+ (title (replace-regexp-in-string "^#" "" title)))
(when (not (string-empty-p title))
(let* ((base (replace-regexp-in-string " +" "-" (downcase title)))
(fname (expand-file-name (concat cat "/" base ".org")
@@ -68,47 +104,14 @@
(insert "\n"))
(defun jao-org-notes--template (k)
- `(,k "Note" plain (file jao-org-notes-open) "* %a "))
-
-(defvar jao-org-notes--rg
- (concat "rg --null --line-buffered --color=ansi --max-columns=250"
- " --no-heading --line-number --smart-case"
- " . -e \"^(#.(title|(file|roam_)tags): .*)ARG\" OPTS"))
-
-(defun jao-org-notes--clean-match (m)
- (cons (replace-regexp-in-string ":[0-9]+:#\\+\\(roam_\\|file\\)?\\(title\\|tags\\):"
- " (\\2)"
- (car m))
- (cdr m)))
-
-(defun jao-org-notes--matches (lines)
- (let ((ms (consult--grep-matches lines)))
- (mapcar #'jao-org-notes--clean-match ms)))
-
-(defun jao-org-notes--lookup (_ cands cand)
- (cadr (assoc cand cands)))
-
-(defvar jao-org-notes--grep-history nil)
-
-(defun jao-org--grep ()
- (let ((default-directory jao-org-notes-dir))
- (consult--read
- (consult--async-command jao-org-notes--rg
- (consult--async-transform jao-org-notes--matches))
- :prompt "Search notes: "
- :lookup #'jao-org-notes--lookup
- :initial consult-async-default-split
- :add-history (concat consult-async-default-split (thing-at-point 'symbol))
- :require-match t
- :category 'jao-org-notes-lookup
- :history '(:input jao-org-notes--grep-history)
- :sort nil)))
+ `(,k "Note" plain (file jao-org-notes-open) "\n- %a "
+ :immediate-finish t :jump-to-captured t))
;;;###autoload
(defun jao-org-notes-consult ()
"Search notes directory for tags and titles."
(interactive)
- (when-let (f (jao-org--grep))
+ (when-let (f (jao-org--grep "Search notes: "))
(find-file f)))
;;;###autoload