Function: bibtex-string-files-init

bibtex-string-files-init is a byte-compiled function defined in bibtex.el.gz.

Signature

(bibtex-string-files-init)

Documentation

Return initialization for bibtex-strings(var)/bibtex-strings(fun).

Use bibtex-predefined-strings and BibTeX files bibtex-string-files with bibtex-string-file-path.

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/bibtex.el.gz
(defun bibtex-string-files-init ()
  "Return initialization for `bibtex-strings'.
Use `bibtex-predefined-strings' and BibTeX files `bibtex-string-files'
with `bibtex-string-file-path'."
  (let ((dirlist
         (or (if (stringp bibtex-string-file-path) ; obsolete format
                 (save-match-data
                   (split-string bibtex-string-file-path ":+" t))
               bibtex-string-file-path)
             (list default-directory)))
        string-files)
    ;; collect absolute file names of valid string files
    (dolist (filename bibtex-string-files)
      (unless (string= "bib" (file-name-extension filename))
        (setq filename (file-name-with-extension filename "bib")))
      ;; test filenames
      (if (file-name-absolute-p filename)
          (if (file-readable-p filename)
              (push filename string-files)
            (user-error "BibTeX strings file %s not found" filename))
        (let (found)
          (dolist (dir dirlist)
            ;; filename may exist in multiple directories
            (let ((fullfilename (expand-file-name filename dir)))
              (when (file-readable-p fullfilename)
                (push fullfilename string-files)
                (setq found t))))
          (unless found
            (user-error "File %s not in bibtex-string-file-path" filename)))))
    ;; parse string files
    (let (compl bounds)
      (dolist (filename string-files)
        (with-temp-buffer
          (insert-file-contents filename)
          (goto-char (point-min))
          (while (setq bounds (bibtex-search-forward-string))
            (push (cons (bibtex-reference-key-in-string bounds)
                        (bibtex-text-in-string bounds t))
                  compl)
            (goto-char (bibtex-end-of-string bounds)))))
      (append bibtex-predefined-strings (nreverse compl)))))