Skip to content

Commit

Permalink
Add denote-link-description-with-signature-and-title and use it as th…
Browse files Browse the repository at this point in the history
…e default
  • Loading branch information
jeanphilippegg committed Nov 3, 2024
1 parent 90c08c1 commit 18e8bb9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 18 deletions.
3 changes: 3 additions & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
49 changes: 31 additions & 18 deletions denote.el
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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."
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 18e8bb9

Please sign in to comment.