Mercurial > emacs
comparison lisp/textmodes/bibtex.el @ 90384:c156f6a9e7b5
Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-56
Merge from emacs--devo--0
Patches applied:
* emacs--devo--0 (patch 204-225)
- Update from CVS
- Sync from erc--emacs--0
- Merge from gnus--rel--5.10
- Improve tq.el.
- Update from CVS: src/puresize.h (PURESIZE_RATIO): Reduce to 10/6.
* gnus--rel--5.10 (patch 81-85)
- Update from CVS
- Merge from emacs--devo--0
author | Miles Bader <miles@gnu.org> |
---|---|
date | Mon, 17 Apr 2006 08:41:12 +0000 |
parents | e6bf73e43cf4 14e2e318d372 |
children | 2ecafc6d5db7 |
comparison
equal
deleted
inserted
replaced
90383:ab20fb198dda | 90384:c156f6a9e7b5 |
---|---|
2854 (bibtex-next-field t) | 2854 (bibtex-next-field t) |
2855 (if (member-ignore-case entry-type bibtex-autofill-types) | 2855 (if (member-ignore-case entry-type bibtex-autofill-types) |
2856 (bibtex-autofill-entry)) | 2856 (bibtex-autofill-entry)) |
2857 (run-hooks 'bibtex-add-entry-hook))) | 2857 (run-hooks 'bibtex-add-entry-hook))) |
2858 | 2858 |
2859 (defun bibtex-entry-update () | 2859 (defun bibtex-entry-update (&optional entry-type) |
2860 "Update an existing BibTeX entry. | 2860 "Update an existing BibTeX entry. |
2861 In the BibTeX entry at point, make new fields for those items that may occur | 2861 In the BibTeX entry at point, make new fields for those items that may occur |
2862 according to `bibtex-field-list', but are not yet present." | 2862 according to `bibtex-field-list', but are not yet present. |
2863 (interactive) | 2863 Also, add field delimiters to numerical fields if they are not present. |
2864 If ENTRY-TYPE is non-nil, change first the entry type to ENTRY-TYPE. | |
2865 When called interactively with a prefix arg, query for a value of ENTRY-TYPE." | |
2866 (interactive | |
2867 (list (if current-prefix-arg | |
2868 (let ((completion-ignore-case t)) | |
2869 (completing-read "New entry type: " bibtex-entry-field-alist | |
2870 nil t nil 'bibtex-entry-type-history))))) | |
2864 (save-excursion | 2871 (save-excursion |
2865 (bibtex-beginning-of-entry) | 2872 (bibtex-beginning-of-entry) |
2866 ;; For inserting new fields, we use the fact that | 2873 (when (looking-at bibtex-entry-maybe-empty-head) |
2867 ;; `bibtex-parse-entry' moves point to the end of the last field. | 2874 (goto-char (match-end 0)) |
2868 (let* ((fields-alist (bibtex-parse-entry)) | 2875 (if entry-type |
2869 (field-list (bibtex-field-list | 2876 (save-excursion |
2870 (cdr (assoc "=type=" fields-alist))))) | 2877 (replace-match (concat "@" entry-type) nil nil nil 1)) |
2871 (skip-chars-backward " \t\n") | 2878 (setq entry-type (bibtex-type-in-head))) |
2872 (dolist (field (car field-list)) | 2879 (let* ((field-list (bibtex-field-list entry-type)) |
2873 (unless (assoc-string (car field) fields-alist t) | 2880 (required (copy-tree (car field-list))) |
2874 (bibtex-make-field field))) | 2881 (optional (copy-tree (cdr field-list))) |
2875 (dolist (field (cdr field-list)) | 2882 bounds) |
2876 (unless (assoc-string (car field) fields-alist t) | 2883 (while (setq bounds (bibtex-parse-field)) |
2877 (bibtex-make-optional-field field)))))) | 2884 (let ((fname (bibtex-name-in-field bounds t)) |
2885 (end (copy-marker (bibtex-end-of-field bounds) t))) | |
2886 (setq required (delete (assoc-string fname required t) required) | |
2887 optional (delete (assoc-string fname optional t) optional)) | |
2888 (when (string-match "\\`[0-9]+\\'" | |
2889 (bibtex-text-in-field-bounds bounds)) | |
2890 (goto-char (bibtex-end-of-text-in-field bounds)) | |
2891 (insert (bibtex-field-right-delimiter)) | |
2892 (goto-char (bibtex-start-of-text-in-field bounds)) | |
2893 (insert (bibtex-field-left-delimiter))) | |
2894 (goto-char end))) | |
2895 (skip-chars-backward " \t\n") | |
2896 (dolist (field required) (bibtex-make-field field)) | |
2897 (dolist (field optional) (bibtex-make-optional-field field)))))) | |
2878 | 2898 |
2879 (defun bibtex-parse-entry (&optional content) | 2899 (defun bibtex-parse-entry (&optional content) |
2880 "Parse entry at point, return an alist. | 2900 "Parse entry at point, return an alist. |
2881 The alist elements have the form (FIELD . TEXT), where FIELD can also be | 2901 The alist elements have the form (FIELD . TEXT), where FIELD can also be |
2882 the special strings \"=type=\" and \"=key=\". For the FIELD \"=key=\" | 2902 the special strings \"=type=\" and \"=key=\". For the FIELD \"=key=\" |
3611 (if help (bibtex-print-help-message (car bounds)))) | 3631 (if help (bibtex-print-help-message (car bounds)))) |
3612 ((not noerror) (error "Not on BibTeX field"))))) | 3632 ((not noerror) (error "Not on BibTeX field"))))) |
3613 | 3633 |
3614 (defun bibtex-find-text-internal (&optional noerror subfield comma) | 3634 (defun bibtex-find-text-internal (&optional noerror subfield comma) |
3615 "Find text part of current BibTeX field or entry head. | 3635 "Find text part of current BibTeX field or entry head. |
3616 Return list (NAME START-TEXT END-TEXT END) with field or entry name, | 3636 Return list (NAME START-TEXT END-TEXT END STRING-CONST) with field |
3617 start and end of text and end of field or entry head, or nil if not found. | 3637 or entry name, start and end of text, and end of field or entry head. |
3618 If optional arg NOERROR is non-nil, an error message is suppressed if text | 3638 STRING-CONST is a flag which is non-nil if current subfield delimited by # |
3619 is not found. If optional arg SUBFIELD is non-nil START-TEXT and END-TEXT | 3639 is a BibTeX string constant. Return value is nil if field or entry head |
3620 correspond to the current subfield delimited by #. | 3640 are not found. |
3641 If optional arg NOERROR is non-nil, an error message is suppressed | |
3642 if text is not found. If optional arg SUBFIELD is non-nil START-TEXT | |
3643 and END-TEXT correspond to the current subfield delimited by #. | |
3621 Optional arg COMMA is as in `bibtex-enclosing-field'." | 3644 Optional arg COMMA is as in `bibtex-enclosing-field'." |
3622 (save-excursion | 3645 (save-excursion |
3623 (let ((pnt (point)) | 3646 (let ((pnt (point)) |
3624 (bounds (bibtex-enclosing-field comma t)) | 3647 (bounds (bibtex-enclosing-field comma t)) |
3625 (case-fold-search t) | 3648 (case-fold-search t) |
3626 name start-text end-text end failure done no-sub) | 3649 name start-text end-text end failure done no-sub string-const) |
3627 (bibtex-beginning-of-entry) | 3650 (bibtex-beginning-of-entry) |
3628 (cond (bounds | 3651 (cond (bounds |
3629 (setq name (bibtex-name-in-field bounds t) | 3652 (setq name (bibtex-name-in-field bounds t) |
3630 start-text (bibtex-start-of-text-in-field bounds) | 3653 start-text (bibtex-start-of-text-in-field bounds) |
3631 end-text (bibtex-end-of-text-in-field bounds) | 3654 end-text (bibtex-end-of-text-in-field bounds) |
3665 (setq failure no-sub) | 3688 (setq failure no-sub) |
3666 (unless failure | 3689 (unless failure |
3667 (goto-char start-text) | 3690 (goto-char start-text) |
3668 (while (not done) | 3691 (while (not done) |
3669 (if (or (prog1 (looking-at bibtex-field-const) | 3692 (if (or (prog1 (looking-at bibtex-field-const) |
3670 (setq end-text (match-end 0))) | 3693 (setq end-text (match-end 0) |
3694 string-const t)) | |
3671 (prog1 (setq bounds (bibtex-parse-field-string)) | 3695 (prog1 (setq bounds (bibtex-parse-field-string)) |
3672 (setq end-text (cdr bounds)))) | 3696 (setq end-text (cdr bounds) |
3697 string-const nil))) | |
3673 (progn | 3698 (progn |
3674 (if (and (<= start-text pnt) (<= pnt end-text)) | 3699 (if (and (<= start-text pnt) (<= pnt end-text)) |
3675 (setq done t) | 3700 (setq done t) |
3676 (goto-char end-text)) | 3701 (goto-char end-text)) |
3677 (if (looking-at "[ \t\n]*#[ \t\n]*") | 3702 (if (looking-at "[ \t\n]*#[ \t\n]*") |
3678 (setq start-text (goto-char (match-end 0))))) | 3703 (setq start-text (goto-char (match-end 0))))) |
3679 (setq done t failure t))))) | 3704 (setq done t failure t))))) |
3680 (cond ((not failure) | 3705 (cond ((not failure) |
3681 (list name start-text end-text end)) | 3706 (list name start-text end-text end string-const)) |
3682 ((and no-sub (not noerror)) | 3707 ((and no-sub (not noerror)) |
3683 (error "Not on text part of BibTeX field")) | 3708 (error "Not on text part of BibTeX field")) |
3684 ((not noerror) (error "Not on BibTeX field")))))) | 3709 ((not noerror) (error "Not on BibTeX field")))))) |
3685 | 3710 |
3686 (defun bibtex-remove-OPT-or-ALT (&optional comma) | 3711 (defun bibtex-remove-OPT-or-ALT (&optional comma) |
3710 (defun bibtex-remove-delimiters (&optional comma) | 3735 (defun bibtex-remove-delimiters (&optional comma) |
3711 "Remove \"\" or {} around current BibTeX field text. | 3736 "Remove \"\" or {} around current BibTeX field text. |
3712 Optional arg COMMA is as in `bibtex-enclosing-field'. It is t for | 3737 Optional arg COMMA is as in `bibtex-enclosing-field'. It is t for |
3713 interactive calls." | 3738 interactive calls." |
3714 (interactive (list t)) | 3739 (interactive (list t)) |
3715 (let* ((bounds (bibtex-find-text-internal nil t comma)) | 3740 (let ((bounds (bibtex-find-text-internal nil t comma))) |
3716 (start (nth 1 bounds)) | 3741 (unless (nth 4 bounds) |
3717 (end (nth 2 bounds))) | 3742 (delete-region (1- (nth 2 bounds)) (nth 2 bounds)) |
3718 (if (memq (char-before end) '(?\} ?\")) | 3743 (delete-region (nth 1 bounds) (1+ (nth 1 bounds)))))) |
3719 (delete-region (1- end) end)) | |
3720 (if (memq (char-after start) '(?\{ ?\")) | |
3721 (delete-region start (1+ start))))) | |
3722 | 3744 |
3723 (defun bibtex-kill-field (&optional copy-only comma) | 3745 (defun bibtex-kill-field (&optional copy-only comma) |
3724 "Kill the entire enclosing BibTeX field. | 3746 "Kill the entire enclosing BibTeX field. |
3725 With prefix arg COPY-ONLY, copy the current field to `bibtex-field-kill-ring', | 3747 With prefix arg COPY-ONLY, copy the current field to `bibtex-field-kill-ring', |
3726 but do not actually kill it. Optional arg COMMA is as in | 3748 but do not actually kill it. Optional arg COMMA is as in |