summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2021-03-03 02:33:29 +0000
committerjao <jao@gnu.org>2021-03-03 02:33:29 +0000
commitff393cd737e944663975bc446be8105bd438c69d (patch)
tree5d67786b11112960006b1c094c73924ff26fee08 /lib
parent4904bfe53fab813ac6f0cb5d50ee5ac862112ff3 (diff)
downloadelibs-ff393cd737e944663975bc446be8105bd438c69d.tar.gz
elibs-ff393cd737e944663975bc446be8105bd438c69d.tar.bz2
jao-org-notes-insert-link
Diffstat (limited to 'lib')
-rw-r--r--lib/org/jao-org-notes.el34
1 files changed, 25 insertions, 9 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)
@@ -126,18 +127,33 @@
(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