[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/denote 21f1c98339 1/3: allow checking for subdirs of `d
|
From: |
ELPA Syncer |
|
Subject: |
[elpa] externals/denote 21f1c98339 1/3: allow checking for subdirs of `denote-dired-directories' (fix #190) |
|
Date: |
Wed, 15 Nov 2023 03:57:40 -0500 (EST) |
branch: externals/denote
commit 21f1c98339b8f1c2dcf91a7edbbb19e74af361ad
Author: Henrik Hörmann <leinfink@mailbox.org>
Commit: Henrik Hörmann <leinfink@mailbox.org>
allow checking for subdirs of `denote-dired-directories' (fix #190)
---
denote.el | 37 ++++++++++++++++++++++++++++++++++---
1 file changed, 34 insertions(+), 3 deletions(-)
diff --git a/denote.el b/denote.el
index b5150ec3db..1538a1e24d 100644
--- a/denote.el
+++ b/denote.el
@@ -2811,6 +2811,15 @@ to the `dired-mode-hook'."
:link '(info-link "(denote) Fontification in Dired")
:group 'denote-dired)
+ (defcustom denote-dired-include-subdirectories nil
+ "Whether to enable `denote-dired-mode' in subdirectories of
`denote-dired-directories'.
+
+If nil, enable `denote-dired-mode' only in directories exactly matching one
of `denote-dired-directories', excluding subdirectories.
+
+If non-nil, enable `denote-dired-mode' in `denote-dired-directories' and their
subdirectories."
+ :group 'denote-dired
+ :type 'boolean)
+
;; FIXME 2022-08-12: Make `denote-dired-mode' work with diredfl. This
;; may prove challenging.
@@ -2862,9 +2871,31 @@ written, it is always returned as a directory."
;;;###autoload
(defun denote-dired-mode-in-directories ()
"Enable `denote-dired-mode' in `denote-dired-directories'.
-Add this function to `dired-mode-hook'."
- (when (member (file-truename default-directory)
(denote-dired--modes-dirs-as-dirs))
- (denote-dired-mode 1)))
+Add this function to `dired-mode-hook'.
+
+If `denote-dired-include-subdirectories' is non-nil, also enable
+it in all subdirectories."
+ (cl-labels ((partial-paths (dir)
+ ;; e.g '("/home/", "/home/docs/", "/home/docs/stuff/")
+ (let* ((path-elements (split-string dir "/" t)))
+ (collect-paths
+ (cons (concat "/" (car path-elements))
+ (cdr path-elements))
+ nil)))
+ (collect-paths (path-elements coll)
+ (if path-elements
+ (collect-paths
+ (cdr path-elements)
+ (cons (concat (car coll) (car path-elements) "/")
+ coll))
+ coll)))
+ (let ((cur-path (file-truename default-directory)))
+ (when (seq-intersection
+ (if denote-dired-include-subdirectories
+ (partial-paths cur-path)
+ (list cur-path))
+ (denote-dired--modes-dirs-as-dirs))
+ (denote-dired-mode 1)))))
;;;; The linking facility