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

    BREAKING: make denote-fontify-links-mode only work in plain text
    
    Check what I am doing in denote-fontify-links-mode to make it work
    only in some places and to work around the default behaviour of
    toggling a minor mode interactively.
---
 README.org | 52 +++++++++++++++++++---------------------------
 denote.el  | 70 ++++++++++++++++++++++++++++++++++----------------------------
 2 files changed, 59 insertions(+), 63 deletions(-)

diff --git a/README.org b/README.org
index 80b812abe0..a0fb1ca23a 100644
--- a/README.org
+++ b/README.org
@@ -184,10 +184,10 @@ Here we include more of what you can configure with 
Denote ([[#h:998ae528-9276-4
 (use-package denote
   :ensure t
   :hook
-  ( ;; If you use Markdown or plain text files, then you want to make
-   ;; the Denote links clickable (Org renders links as buttons right
-   ;; away)
-   (text-mode . denote-fontify-links-mode-maybe)
+  (;; If you use plain text files (.txt), then you want to make the
+   ;; Denote links clickable (Org mode and Markdown mode render links
+   ;; as buttons right away and provide commands to open them)
+   (text-mode . denote-fontify-links-mode)
    ;; Apply colours to Denote names in Dired.  This applies to all
    ;; directories.  Check `denote-dired-directories' for the specific
    ;; directories you may prefer instead.  Then, instead of
@@ -3618,38 +3618,28 @@ appropriate than the other.
 :CUSTOM_ID: h:156c5ea3-147b-4f9d-a404-86a00558c60a
 :END:
 
-#+findex: denote-fontify-links-mode
-Denote links are automatically fontified in Org buffers 
([[#h:5e5e3370-12ab-454f-ba09-88ff44214324][Adding a single link]]).
-This means that Org recognises the link and applies the relevant
-properties to it to make it clickable/actionable. Other major modes,
-such as ~markdown-mode~ (for =.md= files) or ~text-mode~ (for =.txt=
-files) do not have this feature built into them. Users can still get
-the same behaviour as with Org by activating the ~denote-fontify-links-mode~.
-
-The ~denote-fontify-links-mode~ is a buffer-local minor mode. Users can enable
-it automatically in plain text files that correspond to denote notes with
-something like this:
+[ Revised as part of {{{development-version}}} to only target the
+  generic ~text-mode~. Org mode and Markdown mode are both excluded
+  because they work with Denote links by default. This revision also
+  inlcudes the =RET= and =C-c C-o= key bindings for fontified links. ]
 
-#+begin_src emacs-lisp
-(add-hook 'text-mode-hook #'denote-fontify-links-mode-maybe)
-#+end_src
-
-The ~text-mode-hook~ applies to all modes derived from ~text-mode~, including
-~markdown-mode~. Though a more explicit setup does no harm:
+#+findex: denote-fontify-links-mode
+Denote links are automatically fontified in Org mode and Markdown mode
+buffers ([[#h:5e5e3370-12ab-454f-ba09-88ff44214324][Adding a single link]]). 
This means that the given major mode
+recognises the link and applies to it the relevant properties that
+make it clickable/actionable. The generic ~text-mode~ (for =.txt=
+files) does not have this capability, hence the ~denote-fontify-links-mode~:
+it makes all Denote links actionable with the mouse, =RET=, or =C-c C-o=.
+The ~denote-fontify-links-mode~ is a buffer-local minor mode. Users
+can enable it automatically in plain text files that correspond to
+denote notes with something like this:
 
 #+begin_src emacs-lisp
-(add-hook 'markdown-mode-hook #'denote-fontify-links-mode-maybe)
+(add-hook 'text-mode-hook #'denote-fontify-links-mode)
 #+end_src
 
-Because Org already recognises =denote:= links, the function
-~denote-fontify-links-mode-maybe~ will not enable the mode
-~denote-fontify-links-mode~ in Org buffers.
-
-#+findex: denote-link-markdown-follow
-In files whose major mode is ~markdown-mode~, the default key binding
-=C-c C-o= (which calls the command ~markdown-follow-thing-at-point~)
-correctly resolves =denote:= links. Interested users can refer to the
-function ~denote-link-markdown-follow~ for the implementation details.
+Fontified links can be opened with =RET=, =C-c C-o=, or a mouse click
+(=C-c C-o= is also the default for Org and Markdown).
 
 ** The ~denote-link-description-format~ to format link descriptions
 :PROPERTIES:
diff --git a/denote.el b/denote.el
index 79a2b123ca..1c5c02d905 100644
--- a/denote.el
+++ b/denote.el
@@ -6468,47 +6468,53 @@ To be used as a `thing-at' provider."
 
 (defvar thing-at-point-provider-alist)
 
-;;;###autoload
-(defun denote-fontify-links-mode-maybe ()
-  "Enable `denote-fontify-links-mode' unless in Org or Markdown.
-Org or Markdown buffers automatically recognise Denote links."
-  (when (and buffer-file-name
-             (not (derived-mode-p 'org-mode 'markdown-mode))
-             (denote-file-is-in-denote-directory-p buffer-file-name)
-             (denote-file-has-supported-extension-p buffer-file-name)
-             (denote-file-has-denoted-filename-p buffer-file-name))
-    (denote-fontify-links-mode)))
+(define-obsolete-function-alias
+  'denote-fontify-links-mode-maybe
+  'denote-fontify-links-mode
+  "4.2.0")
 
 ;;;###autoload
 (define-minor-mode denote-fontify-links-mode
   "Fontify Denote links in plain text buffers.
-
-Enable this mode only when the current buffer is a Denote note and the
-major mode is not `org-mode' or `markdown-mode' (or any major mode
-derived therefrom).  Consider using `denote-fontify-links-mode-maybe'
-instead of calling the function `denote-fontify-links-mode' directly
-because `denote-fontify-links-mode-maybe' will activate the mode only if
-necessary."
+Do so only when the current buffer is a Denote note and the major mode
+is not `org-mode' or `markdown-mode' (or any major mode derived
+therefrom)."
   :init-value nil
   :global nil
   :group 'denote
   (require 'thingatpt)
-  (if denote-fontify-links-mode
+  (if (and buffer-file-name
+           (not (derived-mode-p 'org-mode 'markdown-mode))
+           (denote-file-is-in-denote-directory-p buffer-file-name)
+           (denote-file-has-supported-extension-p buffer-file-name)
+           (denote-file-has-denoted-filename-p buffer-file-name))
       (progn
-        (add-to-invisibility-spec 'denote-fontified-link)
-        (denote-fontify-links--set-data)
-        (font-lock-add-keywords nil '((denote-fontify-links)))
-        (setq-local thing-at-point-provider-alist
-                    (append thing-at-point-provider-alist
-                            '((url . denote--get-link-file-path-at-point)))))
-    (remove-from-invisibility-spec 'denote-fontified-link)
-    (kill-local-variable 'denote-fontify-links--data)
-    (font-lock-remove-keywords nil '((denote-fontify-links)))
-    (setq-local thing-at-point-provider-alist
-                (delete
-                 '(url . denote--get-link-file-path-at-point)
-                 thing-at-point-provider-alist)))
-  (font-lock-update))
+        (if denote-fontify-links-mode
+            (progn
+              (add-to-invisibility-spec 'denote-fontified-link)
+              (denote-fontify-links--set-data)
+              (font-lock-add-keywords nil '((denote-fontify-links)))
+              (setq-local thing-at-point-provider-alist
+                          (append thing-at-point-provider-alist
+                                  '((url . 
denote--get-link-file-path-at-point)))))
+          (remove-from-invisibility-spec 'denote-fontified-link)
+          (kill-local-variable 'denote-fontify-links--data)
+          (font-lock-remove-keywords nil '((denote-fontify-links)))
+          (setq-local thing-at-point-provider-alist
+                      (delete
+                       '(url . denote--get-link-file-path-at-point)
+                       thing-at-point-provider-alist)))
+        (font-lock-update))
+    ;; NOTE 2026-01-02: If we do not set the value here, then it is
+    ;; toggled on/off even though the above `if' never reaches its
+    ;; THEN branch.
+    (setq denote-fontify-links-mode nil)
+    ;; NOTE 2026-01-02: In interactive use, we get a message that the
+    ;; mode is disabled if we call it in non-supported buffers.  I
+    ;; tried to `let' bind the `inhibit-message' but that did not
+    ;; work.  So I am doing this instead...
+    (when (called-interactively-p 'interactive)
+      (message "`denote-fontify-links-mode' works only in plain text buffers 
inside the `denote-directory'"))))
 
 ;;;;; Add links matching regexp
 

Reply via email to