Subject: bug#33810: 26.1.50; bibtex initializes some global vars after opening a file

From: Konstantin Reich <[email-masked]>
Date: Thu, 20 Dec 2018 12:01:23 +0300

Hey, i am using emacs 26.1.50

When i ran the following code in just started emacs -Q
(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")

Also everything works if I add  (bibtex-set-dialect) after    (bibtex-mode). In (https://emacs.stackexchange.com/questions/46691/package-initialization/46693#46693) I was told that it is some kind of bug due to bibtex initializes some  global vars only after opening a file.