[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/denote d8ef0a0c7c 282/355: EXPERIMENTAL Add buttonizati
From: |
ELPA Syncer |
Subject: |
[elpa] externals/denote d8ef0a0c7c 282/355: EXPERIMENTAL Add buttonization for all links |
Date: |
Sun, 26 Jun 2022 23:58:33 -0400 (EDT) |
branch: externals/denote
commit d8ef0a0c7c557f278e8296650ac7a4079ce1ee05
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: Protesilaos Stavrou <info@protesilaos.com>
EXPERIMENTAL Add buttonization for all links
There still are areas to be refined. The idea is to have the
'denote-link-buttonize-buffer' function make all 'denote:' links
clickable.
---
denote-link.el | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 77 insertions(+), 10 deletions(-)
diff --git a/denote-link.el b/denote-link.el
index 602dbf5ff2..85cbc5f64f 100644
--- a/denote-link.el
+++ b/denote-link.el
@@ -144,10 +144,13 @@ argument (\\[universal-argument]), insert links with just
the
identifier and no further description. In this case, the link
format is always [[denote:IDENTIFIER]]."
(interactive (list (denote-retrieve--read-file-prompt) current-prefix-arg))
- (insert
- (denote-link--format-link
- target
- (denote-link--extension-format-or-id id-only))))
+ (let ((beg (point)))
+ (insert
+ (denote-link--format-link
+ target
+ (denote-link--extension-format-or-id id-only)))
+ (unless (derived-mode-p 'org-mode)
+ (make-button beg (point) 'type 'denote-link-button))))
(defalias 'denote-link-insert-link (symbol-function 'denote-link))
@@ -193,20 +196,84 @@ format is always [[denote:IDENTIFIER]]."
(find-file (denote-link--find-file-prompt files))
(user-error "No links found in the current buffer")))
-;;;; Backlinks' buffer
+;;;; Link buttons
-(define-button-type 'denote-link-backlink-button
+;; TODO 2022-06-19: Review link and backlins buttons. Consolidate what
+;; is needed.
+
+;; Evaluate: (info "(elisp) Button Properties")
+;;
+;; Button can provide a help-echo function as well, but I think we might
+;; not need it.
+(define-button-type 'denote-link-button
'follow-link t
- 'action #'denote-link--find-file
- 'face 'unspecified)
+ 'action #'denote-link--find-file-at-button)
+
+(autoload 'thing-at-point-looking-at "thingatpt")
+
+(defun denote-link--link-at-point-string ()
+ "Return identifier at point."
+ (when (or (thing-at-point-looking-at denote-link--regexp-plain)
+ (thing-at-point-looking-at denote-link--regexp-markdown)
+ (thing-at-point-looking-at denote-link--regexp-org)
+ ;; REVIEW 2022-06-19: This is crude. It is meant to handles
+ ;; the case where a link is broken by `fill-paragraph' into
+ ;; two lines, in which case it buttonizes only the
+ ;; "denote:ID" part. Example:
+ ;;
+ ;; [[denote:20220619T175212][This is a
+ ;; test]]
+ (thing-at-point-looking-at "\\[\\(denote:.*\\)]"))
+ (match-string-no-properties 0)))
+
+(defun denote-link--id-from-string (string)
+ "Extract identifier from STRING."
+ (replace-regexp-in-string
+ (concat ".*denote:" "\\(" denote--id-regexp "\\)" ".*")
+ "\\1" string))
;; NOTE 2022-06-15: I add this as a variable for advanced users who may
;; prefer something else. If there is demand for it, we can make it a
;; defcustom, but I think it would be premature at this stage.
(defvar denote-link-buton-action #'find-file-other-window
- "Action for `denote-link--find-file'.")
+ "Action for Denote buttons.")
+
+(defun denote-link--find-file-at-button (button)
+ "Visit file referenced by BUTTON."
+ (let ((id (denote-link--id-from-string
+ (buffer-substring-no-properties
+ (button-start button)
+ (button-end button)))))
+ (funcall denote-link-buton-action (file-name-completion id
(denote-directory)))))
+
+(defun denote-link-buttonize-buffer ()
+ "Make denote: links actionable buttons in the current buffer.
+Add this to `find-file-hook' (it will not do anything in
+`org-mode' buffers, as buttons already work there).
+
+DEVELOPMENT NOTE: This is experimental and subject to review
+before the release of version 0.1.0. Please test it and/or share
+your thoughts about it."
+ (when (and (not (derived-mode-p 'org-mode))
+ ;; A crude check to test if this is a note
+ (or (string-match-p denote--id-regexp (buffer-file-name))
+ (string= (expand-file-name default-directory)
(denote-directory))))
+ (save-excursion
+ (goto-char (point-min))
+ (while (re-search-forward denote--id-regexp nil t)
+ (when-let ((string (denote-link--link-at-point-string))
+ (beg (match-beginning 0))
+ (end (match-end 0)))
+ (make-button beg end 'type 'denote-link-button))))))
+
+;;;; Backlinks' buffer
+
+(define-button-type 'denote-link-backlink-button
+ 'follow-link t
+ 'action #'denote-link--backlink-find-file
+ 'face 'unspecified)
-(defun denote-link--find-file (button)
+(defun denote-link--backlink-find-file (button)
"Action for BUTTON to `find-file'."
(funcall denote-link-buton-action (buffer-substring (button-start button)
(button-end button))))
- [elpa] externals/denote 443c687f05 248/355: Update denote-dired--edit-front-matter-p docstring, (continued)
- [elpa] externals/denote 443c687f05 248/355: Update denote-dired--edit-front-matter-p docstring, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 9b9a764e57 230/355: Fix typo about package name, ELPA Syncer, 2022/06/27
- [elpa] externals/denote d09249d48f 253/355: Make 'default-directory' safe for denote-directory, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 737c647957 246/355: Rename buffer post file rename, ELPA Syncer, 2022/06/27
- [elpa] externals/denote d0584c0e15 271/355: Refine denote--only-note-p conditions, ELPA Syncer, 2022/06/27
- [elpa] externals/denote dcf8739474 261/355: Improve valid note test (revise ecaaa6b, 8e5899d), ELPA Syncer, 2022/06/27
- [elpa] externals/denote 83d53afae4 245/355: Improve dired revert-buffer post rename, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 8e5899d90e 260/355: Match only files that start with ID in file search, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 341cd28b5a 266/355: Fix bug with 'default-directory' reset, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 0f149afba2 264/355: Simplify how temp buffer contents are returned, ELPA Syncer, 2022/06/27
- [elpa] externals/denote d8ef0a0c7c 282/355: EXPERIMENTAL Add buttonization for all links,
ELPA Syncer <=
- [elpa] externals/denote 843fb30dff 301/355: Answer FAQ about sorting files, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 47a9024b00 252/355: BREAKING update the .dir-locals.el sample, ELPA Syncer, 2022/06/27
- [elpa] externals/denote bd14f8a813 293/355: REMOVE denote-link-register-ol-hyperlink variable, ELPA Syncer, 2022/06/27
- [elpa] externals/denote a611e08ec1 285/355: Clarify that linking still needs some updates, ELPA Syncer, 2022/06/27
- [elpa] externals/denote c3feb9a0ec 250/355: Remove superfluous when, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 662a71d051 330/355: Remove development note about links, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 3b2db33812 322/355: Remove development note about backlinks, ELPA Syncer, 2022/06/27
- [elpa] externals/denote ed75652925 341/355: Remove the ref card from the manual, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 8394280f95 317/355: Refine regexp for front-matter date extraction, ELPA Syncer, 2022/06/27
- [elpa] externals/denote b25235e93e 331/355: Add header links to the mailing list, ELPA Syncer, 2022/06/27