[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))))
- [elpa] externals/denote updated (31e6bcb2eb -> 369f3cc7af), ELPA Syncer, 2022/10/08
- [elpa] externals/denote 4a10683036 5/8: Make stylistic tweaks to denote-link, ELPA Syncer, 2022/10/08
- [elpa] externals/denote d0aab79ed2 4/8: Acknowledge Charanjit Singh, ELPA Syncer, 2022/10/08
- [elpa] externals/denote 369f3cc7af 8/8: Add TODO for denote-link region, ELPA Syncer, 2022/10/08
- [elpa] externals/denote 44c2a6add8 6/8: Clarify denote-link doc string on description text, ELPA Syncer, 2022/10/08
- [elpa] externals/denote fe66333d84 1/8: feat: use region as link title on denote-link,
ELPA Syncer <=
- [elpa] externals/denote e4450998f3 7/8: Document the ability to link to region text, ELPA Syncer, 2022/10/08
- [elpa] externals/denote b350035103 2/8: refactor: handle region-activation entirely in denote-link, ELPA Syncer, 2022/10/08
- [elpa] externals/denote 2bb344e344 3/8: Merge pull request #109 from bitspook/links-with-region-as-title, ELPA Syncer, 2022/10/08