4

When i ran the following code in just started emacs

(with-temp-buffer
  (insert "@article{aaaa,
    author =     {AAA},
    title =  {BBBB}
    }")
  (bibtex-mode)
  (bibtex-autokey-get-field "title"))

I get the following error:

  Debugger entered--Lisp error: (wrong-type-argument stringp nil)
    looking-at(nil)
    bibtex-valid-entry(t)
    bibtex-end-of-entry()
    bibtex-text-in-field("title" t)
    bibtex-autokey-get-field("title")
    (progn (insert "@article{aaaa,\n    author =     {AAA},\n    title =  {BBBB}\n    }") (bibtex-mode) (bibtex-autokey-get-field "title"))
    (unwind-protect (progn (insert "@article{aaaa,\n    author =     {AAA},\n    title =  {BBBB}\n    }") (bibtex-mode) (bibtex-autokey-get-field "title")) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))
    (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (insert "@article{aaaa,\n    author =     {AAA},\n    title =  {BBBB}\n    }") (bibtex-mode) (bibtex-autokey-get-field "title")) (and (buffer-name temp-buffer) (kill-buffer temp-buffer))))
    (let ((temp-buffer (generate-new-buffer " *temp*"))) (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (insert "@article{aaaa,\n    author =     {AAA},\n    title =  {BBBB}\n    }")       (bibtex-mode) (bibtex-autokey-get-field "title")) (and (buffer-name temp-buffer) (kill-buffer temp-buffer)))))
    eval((let ((temp-buffer (generate-new-buffer " *temp*"))) (save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn (insert "@article{aaaa,\n    author =     {AAA},\n    title =  {BBBB}\n    }") (bibtex-mode) (bibtex-autokey-get-field "title")) (and (buffer-name temp-buffer) (kill-buffer temp-buffer))))) nil)
    elisp--eval-last-sexp(t)
    eval-last-sexp(t)
    eval-print-last-sexp(nil)
    funcall-interactively(eval-print-last-sexp nil)
    call-interactively(eval-print-last-sexp nil nil)
    command-execute(eval-print-last-sexp)

After i open any bibtex file the above code works as expected. (I get "BBBB")

If it is important i initialize the bibtex with the following:

  (use-package bibtex
    :mode ("\\.bib" . bibtex-mode)
    )

Could you help me to find the problem

  • Please explain how it "doesn't work" and what you do exactly to try and run that code (and not just "similar" code). Also I don't understand what your use-package call is for: Emacs's default config will already use bibtex-mode for files with the .bib extension. – Stefan Dec 19 '18 at 21:29
  • Thanks for you comment, i rewrote the question – RCV Dec 19 '18 at 22:07
3

It's a bug in bibtex.el which only initializes some of its global vars after opening a file. Please M-x report-emacs-bug.

While waiting for an actual fix, you can use the following workaround: add a call of the form (bibtex-set-dialect) some time after calling bibtex-mode.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.