diff options
author | jao <jao@gnu.org> | 2021-03-02 05:08:18 +0000 |
---|---|---|
committer | jao <jao@gnu.org> | 2021-03-02 05:08:18 +0000 |
commit | 2f73af43db9de972c0ec61bbebc06e1d95079631 (patch) | |
tree | 9fbb9d34d433997aa7abe72e7e1213e0dec5ab1f /lib/org | |
parent | 4d5a02560e5c5aa0da573278b7415071cbd5b5de (diff) | |
download | elibs-2f73af43db9de972c0ec61bbebc06e1d95079631.tar.gz elibs-2f73af43db9de972c0ec61bbebc06e1d95079631.tar.bz2 |
jao-org-notes in lieu of org-roam
Diffstat (limited to 'lib/org')
-rw-r--r-- | lib/org/jao-org-notes.el | 55 |
1 files changed, 53 insertions, 2 deletions
diff --git a/lib/org/jao-org-notes.el b/lib/org/jao-org-notes.el index 3e9abbb..3c3a134 100644 --- a/lib/org/jao-org-notes.el +++ b/lib/org/jao-org-notes.el @@ -28,11 +28,21 @@ (defvar jao-org-notes-dir (expand-file-name "notes" org-directory)) +(defun jao-org-notes--cat () + (let* ((cats (seq-difference (directory-files jao-org-notes-dir) + '("." ".." "attic"))) + (cat (completing-read "Top level category: " cats))) + (cond ((file-exists-p (expand-file-name cat jao-org-notes-dir)) cat) + ((yes-or-no-p "New category, create?") cat) + (t (jao-roam--cat))))) + (defun jao-org-notes--insert-title () - (let ((title (read-string "Title: "))) + (let ((cat (jao-org-notes--cat)) + (title (read-string "Title: "))) (when (not (string-empty-p title)) (let* ((base (replace-regexp-in-string " +" "-" (downcase title))) - (fname (expand-file-name (concat base ".org") jao-org-notes-dir)) + (fname (expand-file-name (concat cat "/" base ".org") + jao-org-notes-dir)) (exists? (file-exists-p fname))) (find-file fname) (when (not exists?) @@ -52,6 +62,47 @@ (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))) + +;;;###autoload +(defun jao-org-notes-consult () + "Search notes directory for tags and titles." + (interactive) + (when-let (f (jao-org--grep)) + (find-file f))) + ;;;###autoload (defun jao-org-notes-open () (interactive) |