emacs-citar / citar

Emacs package to quickly find and act on bibliographic references, and edit org, markdown, and latex academic documents.
GNU General Public License v3.0
479 stars 53 forks source link

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

Open deen1 opened 4 months ago

deen1 commented 4 months ago

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 https://github.com/emacs-citar/citar/discussions/820#discussioncomment-8635275_, the following code needs to change:

https://github.com/emacs-citar/citar/blob/885b86f6733fd70f42c32dd7791d3447f93db990/citar.el#L1337-L1360

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 commented 4 months ago

... 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.