ebib icon indicating copy to clipboard operation
ebib copied to clipboard

File not found error

Open LorenRiccie opened this issue 5 years ago • 6 comments

Dear Joost,

I can’t figure out how to open with Ebib pdf attachments from Jabref (Ebib gives me a "file not found error" feedback). Ebib, correct me if I’m wrong, seems not use the same file name convention. Jabref file’s field format looks like this: file = {:Raby1995.pdf:PDF},  I would like not to change this format as I still want to use Jabref outside emacs.

I saw the problem discussed here (https://forums.zotero.org/discussion/38209/problem-with-export-to-bibtex) but i could not understand how some contributors were able to fix it.

NB. Here is, for information, my ebib configuration in emacs-mac 26.191

(use-package ebib :ensure t :config (setq ebib-index-columns (quote( ("Entry Key" 20 t) ("Author/Editor" 20 nil) ("Year" 6 t) ("Title" 40 t) ("keywords" 20 t)))) (setq ebib-bibtex-dialect 'biblatex) (setq ebib-preload-bib-files '("PATH“)) (setq ebib-file-search-dirs '("PATH“)) (setq ebib-use-timestamp t) (setq ebib-timestamp-format "%d.%m.%Y"))

Thank you very much

LorenRiccie avatar Jan 22 '19 21:01 LorenRiccie

Yes, Ebib does not use the same format for the file field as JabRef. The solution that people talk about on the page you link to seems to be to patch the Ebib source files. This isn't necessary, however: it's possible to add support for JabRef's file field format without patching Ebib. Unfortunately, it does require writing a bit of Elisp.

There is a customisation option ebib-file-name-mod-function that can be used for this purpose. It should be set to a function that can extract the actual file name from the contents of the file field (and can also do the reverse: convert a file path to the format that is used in the file field). Additionally, you'd need to set the option ebib-filename-separator to an appropriate value.

If all your file fields have the same form that you describe, i.e., ":Raby1995.pdf:PDF", then you should be able to get by if you add the following function to your init file:

  "Modify FILE for JabRef."
  (if direction
      ;; Modify for storing FILE in the file field.
      (concat ":" file ":PDF")
    ;; Undo modifications so FILE can be passed to an external viewer 
    (let ((data (split-string file ":")))
      (if (= (length data) 1)
          (car data)
        (cl-second data)))))

In addition, you need to add the following two lines to the :config section of your use-package declaration:

(setq ebib-file-name-mod-function 'my-ebib-file-name-transform)
(setq ebib-filename-separator ";")

This should get you going, though I haven't tested it much and I assume that every file field has the same format. If you run into problems, feel free to let me know.

I think it would actually be a good idea to add support for the JabRef format to Ebib. That will take a bit longer, though, but when I do, I'll post here to let you know.

joostkremers avatar Jan 23 '19 09:01 joostkremers

Unfortunately an error occurred with the lisp code: “Warning (initialization): An error occurred while loading ‘/Users/***/.emacs.d/init.el’: Symbol's value as variable is void: direction

Here is the backtrace result: Debugger entered--Lisp error: (void-variable direction) (if direction (concat ":" file ":PDF") (let ((data (split-string file ":"))) (if (= (length data) 1) (car data) (car (cdr data)))))

LorenRiccie avatar Jan 23 '19 19:01 LorenRiccie

Sorry, that's because the first line of the code snippet is missing. It should be:

(defun my-ebib-file-name-transform (file direction)
  "Modify FILE for JabRef."
  (if direction
      ;; Modify for storing FILE in the file field.
      (concat ":" file ":PDF")
    ;; Undo modifications so FILE can be passed to an external viewer.
    (let ((data (split-string file ":")))
      (if (= (length data) 1)
          (car data)
        (cl-second data)))))

I hope it works now.

joostkremers avatar Jan 23 '19 19:01 joostkremers

Yes, It does! 🙏🙏🙏

LorenRiccie avatar Jan 23 '19 20:01 LorenRiccie

Great! :tada:

I'll keep this issue open because I would like to improve support for JabRef-style file fields, but I first need to figure out what exactly JabRef allows and does not allow. Once I have added something to Ebib, I'll will post here to let you know.

joostkremers avatar Jan 23 '19 20:01 joostkremers

I'd like also suggest an enhencement of the ebib--expand-file-name:

(defun ebib--expand-file-name (file)
  "Search and expand FILE.
FILE is a file name, possibly with a partial file path.  It is
expanded relative to `ebib-file-search-dirs'.  If the file cannot
be found, the non-directory part is searched for as well.  As a
last resort, FILE is expanded relative to `default-directory'.
If FILE is an absolute file name, expand it with
`expand-file-name' and return the result."
  (if (file-name-absolute-p file)
      (expand-file-name file)
    (let* ((unmod-file (funcall ebib-file-name-mod-function file nil))
           (ebib-file-search-dirs (append ebib-file-search-dirs `(,(file-name-directory (ebib-db-get-filename ebib--cur-db)))))
           )
      (or (locate-file unmod-file ebib-file-search-dirs)
          (locate-file (file-name-nondirectory unmod-file) ebib-file-search-dirs)
          (locate-file unmod-file '((file-name-directory (ebib-db-get-filename ebib--cur-db))))
          (expand-file-name unmod-file)))))

The (ebib-file-search-dirs (append ebib-file-search-dirs (,(file-name-directory (ebib-db-get-filename ebib--cur-db)))))` add the the bib file location to the ebib-file-search-dirs temporally. It can help exploring any bib file in dired mode and no need to set ebib-file-search-dirs.

ShuguangSun avatar Apr 13 '19 07:04 ShuguangSun