(internal): Simplify `org-roam--list-files` implementation. (#497)

Use destructive elisp functions to optimize for speed and memory
usage.

Refs #104
master
Jürgen Hötzel 6 years ago committed by GitHub
parent 228af5b6be
commit a35454bb7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 21
      org-roam.el

@ -174,22 +174,11 @@ If FILE is not specified, use the current buffer's file-path."
(defun org-roam--list-files (dir)
"Return all Org-roam files located within DIR, at any nesting level.
Ignores hidden files and directories."
(if (file-exists-p dir)
(let ((files (directory-files dir t "." t))
(dir-ignore-regexp (concat "\\(?:"
"\\."
"\\|\\.\\."
"\\)$"))
result)
(dolist (file files)
(cond
((file-directory-p file)
(unless (string-match dir-ignore-regexp file)
(setq result (append (org-roam--list-files file) result))))
((and (file-readable-p file)
(org-roam--org-file-p file))
(setq result (cons (file-truename file) result)))))
result)))
(let ((regex (concat "\\.\\(?:"(mapconcat #'regexp-quote org-roam-file-extensions "\\|" )"\\)\\(?:\\.gpg\\)?\\'"))
result)
(dolist (file (directory-files-recursively dir regex) result)
(when (and (file-readable-p file) (org-roam--org-file-p file))
(push file result)))))
(defun org-roam--list-all-files ()
"Return a list of all Org-roam files within `org-roam-directory'."

Loading…
Cancel
Save