aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2004-06-01 23:31:00 +0000
committerStefan Monnier2004-06-01 23:31:00 +0000
commitcb75af7678a5781f838e47a8c562fcb356d66cf2 (patch)
tree409376caacd8cc868caffe503d40a0e53718a320
parent2b47b74d0c65aec3fa71301ee92ca8274af99959 (diff)
downloademacs-cb75af7678a5781f838e47a8c562fcb356d66cf2.tar.gz
emacs-cb75af7678a5781f838e47a8c562fcb356d66cf2.zip
(bibtex-format-entry): Fix regexps.
(bibtex-parse-strings): Bugfix, use assoc instead of assoc-string. (bibtex-entry-update): Handle alternatives and optional fields. (bibtex-parse-entry): Bugfix, handle empty key.
-rw-r--r--lisp/textmodes/bibtex.el23
1 files changed, 13 insertions, 10 deletions
diff --git a/lisp/textmodes/bibtex.el b/lisp/textmodes/bibtex.el
index 99e693abb94..15348205c51 100644
--- a/lisp/textmodes/bibtex.el
+++ b/lisp/textmodes/bibtex.el
@@ -1793,7 +1793,7 @@ Formats current entry according to variable `bibtex-entry-format'."
1793 (goto-char (point-min)) 1793 (goto-char (point-min))
1794 (let* ((fields-alist (bibtex-parse-entry)) 1794 (let* ((fields-alist (bibtex-parse-entry))
1795 (case-fold-search t) 1795 (case-fold-search t)
1796 (field (bibtex-assoc-regexp "\\(OPT\\)?crossref\\>" 1796 (field (bibtex-assoc-regexp "\\`\\(OPT\\)?crossref\\'"
1797 fields-alist))) 1797 fields-alist)))
1798 (setq crossref-key (and field 1798 (setq crossref-key (and field
1799 (not (string-match bibtex-empty-field-re 1799 (not (string-match bibtex-empty-field-re
@@ -1807,7 +1807,7 @@ Formats current entry according to variable `bibtex-entry-format'."
1807 (when (nth 3 rfield) ; we should have an alternative 1807 (when (nth 3 rfield) ; we should have an alternative
1808 (setq alternatives-there t 1808 (setq alternatives-there t
1809 field (bibtex-assoc-regexp 1809 field (bibtex-assoc-regexp
1810 (concat "\\(ALT\\)?" (car rfield) "\\>") 1810 (concat "\\`\\(ALT\\)?" (car rfield) "\\'")
1811 fields-alist)) 1811 fields-alist))
1812 (if (and field 1812 (if (and field
1813 (not (string-match bibtex-empty-field-re 1813 (not (string-match bibtex-empty-field-re
@@ -2317,7 +2317,7 @@ Return alist of strings if parsing was completed, `aborted' otherwise."
2317 ;; user has aborted by typing a key --> return `aborted' 2317 ;; user has aborted by typing a key --> return `aborted'
2318 (throw 'userkey 'aborted)) 2318 (throw 'userkey 'aborted))
2319 (setq key (bibtex-reference-key-in-string bounds)) 2319 (setq key (bibtex-reference-key-in-string bounds))
2320 (if (not (assoc-string key strings t)) 2320 (if (not (assoc key strings))
2321 (push (cons key (bibtex-text-in-string bounds t)) 2321 (push (cons key (bibtex-text-in-string bounds t))
2322 strings)) 2322 strings))
2323 (goto-char (bibtex-end-of-text-in-string bounds))) 2323 (goto-char (bibtex-end-of-text-in-string bounds)))
@@ -2722,24 +2722,27 @@ according to `bibtex-entry-field-alist', but are not yet present."
2722 (let* ((fields-alist (bibtex-parse-entry)) 2722 (let* ((fields-alist (bibtex-parse-entry))
2723 (field-list (bibtex-field-list 2723 (field-list (bibtex-field-list
2724 (substring (cdr (assoc "=type=" fields-alist)) 2724 (substring (cdr (assoc "=type=" fields-alist))
2725 1)))) ; don't want @ 2725 1))) ; don't want @
2726 (case-fold-search t))
2726 (dolist (field (car field-list)) 2727 (dolist (field (car field-list))
2727 (unless (assoc-string (car field) fields-alist t) 2728 (unless (bibtex-assoc-regexp (concat "\\`\\(ALT\\)?" (car field) "\\'")
2729 fields-alist)
2728 (bibtex-make-field field))) 2730 (bibtex-make-field field)))
2729 (dolist (field (cdr field-list)) 2731 (dolist (field (cdr field-list))
2730 (unless (assoc-string (car field) fields-alist t) 2732 (unless (bibtex-assoc-regexp (concat "\\`\\(OPT\\)?" (car field) "\\'")
2733 fields-alist)
2731 (bibtex-make-optional-field field)))))) 2734 (bibtex-make-optional-field field))))))
2732 2735
2733(defun bibtex-parse-entry () 2736(defun bibtex-parse-entry ()
2734 "Parse entry at point, return an alist. 2737 "Parse entry at point, return an alist.
2735The alist elements have the form (FIELD . TEXT), where FIELD can also be 2738The alist elements have the form (FIELD . TEXT), where FIELD can also be
2736the special strings \"=type=\" and \"=key=\". 2739the special strings \"=type=\" and \"=key=\". For the FIELD \"=key=\"
2737Move point to the end of the last field." 2740TEXT may be nil. Move point to the end of the last field."
2738 (let (alist bounds) 2741 (let (alist bounds)
2739 (when (looking-at bibtex-entry-head) 2742 (when (looking-at bibtex-entry-maybe-empty-head)
2740 (push (cons "=type=" (match-string bibtex-type-in-head)) alist) 2743 (push (cons "=type=" (match-string bibtex-type-in-head)) alist)
2741 (push (cons "=key=" (match-string bibtex-key-in-head)) alist) 2744 (push (cons "=key=" (match-string bibtex-key-in-head)) alist)
2742 (goto-char (match-end bibtex-key-in-head)) 2745 (goto-char (match-end 0))
2743 (while (setq bounds (bibtex-parse-field bibtex-field-name)) 2746 (while (setq bounds (bibtex-parse-field bibtex-field-name))
2744 (push (cons (bibtex-name-in-field bounds) 2747 (push (cons (bibtex-name-in-field bounds)
2745 (bibtex-text-in-field-bounds bounds)) 2748 (bibtex-text-in-field-bounds bounds))