Skip to content
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

Excluded directories feature #101

Closed
Sabicool opened this issue Dec 10, 2024 · 5 comments
Closed

Excluded directories feature #101

Sabicool opened this issue Dec 10, 2024 · 5 comments

Comments

@Sabicool
Copy link

Sabicool commented Dec 10, 2024

I am not a programmer and don't know how to do pull requests. Here is an implementation of excluding some directories in obsidian using the f.el package:

(defcustom obsidian-exclude-directories nil
  "List of directories to exclude from Obsidian file searches.
Each directory should be a full path relative to `obsidian-directory`."
  :type '(repeat directory)
  :group 'obsidian)

(defun obsidian-not-in-excluded-directories-p (&optional file)
  "Check if FILE is not in any of the excluded directories.
If FILE is not provided, use the current buffer's file name."
  (let ((target-file (or file (when (buffer-file-name) (buffer-file-name)))))
    (if (and target-file obsidian-exclude-directories)
        (not (seq-some (lambda (dir)
                         (f-descendant-of-p target-file dir))
                       obsidian-exclude-directories))
      t)))

(defun obsidian-reset-cache ()
  "Clear and reset obsidian cache.
Excludes files in directories specified by `obsidian-exclude-directories`."
  (setq obsidian-files-cache
        (->> (directory-files-recursively obsidian-directory "\.*$")
             (-filter #'obsidian-file-p)
             (-filter #'obsidian-not-in-excluded-directories-p)))
  (setq obsidian-cache-timestamp (float-time)))

I use it to exclude folders for markdown files which may not have syntax correct yaml front matter resulting in obsidian.el throwing errors such as the one mentioned in #99

@licht1stein
Copy link
Owner

Thanks! The error will be fixed in the version 2.0, I think.

@Sabicool
Copy link
Author

Either way, @licht1stein, I believe it would be useful to have this feature of excluding directories. For example, excluding the excalidraw folder.

@licht1stein
Copy link
Owner

Well if you ask @jayemar nicely maybe he'll include it in version 2. He's doing all the work for it.

@jayemar
Copy link
Collaborator

jayemar commented Dec 13, 2024

I added this feature yesterday along with tests and a mention in the README, so it should be all ready to go for 2.0.

@Sabicool
Copy link
Author

I added this feature yesterday along with tests and a mention in the README, so it should be all ready to go for 2.0.

Ah okay I will close this issue. Thank you for developing this package

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants