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

Fix recursive directories #841

Merged
merged 6 commits into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions citar-file.el
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,16 @@ whether entries have associated files."
(when citar-file-variable
(lambda (citekey) (and (citar-get-value citar-file-variable citekey) t))))

(defun citar--library-dirs ()
(defun citar-file--library-dirs ()
"Return all directories to be searched for library files."
(mapcar (lambda (dir)
(cons dir (when citar-library-paths-recursive
(directory-files-recursively dir "" :include-directories
#'file-directory-p))))
citar-library-paths))
(apply #'append
(mapcar (lambda (dir)
(cons dir
(when citar-library-paths-recursive
(seq-filter #'file-directory-p
(directory-files-recursively dir ""
:include-directories)))))
citar-library-paths)))

(defun citar-file--get-from-file-field (&optional keys)
"Return files for KEYS by parsing the `citar-file-variable' field.
Expand All @@ -200,7 +203,7 @@ files associated with KEYS."
(when-let ((filefield citar-file-variable))
(citar--check-configuration 'citar-library-paths 'citar-library-file-extensions
'citar-file-parser-functions)
(let ((dirs (append (citar--library-dirs)
(let ((dirs (append (citar-file--library-dirs)
(mapcar #'file-name-directory (citar--bibliography-files)))))
(citar--get-resources-using-function
(lambda (citekey entry)
Expand All @@ -221,7 +224,7 @@ files associated with KEYS."
"Return list of files for KEYS in ENTRIES."
(citar--check-configuration 'citar-library-paths 'citar-library-file-extensions)
(citar-file--directory-files
citar-library-paths keys citar-library-file-extensions
(citar-file--library-dirs) keys citar-library-file-extensions
citar-file-additional-files-separator))

(defun citar-file--make-filename-regexp (keys extensions &optional additional-sep)
Expand Down
7 changes: 4 additions & 3 deletions citar.el
Original file line number Diff line number Diff line change
Expand Up @@ -1352,9 +1352,10 @@ it.

SOURCE-PLIST must be as specified in the documentation of
`citar-add-file-sources'."
(let* ((directory (if (cdr citar-library-paths)
(completing-read "Directory: " citar-library-paths)
(car citar-library-paths)))
(let* ((dirs (citar-file--library-dirs))
(directory (if (cdr dirs)
(completing-read "Directory: " dirs)
(car dirs)))
(extension (or (plist-get source-plist :extension)
(read-string "File extension: ")))
(destfile (expand-file-name citekey directory))
Expand Down
Loading