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

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

[elpa] externals/denote 16335454e1 2/2: Merge pull request #110 from bit


From: ELPA Syncer
Subject: [elpa] externals/denote 16335454e1 2/2: Merge pull request #110 from bitspook/links-with-region-as-title
Date: Sun, 9 Oct 2022 21:57:28 -0400 (EDT)

branch: externals/denote
commit 16335454e108f82b1de355083ac97f5e750cfd1c
Merge: 369f3cc7af b0554c9589
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: GitHub <noreply@github.com>

    Merge pull request #110 from bitspook/links-with-region-as-title
    
    Org-mode-like insert-link behavior with empty active region
---
 denote.el | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/denote.el b/denote.el
index cec80874cd..f85249fb3e 100644
--- a/denote.el
+++ b/denote.el
@@ -2261,16 +2261,20 @@ Use TARGET's title for the link's description.  The 
title comes
 either from the front matter or the file name.
 
 If region is active, use its text as the link's description
-instead of TARGET's title."
+instead of TARGET's title. If active region is empty (i.e
+whitespace-only), insert an id-only link (following org-mode's
+behavior with empty description)."
   (interactive (list (denote-file-prompt) current-prefix-arg))
   (let* ((beg (point))
-         ;; TODO 2022-10-09: Do we need to check for empty region?
          (description (when-let* (((region-active-p))
                                   (beg (region-beginning))
                                   (end (region-end))
-                                  (selected-text 
(buffer-substring-no-properties beg end)))
+                                  (selected-text (string-trim 
(buffer-substring-no-properties beg end))))
                         (delete-region beg end)
-                        selected-text)))
+                        selected-text))
+         ;; If DESCRIPTION is empty, we follow org-mode's behavior of inserting
+         ;; ID-only link
+         (id-only (or id-only (string-empty-p description))))
     (insert
      (denote-link--format-link
       target



reply via email to

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