joostkremers / ebib

A BibTeX database manager for Emacs.
https://joostkremers.github.io/ebib/
BSD 3-Clause "New" or "Revised" License
272 stars 37 forks source link

ebib-import-file target directory #295

Closed scfrank-pri closed 2 months ago

scfrank-pri commented 3 months ago

When importing files from e.g. ~/Downloads, they are renamed according to the bibkey (which is great) and then moved to ??? I experienced that, no matter what I tried, they will be always moved to the first dir listed for ebib-file-search-directories which is ~/path/to/Biology in my case. Intuitively, I had expected they are moved to the directory where the bib file is found, e.g. chemistry.bib leads to ~/path/to/Chemistry. The different options for ebib-link-file-path-type: 'relative etc. did not make any difference for me. My workaround is to first change ebib-file-search-directories and then import files. But that is not convenient and probably also not intended. Can this be fixed? Thanks

joostkremers commented 3 months ago

Yes, unfortunately this is hard-coded. :slightly_frowning_face: You can customise the file name to which the imported file is saved, and you can actually include a directory part in the generated file name, but that would still be relative to the first directory in ebib-file-search-dirs.

ebib-link-file-path-type applies to creating Org links, so it's not relevant to importing files.

You could make your work-around a bit more convenient by wrapping it in a function that determines the target directory (based on the current database, or on user input if you prefer), let-binds ebib-file-search-directories and then calls ebib-import-file.

For a more permanent solution, I'd need to consider the different preferences users might have. The most straightfordward way would probably be to give ebib-file-search-dirs more options.

scfrank-pri commented 3 months ago

Thanks - I'll use the workaround.

fschweitzer-ETHZ commented 2 months ago

This is our workaround solution:

(defun ebib-import-to-current-bib-dir ()
    "Import a file directly into the directory of the current bib file in ebib."
    (interactive)
    (let* ((current-bib-dir (file-name-directory (ebib-db-get-filename ebib--cur-db)))  ; Retrieve the directory of the current bib file
           (ebib-file-search-dirs (list current-bib-dir)))  ; Temporarily set search dirs to current bib directory
      (ebib-import-file nil)  ; ebib-import-file should prompt for the file internally
      (message "Import initiated for directory: %s" current-bib-dir)))  ; Notify the user
joostkremers commented 2 months ago

I've added a new user option ebib-import-target-directory, which should handle this in a more elegant manner. By default, it points to the first directory in ebib-file-search-dirs, but it has a few other options, one of which is to use the same directory as the .bib file into which the file is being imported.

Let me know if any issues pop up, or if something more is needed.