From 2f73af43db9de972c0ec61bbebc06e1d95079631 Mon Sep 17 00:00:00 2001 From: jao Date: Tue, 2 Mar 2021 05:08:18 +0000 Subject: jao-org-notes in lieu of org-roam --- consult.org | 2 +- lib/org/jao-org-notes.el | 55 ++++++++++++++++++++++++++++++++++-- lib/themes/jao-themes.el | 2 ++ org.org | 72 ++++-------------------------------------------- 4 files changed, 62 insertions(+), 69 deletions(-) diff --git a/consult.org b/consult.org index f1ac31c..f55f20f 100644 --- a/consult.org +++ b/consult.org @@ -45,7 +45,7 @@ ("C-x b" . consult-buffer) ("C-x 4 b" . consult-buffer-other-window) ("C-x 5 b" . consult-buffer-other-frame) - ("C-c b" . consult-bookmark) + ("C-c b" . project-find-file) ("C-c B" . bookmark-set) ("C-c h" . consult-history) ("C-c i" . consult-imenu) 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)) diff --git a/org.org b/org.org index 2f6d773..725049d 100644 --- a/org.org +++ b/org.org @@ -75,13 +75,8 @@ ("a" "Appointment" entry (file+olp "inbox.org" "Appointments") "* %^T %?\n %a" :time-prompt t) - ("w" "Wintermute TODO" entry - (file+olp "bigml.org" "Wintermute" "Tasks") - "* TODO %?\n %i%a" :prepend t) ("i" "Inbox note" entry (file+headline "inbox.org" "Notes") - "* %a\n %i%?(added on: %u)" :prepend t) - ("x" "Clipboard" entry (file+headline "inbox.org" "Notes") - "* %?\n %a\n %x\n (added: %u)" :prepend t))) + "* %a\n %i%?(added on: %u)" :prepend t))) ;; (org-capture-upgrade-templates org-capture-templates) #+END_SRC * MIME and file apps @@ -213,67 +208,12 @@ ("C-c I" . org-download-yank)))) #+end_src -* Org roam +* Notes #+begin_src emacs-lisp - (use-package org-roam - :ensure t - :init - (defun jao-roam--slug (slug) (replace-regexp-in-string "_" "-" slug)) - - (defun jao-roam--cat () - (let* ((cats (seq-difference (directory-files org-roam-directory) - '("." ".." "attic"))) - (cat (completing-read "Top level cat: " cats))) - (cond ((file-exists-p (expand-file-name cat org-roam-directory)) cat) - ((yes-or-no-p "New category, create?") cat) - (t (jao-roam--cat))))) - - (setq org-roam-capture-templates - `(("d" "default" plain #'org-roam-capture--get-point - "%a %i" - :file-name "%(jao-roam--cat)/%(jao-roam--slug \"${slug}\")" - :head ,(concat "#+title: ${title}" - "\n#+created: %T" - "\n#+roam_tags: %?" - "\n#+roam_ref: %:url\n\n")))) - - :custom ((org-roam-directory (expand-file-name "~/org/notes")) - (org-roam-encrypt-files nil) - (org-roam-buffer-position nil) - (org-roam-buffer-height nil) - (org-roam-buffer-window-parameters nil) - (org-roam-link-use-custom-faces t) - (org-roam-link-auto-replace t) - (org-roam-tag-sources '(prop vanilla all-directories)) - (org-roam-file-exclude-regexp ".+/code\\|attic/.*") - (org-roam-verbose nil)) - - :config - (defvar org-roam-consult-flags - '("--null" "--ignore-case" "--type=org" "--line-buffered" - "--color=always" "--max-columns=250" "--no-heading" "--line-number")) - - (defun consult-org-roam () - "Search org-roam directory using consult-ripgrep. With live-preview." - (interactive) - (let ((consult-ripgrep-command - (format "rg %s . -e ARG OPTS" - (mapconcat 'identity org-roam-consult-flags " ")))) - (consult-ripgrep org-roam-directory))) - - (major-mode-hydra-define+ org-mode () - ("Roam" - (("i" org-roam-insert "insert") - ("f" org-roam-find-file "find-file") - ("o" consult-org-roam "consult") - ("v" org-roam-buffer-toggle-display "toggle backlinks")))) - - (jao-define-attached-buffer (regexp-quote org-roam-buffer) 0.33) - - :hook ((after-init . org-roam-mode)) - :bind (("C-c n" . org-roam-capture) - ("C-c N" . org-roam-find-file)) - :diminish) + (use-package jao-org-notes + :config (jao-org-notes-setup "n") + :bind (("C-c n" . jao-org-notes-consult) + ("C-c N" . jao-org-notes-open))) #+end_src * Links #+begin_src emacs-lisp -- cgit v1.2.3