Mercurial > emacs
comparison lisp/textmodes/bibtex.el @ 55730:b4eeb441c089
Use assoc-string, not assoc-ignore-case.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sat, 22 May 2004 21:51:17 +0000 |
parents | c1f70dc19ce5 |
children | 1b2cb608f18e |
comparison
equal
deleted
inserted
replaced
55729:0c0b514a4952 | 55730:b4eeb441c089 |
---|---|
1500 (beg (copy-marker (match-beginning 0))) | 1500 (beg (copy-marker (match-beginning 0))) |
1501 (end (copy-marker (save-excursion (bibtex-end-of-entry))))) | 1501 (end (copy-marker (save-excursion (bibtex-end-of-entry))))) |
1502 (save-excursion | 1502 (save-excursion |
1503 (if (or (and (not bibtex-sort-ignore-string-entries) | 1503 (if (or (and (not bibtex-sort-ignore-string-entries) |
1504 (string-equal "string" (downcase entry-type))) | 1504 (string-equal "string" (downcase entry-type))) |
1505 (assoc-ignore-case entry-type bibtex-entry-field-alist)) | 1505 (assoc-string entry-type bibtex-entry-field-alist t)) |
1506 (funcall fun key beg end))) | 1506 (funcall fun key beg end))) |
1507 (goto-char end))))) | 1507 (goto-char end))))) |
1508 | 1508 |
1509 (defun bibtex-progress-message (&optional flag interval) | 1509 (defun bibtex-progress-message (&optional flag interval) |
1510 "Echo a message about progress of current buffer. | 1510 "Echo a message about progress of current buffer. |
1769 ;; identify entry type | 1769 ;; identify entry type |
1770 (goto-char (point-min)) | 1770 (goto-char (point-min)) |
1771 (re-search-forward bibtex-entry-type) | 1771 (re-search-forward bibtex-entry-type) |
1772 (let ((beg-type (1+ (match-beginning 0))) | 1772 (let ((beg-type (1+ (match-beginning 0))) |
1773 (end-type (match-end 0))) | 1773 (end-type (match-end 0))) |
1774 (setq entry-list (assoc-ignore-case (buffer-substring-no-properties | 1774 (setq entry-list (assoc-string (buffer-substring-no-properties |
1775 beg-type end-type) | 1775 beg-type end-type) |
1776 bibtex-entry-field-alist)) | 1776 bibtex-entry-field-alist |
1777 t)) | |
1777 | 1778 |
1778 ;; unify case of entry name | 1779 ;; unify case of entry name |
1779 (when (memq 'unify-case format) | 1780 (when (memq 'unify-case format) |
1780 (delete-region beg-type end-type) | 1781 (delete-region beg-type end-type) |
1781 (insert (car entry-list))) | 1782 (insert (car entry-list))) |
1844 ;; anyway. So for speed-up we avoid using them. | 1845 ;; anyway. So for speed-up we avoid using them. |
1845 | 1846 |
1846 (if (memq 'opts-or-alts format) | 1847 (if (memq 'opts-or-alts format) |
1847 (cond ((and empty-field | 1848 (cond ((and empty-field |
1848 (or opt-alt | 1849 (or opt-alt |
1849 (let ((field (assoc-ignore-case | 1850 (let ((field (assoc-string |
1850 field-name req-field-list))) | 1851 field-name req-field-list t))) |
1851 (or (not field) ; OPT field | 1852 (or (not field) ; OPT field |
1852 (nth 3 field))))) ; ALT field | 1853 (nth 3 field))))) ; ALT field |
1853 ;; Either it is an empty ALT field. Then we have checked | 1854 ;; Either it is an empty ALT field. Then we have checked |
1854 ;; already that we have one non-empty alternative. Or it | 1855 ;; already that we have one non-empty alternative. Or it |
1855 ;; is an empty OPT field that we do not miss anyway. | 1856 ;; is an empty OPT field that we do not miss anyway. |
1916 (insert booktitle)))) | 1917 (insert booktitle)))) |
1917 | 1918 |
1918 ;; if empty field, complain | 1919 ;; if empty field, complain |
1919 (if (and empty-field | 1920 (if (and empty-field |
1920 (memq 'required-fields format) | 1921 (memq 'required-fields format) |
1921 (assoc-ignore-case field-name req-field-list)) | 1922 (assoc-string field-name req-field-list t)) |
1922 (error "Mandatory field `%s' is empty" field-name)) | 1923 (error "Mandatory field `%s' is empty" field-name)) |
1923 | 1924 |
1924 ;; unify case of field name | 1925 ;; unify case of field name |
1925 (if (memq 'unify-case format) | 1926 (if (memq 'unify-case format) |
1926 (let ((fname (car (assoc-ignore-case | 1927 (let ((fname (car (assoc-string |
1927 field-name (append (nth 0 (nth 1 entry-list)) | 1928 field-name |
1928 (nth 1 (nth 1 entry-list)) | 1929 (append (nth 0 (nth 1 entry-list)) |
1929 bibtex-user-optional-fields))))) | 1930 (nth 1 (nth 1 entry-list)) |
1931 bibtex-user-optional-fields) | |
1932 t)))) | |
1930 (if fname | 1933 (if fname |
1931 (progn | 1934 (progn |
1932 (delete-region beg-name end-name) | 1935 (delete-region beg-name end-name) |
1933 (goto-char beg-name) | 1936 (goto-char beg-name) |
1934 (insert fname)) | 1937 (insert fname)) |
2256 (throw 'userkey 'aborted)) | 2259 (throw 'userkey 'aborted)) |
2257 (let ((key (cond ((match-end 3) | 2260 (let ((key (cond ((match-end 3) |
2258 ;; This is a crossref. | 2261 ;; This is a crossref. |
2259 (buffer-substring-no-properties | 2262 (buffer-substring-no-properties |
2260 (1+ (match-beginning 3)) (1- (match-end 3)))) | 2263 (1+ (match-beginning 3)) (1- (match-end 3)))) |
2261 ((assoc-ignore-case (bibtex-type-in-head) | 2264 ((assoc-string (bibtex-type-in-head) |
2262 bibtex-entry-field-alist) | 2265 bibtex-entry-field-alist t) |
2263 ;; This is an entry. | 2266 ;; This is an entry. |
2264 (match-string-no-properties bibtex-key-in-head))))) | 2267 (match-string-no-properties bibtex-key-in-head))))) |
2265 (if (and (stringp key) | 2268 (if (and (stringp key) |
2266 (not (assoc key reference-keys))) | 2269 (not (assoc key reference-keys))) |
2267 (push (list key) reference-keys))))) | 2270 (push (list key) reference-keys))))) |
2312 (if (and abortable | 2315 (if (and abortable |
2313 (input-pending-p)) | 2316 (input-pending-p)) |
2314 ;; user has aborted by typing a key --> return `aborted' | 2317 ;; user has aborted by typing a key --> return `aborted' |
2315 (throw 'userkey 'aborted)) | 2318 (throw 'userkey 'aborted)) |
2316 (setq key (bibtex-reference-key-in-string bounds)) | 2319 (setq key (bibtex-reference-key-in-string bounds)) |
2317 (if (not (assoc-ignore-case key strings)) | 2320 (if (not (assoc-string key strings t)) |
2318 (push (cons key (bibtex-text-in-string bounds t)) | 2321 (push (cons key (bibtex-text-in-string bounds t)) |
2319 strings)) | 2322 strings)) |
2320 (goto-char (bibtex-end-of-text-in-string bounds))) | 2323 (goto-char (bibtex-end-of-text-in-string bounds))) |
2321 ;; successful operation --> return `bibtex-strings' | 2324 ;; successful operation --> return `bibtex-strings' |
2322 (setq bibtex-strings strings)))))) | 2325 (setq bibtex-strings strings)))))) |
2652 (defun bibtex-field-list (entry-type) | 2655 (defun bibtex-field-list (entry-type) |
2653 "Return list of allowed fields for entry ENTRY-TYPE. | 2656 "Return list of allowed fields for entry ENTRY-TYPE. |
2654 More specifically, the return value is a cons pair (REQUIRED . OPTIONAL), | 2657 More specifically, the return value is a cons pair (REQUIRED . OPTIONAL), |
2655 where REQUIRED and OPTIONAL are lists of the required and optional field | 2658 where REQUIRED and OPTIONAL are lists of the required and optional field |
2656 names for ENTRY-TYPE according to `bibtex-entry-field-alist'." | 2659 names for ENTRY-TYPE according to `bibtex-entry-field-alist'." |
2657 (let ((e (assoc-ignore-case entry-type bibtex-entry-field-alist)) | 2660 (let ((e (assoc-string entry-type bibtex-entry-field-alist t)) |
2658 required optional) | 2661 required optional) |
2659 (unless e | 2662 (unless e |
2660 (error "Bibtex entry type %s not defined" entry-type)) | 2663 (error "Bibtex entry type %s not defined" entry-type)) |
2661 (if (and (member-ignore-case entry-type bibtex-include-OPTcrossref) | 2664 (if (and (member-ignore-case entry-type bibtex-include-OPTcrossref) |
2662 (nth 2 e)) | 2665 (nth 2 e)) |
2719 (let* ((fields-alist (bibtex-parse-entry)) | 2722 (let* ((fields-alist (bibtex-parse-entry)) |
2720 (field-list (bibtex-field-list | 2723 (field-list (bibtex-field-list |
2721 (substring (cdr (assoc "=type=" fields-alist)) | 2724 (substring (cdr (assoc "=type=" fields-alist)) |
2722 1)))) ; don't want @ | 2725 1)))) ; don't want @ |
2723 (dolist (field (car field-list)) | 2726 (dolist (field (car field-list)) |
2724 (unless (assoc-ignore-case (car field) fields-alist) | 2727 (unless (assoc-string (car field) fields-alist t) |
2725 (bibtex-make-field field))) | 2728 (bibtex-make-field field))) |
2726 (dolist (field (cdr field-list)) | 2729 (dolist (field (cdr field-list)) |
2727 (unless (assoc-ignore-case (car field) fields-alist) | 2730 (unless (assoc-string (car field) fields-alist t) |
2728 (bibtex-make-optional-field field)))))) | 2731 (bibtex-make-optional-field field)))))) |
2729 | 2732 |
2730 (defun bibtex-parse-entry () | 2733 (defun bibtex-parse-entry () |
2731 "Parse entry at point, return an alist. | 2734 "Parse entry at point, return an alist. |
2732 The alist elements have the form (FIELD . TEXT), where FIELD can also be | 2735 The alist elements have the form (FIELD . TEXT), where FIELD can also be |
2790 (while (setq bounds (bibtex-parse-field bibtex-field-name)) | 2793 (while (setq bounds (bibtex-parse-field bibtex-field-name)) |
2791 (goto-char (bibtex-start-of-name-in-field bounds)) | 2794 (goto-char (bibtex-start-of-name-in-field bounds)) |
2792 (let* ((name (buffer-substring | 2795 (let* ((name (buffer-substring |
2793 (if (looking-at "ALT\\|OPT") (match-end 0) (point)) | 2796 (if (looking-at "ALT\\|OPT") (match-end 0) (point)) |
2794 (bibtex-end-of-name-in-field bounds))) | 2797 (bibtex-end-of-name-in-field bounds))) |
2795 (text (assoc-ignore-case name other))) | 2798 (text (assoc-string name other t))) |
2796 (goto-char (bibtex-start-of-text-in-field bounds)) | 2799 (goto-char (bibtex-start-of-text-in-field bounds)) |
2797 (if (not (and (looking-at bibtex-empty-field-re) text)) | 2800 (if (not (and (looking-at bibtex-empty-field-re) text)) |
2798 (goto-char (bibtex-end-of-field bounds)) | 2801 (goto-char (bibtex-end-of-field bounds)) |
2799 (delete-region (point) (bibtex-end-of-text-in-field bounds)) | 2802 (delete-region (point) (bibtex-end-of-text-in-field bounds)) |
2800 (insert (cdr text))))) | 2803 (insert (cdr text))))) |
2823 (match-end 0) mb) | 2826 (match-end 0) mb) |
2824 (bibtex-end-of-name-in-field bounds))) | 2827 (bibtex-end-of-name-in-field bounds))) |
2825 (field-list (bibtex-field-list (progn (re-search-backward | 2828 (field-list (bibtex-field-list (progn (re-search-backward |
2826 bibtex-entry-maybe-empty-head nil t) | 2829 bibtex-entry-maybe-empty-head nil t) |
2827 (bibtex-type-in-head)))) | 2830 (bibtex-type-in-head)))) |
2828 (comment (assoc-ignore-case field-name | 2831 (comment (assoc-string field-name |
2829 (append (car field-list) | 2832 (append (car field-list) |
2830 (cdr field-list))))) | 2833 (cdr field-list)) |
2834 t))) | |
2831 (if comment | 2835 (if comment |
2832 (message (nth 1 comment)) | 2836 (message (nth 1 comment)) |
2833 (message "No comment available"))))) | 2837 (message "No comment available"))))) |
2834 | 2838 |
2835 (defun bibtex-make-field (field &optional called-by-yank) | 2839 (defun bibtex-make-field (field &optional called-by-yank) |
3233 (lambda (key beg end) | 3237 (lambda (key beg end) |
3234 (bibtex-progress-message) | 3238 (bibtex-progress-message) |
3235 (let* ((entry-list (progn | 3239 (let* ((entry-list (progn |
3236 (goto-char beg) | 3240 (goto-char beg) |
3237 (bibtex-search-entry nil end) | 3241 (bibtex-search-entry nil end) |
3238 (assoc-ignore-case (bibtex-type-in-head) | 3242 (assoc-string (bibtex-type-in-head) |
3239 bibtex-entry-field-alist))) | 3243 bibtex-entry-field-alist t))) |
3240 (req (copy-sequence (elt (elt entry-list 1) 0))) | 3244 (req (copy-sequence (elt (elt entry-list 1) 0))) |
3241 (creq (copy-sequence (elt (elt entry-list 2) 0))) | 3245 (creq (copy-sequence (elt (elt entry-list 2) 0))) |
3242 crossref-there bounds) | 3246 crossref-there bounds) |
3243 (goto-char beg) | 3247 (goto-char beg) |
3244 (while (setq bounds (bibtex-search-forward-field | 3248 (while (setq bounds (bibtex-search-forward-field |
3250 (not (string-match questionable-month | 3254 (not (string-match questionable-month |
3251 (bibtex-text-in-field-bounds bounds)))) | 3255 (bibtex-text-in-field-bounds bounds)))) |
3252 (push (list (bibtex-current-line) | 3256 (push (list (bibtex-current-line) |
3253 "Questionable month field") | 3257 "Questionable month field") |
3254 error-list)) | 3258 error-list)) |
3255 (setq req (delete (assoc-ignore-case field-name req) req) | 3259 (setq req (delete (assoc-string field-name req t) req) |
3256 creq (delete (assoc-ignore-case field-name creq) creq)) | 3260 creq (delete (assoc-string field-name creq t) creq)) |
3257 (if (equal field-name "crossref") | 3261 (if (equal field-name "crossref") |
3258 (setq crossref-there t)))) | 3262 (setq crossref-there t)))) |
3259 (if crossref-there | 3263 (if crossref-there |
3260 (setq req creq)) | 3264 (setq req creq)) |
3261 (if (or (> (length req) 1) | 3265 (if (or (> (length req) 1) |