From ff393cd737e944663975bc446be8105bd438c69d Mon Sep 17 00:00:00 2001 From: jao Date: Wed, 3 Mar 2021 02:33:29 +0000 Subject: jao-org-notes-insert-link --- lib/org/jao-org-notes.el | 34 +++++++++++++++++++++++++--------- org.org | 14 ++++++++++---- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/lib/org/jao-org-notes.el b/lib/org/jao-org-notes.el index 8cd71b8..9624a94 100644 --- a/lib/org/jao-org-notes.el +++ b/lib/org/jao-org-notes.el @@ -108,14 +108,15 @@ :immediate-finish t :jump-to-captured t)) ;;;###autoload -(defun jao-org-notes-consult () - "Search notes directory for tags and titles." +(defun jao-org-notes-open () + "Search for a note file, matching tags and titles with completion." (interactive) (when-let (f (jao-org--grep "Search notes: ")) (find-file f))) ;;;###autoload -(defun jao-org-notes-open () +(defun jao-org-notes-open-or-create () + "Open or create a new note file, matching tags and titles with completion." (interactive) (when (jao-org-notes--insert-title) (jao-org-notes--insert-date) @@ -125,19 +126,34 @@ (save-buffer) (buffer-file-name)) +;;;###autoload +(defun jao-org-notes-backlinks () + "Show a list of note files linking to the current one." + (interactive) + (consult-ripgrep jao-org-notes-dir + (concat "\\[\\[file:(.*/)?" (regexp-quote (buffer-name))))) + +;;;###autoload +(defun jao-org-notes-insert-link () + "Select a note file (with completion) and insert a link to it." + (interactive) + (when-let (f (jao-org--grep "Notes file: ")) + (let ((rel-path (file-relative-name f default-directory)) + (title (with-current-buffer (find-file-noselect f) + (save-excursion + (goto-char (point-min)) + (when (re-search-forward "^#\\+title: \\(.+\\)" nil t) + (match-string 1)))))) + (insert (format "[[file:%s][%s]]" rel-path title))))) + ;;;###autoload (defun jao-org-notes-setup (mnemonic) + "Set up the notes system, providing a mnemonic character for its org template." (setq org-capture-templates (add-to-list 'org-capture-templates (jao-org-notes--template mnemonic))) (add-to-list 'org-agenda-files jao-org-notes-dir) (when (fboundp 'org-capture-upgrade-templates) (org-capture-upgrade-templates org-capture-templates))) -;;;###autoload -(defun jao-org-notes-backlinks () - (interactive) - (consult-ripgrep jao-org-notes-dir - (concat "\\[\\[file:(.*/)?" (regexp-quote (buffer-name))))) - (provide 'jao-org-notes) ;;; jao-org-notes.el ends here diff --git a/org.org b/org.org index 725049d..0e300ec 100644 --- a/org.org +++ b/org.org @@ -211,8 +211,15 @@ * Notes #+begin_src emacs-lisp (use-package jao-org-notes - :config (jao-org-notes-setup "n") - :bind (("C-c n" . jao-org-notes-consult) + :config + (jao-org-notes-setup "n") + (major-mode-hydra-define+ org-mode () + ("Notes" + (("i" jao-org-notes-insert-link "insert link") + ("o" jao-org-notes-open "find and open note") + ("c" jao-org-notes-open-or-create "open or create note") + ("v" jao-org-notes-backlinks "show backlinks")))) + :bind (("C-c n" . jao-org-notes-open-or-create) ("C-c N" . jao-org-notes-open))) #+end_src * Links @@ -225,8 +232,7 @@ (require 'ol-docview nil t) (require 'ol-info nil t) - (setq org-link-abbrev-alist - '(("jao.io" "https://jao.io/"))) + (setq org-link-abbrev-alist '(("jao.io" "https://jao.io/"))) #+end_src * jao-org #+begin_src emacs-lisp -- cgit v1.2.3