From 2f73af43db9de972c0ec61bbebc06e1d95079631 Mon Sep 17 00:00:00 2001
From: jao <jao@gnu.org>
Date: Tue, 2 Mar 2021 05:08:18 +0000
Subject: jao-org-notes in lieu of org-roam

---
 lib/org/jao-org-notes.el | 55 ++++++++++++++++++++++++++++++++++++++++++++++--
 lib/themes/jao-themes.el |  2 ++
 2 files changed, 55 insertions(+), 2 deletions(-)

(limited to 'lib')

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)
diff --git a/lib/themes/jao-themes.el b/lib/themes/jao-themes.el
index d2ca2ba..3518013 100644
--- a/lib/themes/jao-themes.el
+++ b/lib/themes/jao-themes.el
@@ -956,6 +956,8 @@
             (sldb-frame-line-face (p f00))
             (sldb-frame-label-face (p f01))
             (sldb-condition-face (p f02))
+            (selectrum-group-separator (p dimm))
+            (selectrum-group-title (p dimm))
             (slime-repl-prompt-face (p f00))
             (slime-repl-input-face (p f00) bf)
             (slime-repl-inputed-output-face (p f02))
-- 
cgit v1.2.3