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

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

[elpa] externals/denote 18e8bb9ece 2/3: Add denote-link-description-with


From: ELPA Syncer
Subject: [elpa] externals/denote 18e8bb9ece 2/3: Add denote-link-description-with-signature-and-title and use it as the default
Date: Mon, 4 Nov 2024 00:57:52 -0500 (EST)

branch: externals/denote
commit 18e8bb9ece60ce0d1839ff51cebeb12acceac368
Author: Jean-Philippe Gagné Guay <jeanphilippe150@gmail.com>
Commit: Jean-Philippe Gagné Guay <jeanphilippe150@gmail.com>

    Add denote-link-description-with-signature-and-title and use it as the 
default
---
 README.org |  3 +++
 denote.el  | 49 +++++++++++++++++++++++++++++++------------------
 2 files changed, 34 insertions(+), 18 deletions(-)

diff --git a/README.org b/README.org
index 3715c3c4b3..afa7987a48 100644
--- a/README.org
+++ b/README.org
@@ -3359,6 +3359,9 @@ The value can be either a function or a string. If it is 
a function,
 it is called with one argument, the file, and should return a string
 representing the link description.
 
+The default is a function that returns the active region or the title of
+the note (with the signature if present).
+
 If the value is a string, it treats specially the following specifiers:
 
 - The =%t= is the Denote =TITLE= of the file.
diff --git a/denote.el b/denote.el
index c97b4a0628..e9802e39a6 100644
--- a/denote.el
+++ b/denote.el
@@ -865,7 +865,7 @@ have been warned."
 ;; FIXME 2024-11-03: This breaks `denote-link-with-signature'.  Check
 ;; the FIXME above that function to decide how best to proceed.
 
-(defcustom denote-link-description-format "%t"
+(defcustom denote-link-description-format 
#'denote-link-description-with-signature-and-title
   "The format of a link description text.
 This determines how `denote-link' and related functions create a link
 description by default.
@@ -874,6 +874,9 @@ The value can be either a function or a string.  If it is a 
function, it
 is called with one argument, the file, and should return a string
 representing the link description.
 
+The default is a function that returns the active region or the title of
+the note (with the signature if present).
+
 If the value is a string, it treats specially the following specifiers:
 
 - The %t is the Denote TITLE of the file.
@@ -903,7 +906,7 @@ a [D] prefix.
 If the region is active, its text is used as the link's description."
   :type '(choice
           (string :tag "String with treats format specifiers specially")
-          (function :tag "Custom function like `denote-get-link-description'"))
+          (function :tag "Custom function like 
`denote-link-description-with-signature-and-title'"))
   :package-version '(denote . "3.2.0")
   :group 'denote)
 
@@ -4086,10 +4089,29 @@ With optional INCLUDE-DATE, convert the identifier using
 
 (make-obsolete 'denote-link-signature-format nil "2.3.0")
 
-(make-obsolete
- 'denote-link-description-with-signature-and-title
- 'denote-get-link-description
- "3.2.0: Also see the user option `denote-link-description-format'.")
+(defun denote-link-description-with-signature-and-title (file)
+  "Return link description for FILE.
+
+- If the region is active, use it as the description.
+
+- If FILE has a signature, then format the description as a sequence of
+  the signature text and the title with two spaces between them.
+
+- If FILE does not have a signature, then use its title as the
+  description.
+
+This is useful as the value of the user option
+`denote-link-description-function'."
+  (let* ((file-type (denote-filetype-heuristics file))
+         (signature (denote-retrieve-filename-signature file))
+         (title (denote-retrieve-title-or-filename file file-type))
+         (region-text (denote--get-active-region-content)))
+    (cond
+     (region-text region-text)
+     ((and signature title) (format "%s  %s" signature title))
+     (title (format "%s" title))
+     (signature (format "%s" signature))
+     (t ""))))
 
 (defun denote--get-active-region-content ()
   "Return the text of the active region, else nil."
@@ -4105,9 +4127,6 @@ With optional INCLUDE-DATE, convert the identifier using
               (end (region-end)))
     (delete-region beg end)))
 
-;; FIXME 2024-11-03: This breaks `denote-link-with-signature'.  Check
-;; the FIXME above that function to decide how best to proceed.
-
 (defun denote-get-link-description (file)
   "Return a link description for FILE.
 
@@ -4154,7 +4173,9 @@ case, derive FILE-TYPE from the current buffer.  
FILE-TYPE is used to
 determine the format of the link.
 
 Return the DESCRIPTION of the link in the format specified by
-`denote-link-description-format'.
+`denote-link-description-format'.  The default is to return the text of
+the active region or the title of the note (with the signature if
+present).
 
 With optional ID-ONLY as a non-nil argument, such as with a universal
 prefix (\\[universal-argument]), insert links with just the identifier
@@ -4186,14 +4207,6 @@ Also see `denote-link-with-signature'."
 (defalias 'denote-insert-link 'denote-link
   "Alias for `denote-link' command.")
 
-;; FIXME 2024-11-03: This is now broken by the
-;; `denote-get-link-description', which only reads the
-;; `denote-link-description-format'.  How best to ensure we keep the
-;; behaviour that was there before?  Maybe make the user option accept
-;; an alist and have `denote-get-link-description' try to read that if
-;; given a non-nil value for a CONSIDER-SIGNATURE parameter (or
-;; something along those lines)?
-
 ;;;###autoload
 (defun denote-link-with-signature ()
   "Insert link to file with signature.



reply via email to

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