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

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

[elpa] externals/denote b0554c9589 1/2: fix: org-mode-like insert-link b


From: ELPA Syncer
Subject: [elpa] externals/denote b0554c9589 1/2: fix: org-mode-like insert-link behavior with empty active region
Date: Sun, 9 Oct 2022 21:57:28 -0400 (EDT)

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

    fix: org-mode-like insert-link behavior with empty active region
    
    If user has whitespace-only region active when inserting a denote-link, 
behave
    org-mode does when inserting a link in this case. i.e selected region is
    deleted, and an id-only link is inserted. Active region is trimmed 
regardless,
    so if user try to link "hello " part of "hello world", the text is changed 
to
    "helloworld" with "hello" being the link description and "world" plain text.
---
 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]