aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlcah <27054757+alcah@users.noreply.github.com>2021-08-02 18:25:01 +0930
committerAlcah <27054757+alcah@users.noreply.github.com>2021-08-02 18:26:34 +0930
commit9d06e1ac0789f24f66689b34b969a0660842bf11 (patch)
treea9907286d46b4f9797ee6840eee60e3948200326
parent96a000fb27a5e8726f23423e970c6eb99f3575fe (diff)
downloademacs-zettelkasten-9d06e1ac0789f24f66689b34b969a0660842bf11.tar.gz
emacs-zettelkasten-9d06e1ac0789f24f66689b34b969a0660842bf11.zip
optionally use highlighted region as link text
-rw-r--r--zettelkasten.el13
1 files changed, 9 insertions, 4 deletions
diff --git a/zettelkasten.el b/zettelkasten.el
index 10e4639..df24679 100644
--- a/zettelkasten.el
+++ b/zettelkasten.el
@@ -90,10 +90,10 @@ aims to remove."
(string-match "[^0-9]*\\([0-9]+\\)" note)
(match-string 1 note))
-(defun zettelkasten--format-link (note)
+(defun zettelkasten--format-link (note &optional link-text)
"Format a link to a NOTE."
(format zettelkasten-link-format
- (zettelkasten--get-note-title note)
+ (or link-text (zettelkasten--get-note-title note))
(zettelkasten--get-id note)
zettelkasten-extension))
@@ -375,11 +375,16 @@ publishing."
;;; ---------------------
(defun zettelkasten-insert-link (note)
- "Insert a link to another NOTE in the current note."
+ "Insert a link to another NOTE in the current note.
+if region is active use that as link text"
(interactive
(list (completing-read "Notes: "
(zettelkasten--list-notes) nil 'match)))
- (insert (zettelkasten--format-link (zettelkasten--get-id note))))
+ (let ((region-text (when (use-region-p)
+ (prog1 (buffer-substring-no-properties (region-beginning)
+ (region-end))
+ (delete-region (region-beginning) (region-end))))))
+ (insert (zettelkasten--format-link (zettelkasten--get-id note) region-text))))
(defun zettelkasten-create-new-note (prefix)
"Create a new zettelkasten.