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

Feature request: Allow citar to add multiple files to library item/citeky via citar-add-file-to-library #821

Open
deen1 opened this issue Mar 1, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@deen1
Copy link

deen1 commented Mar 1, 2024

While setting the citar-file-additional-files-separator variable to non-nil allows a library item to have multiple associated files under the same cite-key -- e.g. {cite-key}_{cite-year}.pdf, {cite-key}_{cite-year}-1.pdf, {cite-key}_{cite-year}-2.pdf -- it is currently only possible to add an additional file to an item only by renaming the file and moving it to the directory manually. Otherwise, running M-x citar-add-file-to-library will produce the File ... exists, overwrite? (y or n) prompt in the minibuffer, and answering will either overwrite the existing file (y) or cancel the operation (n).

Via @bdarcus in #820 (comment)_, the following code needs to change:

citar/citar.el

Lines 1337 to 1360 in 885b86f

(defun citar-save-file-to-library (citekey source-plist)
"Use as `citar-add-file-function' to save files to `citar-library-paths'.
Save the file with the filename CITEKEY.EXTENSION to a directory
from `citar-library-paths'. If there are multiple such
directories, prompt the user to choose one. If SOURCE-PLIST has
an :extension key, use its value as EXTENSION; otherwise prompt
the user. If the file already exists, confirm before overwriting
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)))
(extension (or (plist-get source-plist :extension)
(read-string "File extension: ")))
(destfile (expand-file-name citekey directory))
(destfile (if (string-empty-p extension)
destfile
(concat destfile "." extension)))
;; an integer means to confirm before overwriting
(ok-if-already-exists 1))
(funcall (plist-get source-plist :write-file)

I would say that

 (destfile (expand-file-name citekey directory)) 
          (destfile (if (string-empty-p extension) 
                        destfile 
                      (concat destfile "." extension))) 
          ;; an integer means to confirm before overwriting 
          (ok-if-already-exists 1)

needs to change to prompt the user to either overwrite the existing file (y), or add the new file with an appended filename (a), or cancel (c/q/n).

If the user chooses to add with an appended filename, then citar should check if the -1, -2 ... -n. versions of the filename are in use, before adding the file with filename {cite_key}_{cite_year}-{n+1}.ext.

@bdarcus bdarcus added the enhancement New feature or request label Mar 1, 2024
@bdarcus
Copy link
Contributor

bdarcus commented Mar 3, 2024

... needs to change to prompt the user to either overwrite the existing file (y), or add the new file with an appended filename (a), or cancel (c/q/n).

If the user chooses to add with an appended filename, then citar should check if the -1, -2 ... -n. versions of the filename are in use, before adding the file with filename {cite_key}_{cite_year}-{n+1}.ext.

This makes sense to me, so suggest whoever gets to this start here.

The only amendment I would make is this should only work like this if the file separator variable is set.

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

No branches or pull requests

2 participants