Mercurial > emacs
comparison lisp/textmodes/bibtex.el @ 55880:1b2cb608f18e
(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.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Tue, 01 Jun 2004 23:31:00 +0000 |
parents | b4eeb441c089 |
children | 0b058857c704 4c90ffeb71c5 |
comparison
equal
deleted
inserted
replaced
55879:7fd80a9c338d | 55880:1b2cb608f18e |
---|---|
1791 ;; determine if entry has crossref field and if at least | 1791 ;; determine if entry has crossref field and if at least |
1792 ;; one alternative is non-empty | 1792 ;; one alternative is non-empty |
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 |
1800 (cdr field))) | 1800 (cdr field))) |
1801 (cdr field)) | 1801 (cdr field)) |
1805 | 1805 |
1806 (dolist (rfield req-field-list) | 1806 (dolist (rfield req-field-list) |
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 |
1814 (cdr field)))) | 1814 (cdr field)))) |
1815 (cond ((not non-empty-alternative) | 1815 (cond ((not non-empty-alternative) |
2315 (if (and abortable | 2315 (if (and abortable |
2316 (input-pending-p)) | 2316 (input-pending-p)) |
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))) |
2324 ;; successful operation --> return `bibtex-strings' | 2324 ;; successful operation --> return `bibtex-strings' |
2325 (setq bibtex-strings strings)))))) | 2325 (setq bibtex-strings strings)))))) |
2720 ;; For inserting new fields, we use the fact that | 2720 ;; For inserting new fields, we use the fact that |
2721 ;; bibtex-parse-entry moves point to the end of the last field. | 2721 ;; bibtex-parse-entry moves point to the end of the last field. |
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. |
2735 The alist elements have the form (FIELD . TEXT), where FIELD can also be | 2738 The alist elements have the form (FIELD . TEXT), where FIELD can also be |
2736 the special strings \"=type=\" and \"=key=\". | 2739 the special strings \"=type=\" and \"=key=\". For the FIELD \"=key=\" |
2737 Move point to the end of the last field." | 2740 TEXT 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)) |
2746 alist) | 2749 alist) |
2747 (goto-char (bibtex-end-of-field bounds)))) | 2750 (goto-char (bibtex-end-of-field bounds)))) |