New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow checking for subdirs of `denote-dired-directories' (fix #190) #191
Conversation
|
I set the default value of the user option to |
|
Merged. Thank you! |
This change is within the ~15 line limit and thus does not require copyright assignment to the Free Software Foundation. It was done in pull request 191 on the GitHub mirror: <#191>.
|
@leinfink What do you think about this tweak? main 1ecbd55b46b7799348fdb9cb095357286ea30501
Author: Protesilaos Stavrou <info@protesilaos.com>
AuthorDate: Wed Nov 15 08:20:04 2023 +0200
Commit: Protesilaos Stavrou <info@protesilaos.com>
CommitDate: Wed Nov 15 08:20:04 2023 +0200
Parent: d26b50b Acknowledge leinfink for commit 21f1c98
Merged: main
Contained: main
Follows: 2.1.0 (5)
Simplify denote-dired-mode-in-directories (tweak 21f1c98)
1 file changed, 9 insertions(+), 21 deletions(-)
denote.el | 30 +++++++++---------------------
modified denote.el
@@ -2875,27 +2875,15 @@ (defun denote-dired-mode-in-directories ()
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)))))
+ (when-let ((dirs (denote-dired--modes-dirs-as-dirs))
+ ;; Also include subdirs
+ ((and denote-dired-include-subdirectories
+ (or (member (file-truename default-directory) (denote-dired--modes-dirs-as-dirs))
+ (seq-some
+ (lambda (dir)
+ (string-prefix-p dir (file-truename default-directory)))
+ dirs)))))
+ (denote-dired-mode 1)))
;;;; The linking facility
|
|
Great, that looks much more elegant! |
|
Ah wait, shouldn't the Like this: |
|
And perhaps make it even more compact by using the |
Thanks to leinfink for the feedback in the comments of pull request 190 on the GitHub mirror: <#191>.
… user option This is a follow-up to pull request 190 on the GitHub mirror, which added the original idea: <#191>. Thanks to leinfink for the contribution!
|
Thanks for the feedback! I tweaked the code. Also updated the name of the variable to make it easier to communicate what it does. |
This fixes #190.
I don't have a lot of experience in Elisp, so this might not be the best way of doing it, feel free to change things. Basically, I take the current path and build up a list of all sub-paths in it (e.g., for
"/home/docs/stuff/", we get'("/home/" "/home/docs/" "/home/docs/stuff/"). As long as one of them is a member ofdenote-dired-directories, we should enabledenote-dired-mode. This way, we don't have to actually scan for subdirectories.