emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/denote fe66333d84 1/8: feat: use region as link title o


From: ELPA Syncer
Subject: [elpa] externals/denote fe66333d84 1/8: feat: use region as link title on denote-link
Date: Sat, 8 Oct 2022 20:57:29 -0400 (EDT)

branch: externals/denote
commit fe66333d84794483364ee931fc5e80184566fde1
Author: Charanjit Singh <bitspook@protonmail.com>
Commit: Charanjit Singh <bitspook@protonmail.com>

    feat: use region as link title on denote-link
    
    It is a common use-case to create a link in existing notes. In such cases, 
some
    text is already there, and user just want to create a link on that text 
(instead
    of inserting the link's title). With this change, if a region is active when
    user tries to insert a link, the region is replaced with the link while 
using
    the region's content as link's title.
---
 denote.el | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/denote.el b/denote.el
index 9742ab4b41..b05e4015aa 100644
--- a/denote.el
+++ b/denote.el
@@ -2241,10 +2241,13 @@ title."
 
 (defun denote-link--format-link (file pattern)
   "Prepare link to FILE using PATTERN."
-  (let* ((file-id (denote-retrieve-filename-identifier file))
+  (let* ((region-text (when (region-active-p)
+                        (buffer-substring (region-beginning) (region-end))))
+         (file-id (denote-retrieve-filename-identifier file))
          (file-type (denote-filetype-heuristics file))
          (file-title (unless (string= pattern denote-link--format-id-only)
-                       (denote--retrieve-title-or-filename file file-type))))
+                       (or region-text
+                           (denote--retrieve-title-or-filename file 
file-type)))))
     (format pattern file-id file-title)))
 
 ;;;###autoload
@@ -2252,14 +2255,17 @@ title."
   "Create link to TARGET note in variable `denote-directory'.
 With optional ID-ONLY, such as a universal prefix
 argument (\\[universal-argument]), insert links with just the
-identifier and no further description.  In this case, the link
-format is always [[denote:IDENTIFIER]]."
+identifier and no further description. In this case, the link
+format is always [[denote:IDENTIFIER]]. If region is active,
+region is replaced with the link while using the region as link
+title."
   (interactive (list (denote-file-prompt) current-prefix-arg))
-  (let ((beg (point)))
-    (insert
-     (denote-link--format-link
-      target
-      (denote-link--file-type-format (buffer-file-name) id-only)))
+  (let ((beg (point))
+        (link (denote-link--format-link
+               target
+               (denote-link--file-type-format (buffer-file-name) id-only))))
+    (when (region-active-p) (delete-region (region-beginning) (region-end)))
+    (insert link)
     (unless (derived-mode-p 'org-mode)
       (make-button beg (point) 'type 'denote-link-button))))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]