diff --git a/org-roam-compat.el b/org-roam-compat.el index cfa9692..7251308 100644 --- a/org-roam-compat.el +++ b/org-roam-compat.el @@ -33,7 +33,90 @@ ;;; Code: ;;;; Library Requires +;;; Backports +;; REVIEW Remove when 26.x support is dropped. This is exact the same as +;; `directory-files-recursively' from Emacs 26, but with FOLLOW-SYMLINKS +;; parameter from Emacs 27. +(defun org-roam--directory-files-recursively (dir regexp + &optional include-directories predicate + follow-symlinks) + "Return list of all files under directory DIR whose names match REGEXP. +This function works recursively. Files are returned in \"depth +first\" order, and files from each directory are sorted in +alphabetical order. Each file name appears in the returned list +in its absolute form. + +By default, the returned list excludes directories, but if +optional argument INCLUDE-DIRECTORIES is non-nil, they are +included. + +PREDICATE can be either nil (which means that all subdirectories +of DIR are descended into), t (which means that subdirectories that +can't be read are ignored), or a function (which is called with +the name of each subdirectory, and should return non-nil if the +subdirectory is to be descended into). + +If FOLLOW-SYMLINKS is non-nil, symbolic links that point to +directories are followed. Note that this can lead to infinite +recursion." + (let* ((result nil) + (files nil) + (dir (directory-file-name dir)) + ;; When DIR is "/", remote file names like "/method:" could + ;; also be offered. We shall suppress them. + (tramp-mode (and tramp-mode (file-remote-p (expand-file-name dir))))) + (dolist (file (sort (file-name-all-completions "" dir) + 'string<)) + (unless (member file '("./" "../")) + (if (directory-name-p file) + (let* ((leaf (substring file 0 (1- (length file)))) + (full-file (concat dir "/" leaf))) + ;; Don't follow symlinks to other directories. + (when (and (or (not (file-symlink-p full-file)) + (and (file-symlink-p full-file) + follow-symlinks)) + ;; Allow filtering subdirectories. + (or (eq predicate nil) + (eq predicate t) + (funcall predicate full-file))) + (let ((sub-files + (if (eq predicate t) + (condition-case nil + (org-roam--directory-files-recursively + full-file regexp include-directories + predicate follow-symlinks) + (file-error nil)) + (org-roam--directory-files-recursively + full-file regexp include-directories + predicate follow-symlinks)))) + (setq result (nconc result sub-files)))) + (when (and include-directories + (string-match regexp leaf)) + (setq result (nconc result (list full-file))))) + (when (string-match regexp file) + (push (concat dir "/" file) files))))) + (nconc result (nreverse files)))) + ;;; Obsolete aliases (remove after next major release) +(define-obsolete-function-alias + 'org-roam-dailies-find-today + 'org-roam-dailies-goto-today "org-roam 2.0") +(define-obsolete-function-alias + 'org-roam-dailies-find-yesterday + 'org-roam-dailies-goto-yesterday "org-roam 2.0") +(define-obsolete-function-alias + 'org-roam-dailies-find-tomorrow + 'org-roam-dailies-goto-tomorrow "org-roam 2.0") +(define-obsolete-function-alias + 'org-roam-dailies-find-next-note + 'org-roam-dailies-goto-next-note "org-roam 2.0") +(define-obsolete-function-alias + 'org-roam-dailies-find-previous-note + 'org-roam-dailies-goto-previous-note "org-roam 2.0") +(define-obsolete-function-alias + 'org-roam-dailies-find-date + 'org-roam-dailies-goto-date "org-roam 2.0") + ;;; Obsolete functions (provide 'org-roam-compat) diff --git a/org-roam-dailies.el b/org-roam-dailies.el index e5a88df..20fd79f 100644 --- a/org-roam-dailies.el +++ b/org-roam-dailies.el @@ -327,25 +327,6 @@ negative, find note N days in the future." (define-key org-roam-dailies-map (kbd "v") #'org-roam-dailies-capture-date) (define-key org-roam-dailies-map (kbd ".") #'org-roam-dailies-find-directory) -(define-obsolete-function-alias - 'org-roam-dailies-find-today - 'org-roam-dailies-goto-today "org-roam 2.0") -(define-obsolete-function-alias - 'org-roam-dailies-find-yesterday - 'org-roam-dailies-goto-yesterday "org-roam 2.0") -(define-obsolete-function-alias - 'org-roam-dailies-find-tomorrow - 'org-roam-dailies-goto-tomorrow "org-roam 2.0") -(define-obsolete-function-alias - 'org-roam-dailies-find-next-note - 'org-roam-dailies-goto-next-note "org-roam 2.0") -(define-obsolete-function-alias - 'org-roam-dailies-find-previous-note - 'org-roam-dailies-goto-previous-note "org-roam 2.0") -(define-obsolete-function-alias - 'org-roam-dailies-find-date - 'org-roam-dailies-goto-date "org-roam 2.0") - (provide 'org-roam-dailies) ;;; org-roam-dailies.el ends here diff --git a/org-roam.el b/org-roam.el index 94eeae2..5be71e9 100644 --- a/org-roam.el +++ b/org-roam.el @@ -216,67 +216,6 @@ E.g. (\".org\") => (\"*.org\" \"*.org.gpg\")" (command (s-join " " `(,executable "-L" ,dir "-type f \\(" ,names "\\)")))) (org-roam--shell-command-files command))) -;; Emacs 26 does not have FOLLOW-SYMLINKS in `directory-files-recursively' -(defun org-roam--directory-files-recursively (dir regexp - &optional include-directories predicate - follow-symlinks) - "Return list of all files under directory DIR whose names match REGEXP. -This function works recursively. Files are returned in \"depth -first\" order, and files from each directory are sorted in -alphabetical order. Each file name appears in the returned list -in its absolute form. - -By default, the returned list excludes directories, but if -optional argument INCLUDE-DIRECTORIES is non-nil, they are -included. - -PREDICATE can be either nil (which means that all subdirectories -of DIR are descended into), t (which means that subdirectories that -can't be read are ignored), or a function (which is called with -the name of each subdirectory, and should return non-nil if the -subdirectory is to be descended into). - -If FOLLOW-SYMLINKS is non-nil, symbolic links that point to -directories are followed. Note that this can lead to infinite -recursion." - (let* ((result nil) - (files nil) - (dir (directory-file-name dir)) - ;; When DIR is "/", remote file names like "/method:" could - ;; also be offered. We shall suppress them. - (tramp-mode (and tramp-mode (file-remote-p (expand-file-name dir))))) - (dolist (file (sort (file-name-all-completions "" dir) - 'string<)) - (unless (member file '("./" "../")) - (if (directory-name-p file) - (let* ((leaf (substring file 0 (1- (length file)))) - (full-file (concat dir "/" leaf))) - ;; Don't follow symlinks to other directories. - (when (and (or (not (file-symlink-p full-file)) - (and (file-symlink-p full-file) - follow-symlinks)) - ;; Allow filtering subdirectories. - (or (eq predicate nil) - (eq predicate t) - (funcall predicate full-file))) - (let ((sub-files - (if (eq predicate t) - (condition-case nil - (org-roam--directory-files-recursively - full-file regexp include-directories - predicate follow-symlinks) - (file-error nil)) - (org-roam--directory-files-recursively - full-file regexp include-directories - predicate follow-symlinks)))) - (setq result (nconc result sub-files)))) - (when (and include-directories - (string-match regexp leaf)) - (setq result (nconc result (list full-file))))) - (when (string-match regexp file) - (push (concat dir "/" file) files))))) - (nconc result (nreverse files)))) - (defun org-roam--list-files-elisp (dir) "Return all Org-roam files located recursively within DIR, using elisp." (let ((regex (concat "\\.\\(?:"(mapconcat