Function: bibtex-field-re-init

bibtex-field-re-init is a byte-compiled function defined in bibtex.el.gz.

Signature

(bibtex-field-re-init REGEXP-ALIST TYPE)

Documentation

Calculate optimized value for bibtex-regexp-TYPE-opt.

This value is based on bibtex-regexp-TYPE-alist. TYPE is braces or strings. Return optimized value to be used by bibtex-format-entry.

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/bibtex.el.gz
(defun bibtex-field-re-init (regexp-alist type)
  "Calculate optimized value for bibtex-regexp-TYPE-opt.
This value is based on bibtex-regexp-TYPE-alist.  TYPE is `braces' or `strings'.
Return optimized value to be used by `bibtex-format-entry'."
  (setq regexp-alist
        (mapcar (lambda (e)
                  (list (car e)
                        (replace-regexp-in-string " +" "[ \t\n]+" (nth 1 e))
                        (nth 2 e))) ; nil for 'braces'.
                regexp-alist))
  (let (opt-list)
    ;; Loop over field names
    (dolist (field (delete-dups (apply #'append (mapcar #'car regexp-alist))))
      (let (rules)
        ;; Collect all matches we have for this field name
        (dolist (e regexp-alist)
          (if (assoc-string field (car e) t)
              (push (cons (nth 1 e) (nth 2 e)) rules)))
        (if (eq type 'braces)
            ;; concatenate all regexps to a single regexp
            (setq rules (concat "\\(?:" (mapconcat #'car rules "\\|") "\\)")))
        ;; create list of replacement rules.
        (push (cons field rules) opt-list)))
    opt-list))