Function: bibtex-initialize
bibtex-initialize is an autoloaded, interactive and byte-compiled
function defined in bibtex.el.gz.
Signature
(bibtex-initialize &optional CURRENT FORCE SELECT)
Documentation
(Re)Initialize BibTeX buffers.
Visit the BibTeX files defined by bibtex-files and return a list
of corresponding buffers.
Initialize in these buffers bibtex-reference-keys if not yet set.
List of BibTeX buffers includes current buffer if CURRENT is non-nil
and the current buffer visits a file using bibtex-mode.
If FORCE is non-nil, (re)initialize bibtex-reference-keys even if
already set. If SELECT is non-nil interactively select a BibTeX buffer.
When called interactively, FORCE is t, CURRENT is t if current buffer
visits a file using bibtex-mode, and SELECT is t if current buffer
does not use bibtex-mode.
Probably introduced at or before Emacs version 23.1.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/textmodes/bibtex.el.gz
;;;###autoload
(defun bibtex-initialize (&optional current force select)
"(Re)Initialize BibTeX buffers.
Visit the BibTeX files defined by `bibtex-files' and return a list
of corresponding buffers.
Initialize in these buffers `bibtex-reference-keys' if not yet set.
List of BibTeX buffers includes current buffer if CURRENT is non-nil
and the current buffer visits a file using `bibtex-mode'.
If FORCE is non-nil, (re)initialize `bibtex-reference-keys' even if
already set. If SELECT is non-nil interactively select a BibTeX buffer.
When called interactively, FORCE is t, CURRENT is t if current buffer
visits a file using `bibtex-mode', and SELECT is t if current buffer
does not use `bibtex-mode'."
;; Interactively, exclude current buffer if it does not visit a file
;; using `bibtex-mode'. This way, we exclude BibTeX buffers such as
;; `bibtex-search-buffer' that are not visiting a BibTeX file.
;; Also, calling `bibtex-initialize' gives meaningful results for any
;; current buffer.
(interactive (list (eq major-mode 'bibtex-mode)
(and buffer-file-name (eq major-mode 'bibtex-mode))
(not (eq major-mode 'bibtex-mode))))
(let ((file-path
(or (if (stringp bibtex-file-path) ; obsolete format
(save-match-data
(split-string bibtex-file-path ":+" t))
bibtex-file-path)
(list default-directory)))
file-list dir-list buffer-list)
;; generate list of BibTeX files
(dolist (file bibtex-files)
(cond ((eq file 'bibtex-file-path)
(setq dir-list (append dir-list file-path)))
((file-accessible-directory-p file)
(push file dir-list))
((progn (unless (string= "bib" (file-name-extension file))
(setq file (file-name-with-extension file "bib")))
(file-name-absolute-p file))
(push file file-list))
(t
(let (expanded-file-name found)
(dolist (dir file-path)
;; filename may exist in multiple directories
(when (file-readable-p
(setq expanded-file-name (expand-file-name file dir)))
(push expanded-file-name file-list)
(setq found t)))
(unless found
(user-error "File `%s' not in bibtex-file-path" file))))))
(dolist (file file-list)
(unless (file-readable-p file)
(user-error "BibTeX file `%s' not found" file)))
;; expand dir-list
(dolist (dir dir-list)
(setq file-list
(append file-list (directory-files dir t "\\.bib\\'" t))))
(delete-dups file-list)
;; visit files in FILE-LIST
(dolist (file file-list)
(if (file-readable-p file)
(push (find-file-noselect file) buffer-list)))
;; Include current buffer iff we want it.
(cond ((and current (not (memq (current-buffer) buffer-list)))
(push (current-buffer) buffer-list))
((and (not current) (memq (current-buffer) buffer-list))
(setq buffer-list (delq (current-buffer) buffer-list))))
;; parse keys
(let (string-init)
(dolist (buffer buffer-list)
(with-current-buffer buffer
;; `bibtex-reference-keys' and `bibtex-strings' are buffer-local
;; lazy completion tables. So we only initiate them as needed.
(if (or force (functionp bibtex-reference-keys))
(bibtex-parse-keys))
(when (or force (functionp bibtex-strings))
(unless string-init (setq string-init (bibtex-string-files-init)))
(bibtex-parse-strings string-init)))))
;; select BibTeX buffer
(if select
(if buffer-list
(switch-to-buffer
(completing-read "Switch to BibTeX buffer: "
(mapcar #'buffer-name buffer-list)
nil t
(if current (buffer-name (current-buffer)))))
(message "No BibTeX buffers defined")))
buffer-list))