branch: externals/denote
commit e7478b1627d709cb0198d95164b3e3680ac7c515
Author: Protesilaos Stavrou <[email protected]>
Commit: Protesilaos Stavrou <[email protected]>

    Simplify how denote-get-link-description checks for function arity
    
    I found func-arity by chance and immediately thought of this. What I
    had before was ugly by comparison, even though its idea made sense.
---
 denote.el | 30 +++++++-----------------------
 1 file changed, 7 insertions(+), 23 deletions(-)

diff --git a/denote.el b/denote.el
index 333713b6d3..69bb7c8b0b 100644
--- a/denote.el
+++ b/denote.el
@@ -5293,30 +5293,14 @@ assigned to `denote-link-description-format' accepts a 
single FILE
 argument.  In that case, the function takes care to find the TYPE on its
 own to return the appropriate description."
   (cond
-   ((when-let* ((_ (functionp denote-link-description-format))
-                ;; NOTE 2025-11-23: We used to have
-                ;; `denote-link-description-format' accept a function
-                ;; with a single parameter.  Now we expect two
-                ;; arguments, but must be backward compatible.
-                ;;
-                ;; By the way, this is how I found `wrong-number-of-arguments':
-                ;;
-                ;;     (let ((errors nil))
-                ;;       (mapatoms
-                ;;        (lambda (symbol)
-                ;;          (when (get symbol 'error-conditions)
-                ;;            (push symbol errors))))
-                ;;       errors)
-                ;;
-                ;; As for `error-conditions', I looked into the source
-                ;; of `define-error' to figure out what an "error" is
-                ;; and saw the property there.
-                (description (ignore-error wrong-number-of-arguments
-                               (funcall denote-link-description-format file 
file-type))))
-      description))
    ((functionp denote-link-description-format)
-    (display-warning 'denote "The `denote-link-description-format' function is 
now called with FILE and FILE-TYPE" :warning)
-    (funcall denote-link-description-format file))
+    ;; NOTE 2025-11-23: `denote-link-description-format' used to
+    ;; accept a function with a single parameter.  Now we expect two
+    ;; arguments, but must be backward compatible.
+    (if (> (cdr (func-arity denote-link-description-format)) 1)
+        (funcall denote-link-description-format file file-type)
+      (display-warning 'denote "The `denote-link-description-format' function 
is now called with FILE and FILE-TYPE" :warning)
+      (funcall denote-link-description-format file)))
    ((stringp denote-link-description-format)
     (if-let* ((region (denote--get-active-region-content)))
         region

Reply via email to