[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/denote 1f55b206bd 2/2: Make 'denote-filetype-heuristics
From: |
ELPA Syncer |
Subject: |
[elpa] externals/denote 1f55b206bd 2/2: Make 'denote-filetype-heuristics' work in 'org-capture' buffers |
Date: |
Sat, 4 Nov 2023 03:57:48 -0400 (EDT) |
branch: externals/denote
commit 1f55b206bd9d7ae9d3f2b4ec97e29b6431b7347d
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: Protesilaos Stavrou <info@protesilaos.com>
Make 'denote-filetype-heuristics' work in 'org-capture' buffers
This means that we can call 'denote-link' while capturing a new note.
Thanks to Peter Smith for reporting the bug in issue 186 on the GitHub
mirror: <https://github.com/protesilaos/denote/issues/186>.
---
README.org | 8 ++++----
denote.el | 40 ++++++++++++++++++++++++----------------
2 files changed, 28 insertions(+), 20 deletions(-)
diff --git a/README.org b/README.org
index 836a9551b1..1b42bb906f 100644
--- a/README.org
+++ b/README.org
@@ -4791,10 +4791,10 @@ Denote is meant to be a collective effort. Every bit
of help matters.
Jay Rajput, Jean-Charles Bagneris, Jens Östlund, Jeremy Friesen,
Jonathan Sahar, Johan Bolmsjö, Juanjo Presa, Kai von Fintel, Kaushal
Modi, M. Hadi Timachi, Mark Olson, Mirko Hernandez, Niall Dooley,
- Paul van Gelder, Peter Prevos, Suhail Singh, Shreyas Ragavan, Stefan
- Thesing, Summer Emacs, Sven Seebeck, Taoufik, TJ Stankus, Viktor
- Haag, Wade Mealing, Yi Liu, Ypot, atanasj, doolio, drcxd, hpgisler,
- pRot0ta1p, rbenit68, relict007, sienic, sundar bp.
+ Paul van Gelder, Peter Prevos, Peter Smith, Suhail Singh, Shreyas
+ Ragavan, Stefan Thesing, Summer Emacs, Sven Seebeck, Taoufik, TJ
+ Stankus, Viktor Haag, Wade Mealing, Yi Liu, Ypot, atanasj, doolio,
+ drcxd, hpgisler, pRot0ta1p, rbenit68, relict007, sienic, sundar bp.
Special thanks to Peter Povinec who helped refine the file-naming
scheme, which is the cornerstone of this project.
diff --git a/denote.el b/denote.el
index 19bdb5bf76..df14b2a45a 100644
--- a/denote.el
+++ b/denote.el
@@ -2148,6 +2148,12 @@ See the format of `denote-file-types'."
(string-equal (plist-get (cdr type) :extension) extension))
denote-file-types))
+(defun denote--file-type-org-capture-p ()
+ "Return Org `denote-file-type' if this is an `org-capture' buffer."
+ (and (bound-and-true-p org-capture-mode)
+ (derived-mode-p 'org-mode)
+ (string-match-p "\\`CAPTURE.*\\.org" (buffer-name))))
+
(defun denote-filetype-heuristics (file)
"Return likely file type of FILE.
Use the file extension to detect the file type of the file.
@@ -2159,22 +2165,24 @@ extension in `denote-file-type'.
If no file types in `denote-file-types' has the file extension,
the file type is assumed to be the first of `denote-file-types'."
- (let* ((file-type)
- (extension (denote-get-file-extension-sans-encryption file))
- (types (denote--file-types-with-extension extension)))
- (cond ((not types)
- (setq file-type (caar denote-file-types)))
- ((= (length types) 1)
- (setq file-type (caar types)))
- (t
- (if-let ((found-type
- (seq-find
- (lambda (type)
- (denote--regexp-in-file-p (plist-get (cdr type)
:title-key-regexp) file))
- types)))
- (setq file-type (car found-type))
- (setq file-type (caar types)))))
- file-type))
+ (if (denote--file-type-org-capture-p)
+ 'org
+ (let* ((file-type)
+ (extension (denote-get-file-extension-sans-encryption file))
+ (types (denote--file-types-with-extension extension)))
+ (cond ((not types)
+ (setq file-type (caar denote-file-types)))
+ ((= (length types) 1)
+ (setq file-type (caar types)))
+ (t
+ (if-let ((found-type
+ (seq-find
+ (lambda (type)
+ (denote--regexp-in-file-p (plist-get (cdr type)
:title-key-regexp) file))
+ types)))
+ (setq file-type (car found-type))
+ (setq file-type (caar types)))))
+ file-type)))
(defun denote--file-attributes-time (file)
"Return `file-attribute-modification-time' of FILE as identifier."