branch: externals/denote commit ddbbe549b6826eb59c4eb5a98002e1ab4c7f2625 Author: Protesilaos Stavrou <i...@protesilaos.com> Commit: Protesilaos Stavrou <i...@protesilaos.com>
Use function to test if file likely is a note --- denote-link.el | 5 +---- denote.el | 6 ++++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/denote-link.el b/denote-link.el index 85cbc5f64f..68c55be8d6 100644 --- a/denote-link.el +++ b/denote-link.el @@ -254,10 +254,7 @@ Add this to `find-file-hook' (it will not do anything in 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)))) + (when (and (not (derived-mode-p 'org-mode)) (denote--current-file-is-note-p)) (save-excursion (goto-char (point-min)) (while (re-search-forward denote--id-regexp nil t) diff --git a/denote.el b/denote.el index 80231854ca..3cd2b2ac1d 100644 --- a/denote.el +++ b/denote.el @@ -296,6 +296,12 @@ FILE is relative to the variable `denote-directory'." (string-match-p (concat "\\b" denote--id-regexp) file) (not (string-match-p "[#~]\\'" file)))) +(defun denote--current-file-is-note-p () + "Return non-nil if current file likely is a Denote note." + (and (or (string-match-p denote--id-regexp (buffer-file-name)) + (string-match-p denote--id-regexp (buffer-name))) + (string= (expand-file-name default-directory) (denote-directory)))) + ;;;; Keywords (defun denote--directory-files (&optional absolute)