Mercurial > emacs
comparison lisp/textmodes/bibtex.el @ 69581:98eee222dceb
* textmodes/bibtex.el (bibtex-include-OPTkey)
(bibtex-entry-field-alist, bibtex-generate-url-list): Mark as
risky.
(bibtex-autokey-name-case-convert)
(bibtex-autokey-titleword-case-convert): Make these the aliases
for the following two variables.
(bibtex-autokey-name-case-convert-function)
(bibtex-autokey-titleword-case-convert-function): Make these the
real names.
(bibtex-font-lock-keywords): Make bibtex-font-lock-url and
bibtex-font-lock-crossref sublists.
(bibtex-mode): Revert 2005-12-30 change (which made
completion-ignore-case buffer-local).
(bibtex-url): Simplify
author | Roland Winkler <Roland.Winkler@physik.uni-erlangen.de> |
---|---|
date | Sun, 19 Mar 2006 21:55:25 +0000 |
parents | 067115a6e738 |
children | 0da18bcb2c37 e6bf73e43cf4 |
comparison
equal
deleted
inserted
replaced
69580:9f9192ca6907 | 69581:98eee222dceb |
---|---|
86 :group 'bibtex | 86 :group 'bibtex |
87 :type '(choice (const :tag "None" nil) | 87 :type '(choice (const :tag "None" nil) |
88 (string :tag "Initial text") | 88 (string :tag "Initial text") |
89 (function :tag "Initialize Function" :value fun) | 89 (function :tag "Initialize Function" :value fun) |
90 (other :tag "Default" t))) | 90 (other :tag "Default" t))) |
91 (put 'bibtex-include-OPTkey 'risky-local-variable t) | |
91 | 92 |
92 (defcustom bibtex-user-optional-fields | 93 (defcustom bibtex-user-optional-fields |
93 '(("annote" "Personal annotation (ignored)")) | 94 '(("annote" "Personal annotation (ignored)")) |
94 "List of optional fields the user wants to have always present. | 95 "List of optional fields the user wants to have always present. |
95 Entries should be of the same form as the OPTIONAL and | 96 Entries should be of the same form as the OPTIONAL and |
435 appears in the echo area, INIT is either the initial content of the | 436 appears in the echo area, INIT is either the initial content of the |
436 field or a function, which is called to determine the initial content | 437 field or a function, which is called to determine the initial content |
437 of the field, and ALTERNATIVE-FLAG (either nil or t) marks if the | 438 of the field, and ALTERNATIVE-FLAG (either nil or t) marks if the |
438 field is an alternative. ALTERNATIVE-FLAG may be t only in the | 439 field is an alternative. ALTERNATIVE-FLAG may be t only in the |
439 REQUIRED or CROSSREF-REQUIRED lists.") | 440 REQUIRED or CROSSREF-REQUIRED lists.") |
441 (put 'bibtex-entry-field-alist 'risky-local-variable t) | |
440 | 442 |
441 (defcustom bibtex-comment-start "@Comment" | 443 (defcustom bibtex-comment-start "@Comment" |
442 "String starting a BibTeX comment." | 444 "String starting a BibTeX comment." |
443 :group 'bibtex | 445 :group 'bibtex |
444 :type 'string) | 446 :type 'string) |
593 See `bibtex-generate-autokey' for details." | 595 See `bibtex-generate-autokey' for details." |
594 :group 'bibtex-autokey | 596 :group 'bibtex-autokey |
595 :type '(repeat (cons (regexp :tag "Old") | 597 :type '(repeat (cons (regexp :tag "Old") |
596 (string :tag "New")))) | 598 (string :tag "New")))) |
597 | 599 |
598 (defcustom bibtex-autokey-name-case-convert 'downcase | 600 (defcustom bibtex-autokey-name-case-convert-function 'downcase |
599 "Function called for each name to perform case conversion. | 601 "Function called for each name to perform case conversion. |
600 See `bibtex-generate-autokey' for details." | 602 See `bibtex-generate-autokey' for details." |
601 :group 'bibtex-autokey | 603 :group 'bibtex-autokey |
602 :type '(choice (const :tag "Preserve case" identity) | 604 :type '(choice (const :tag "Preserve case" identity) |
603 (const :tag "Downcase" downcase) | 605 (const :tag "Downcase" downcase) |
604 (const :tag "Capitalize" capitalize) | 606 (const :tag "Capitalize" capitalize) |
605 (const :tag "Upcase" upcase) | 607 (const :tag "Upcase" upcase) |
606 (function :tag "Conversion function"))) | 608 (function :tag "Conversion function"))) |
609 (defvaralias 'bibtex-autokey-name-case-convert | |
610 'bibtex-autokey-name-case-convert-function) | |
607 | 611 |
608 (defcustom bibtex-autokey-name-length 'infty | 612 (defcustom bibtex-autokey-name-length 'infty |
609 "Number of characters from name to incorporate into key. | 613 "Number of characters from name to incorporate into key. |
610 If this is set to anything but a number, all characters are used. | 614 If this is set to anything but a number, all characters are used. |
611 See `bibtex-generate-autokey' for details." | 615 See `bibtex-generate-autokey' for details." |
664 regexp from that list, it is not included in the title part of the key. | 668 regexp from that list, it is not included in the title part of the key. |
665 See `bibtex-generate-autokey' for details." | 669 See `bibtex-generate-autokey' for details." |
666 :group 'bibtex-autokey | 670 :group 'bibtex-autokey |
667 :type '(repeat regexp)) | 671 :type '(repeat regexp)) |
668 | 672 |
669 (defcustom bibtex-autokey-titleword-case-convert 'downcase | 673 (defcustom bibtex-autokey-titleword-case-convert-function 'downcase |
670 "Function called for each titleword to perform case conversion. | 674 "Function called for each titleword to perform case conversion. |
671 See `bibtex-generate-autokey' for details." | 675 See `bibtex-generate-autokey' for details." |
672 :group 'bibtex-autokey | 676 :group 'bibtex-autokey |
673 :type '(choice (const :tag "Preserve case" identity) | 677 :type '(choice (const :tag "Preserve case" identity) |
674 (const :tag "Downcase" downcase) | 678 (const :tag "Downcase" downcase) |
675 (const :tag "Capitalize" capitalize) | 679 (const :tag "Capitalize" capitalize) |
676 (const :tag "Upcase" upcase) | 680 (const :tag "Upcase" upcase) |
677 (function :tag "Conversion function"))) | 681 (function :tag "Conversion function"))) |
682 (defvaralias 'bibtex-autokey-titleword-case-convert | |
683 'bibtex-autokey-titleword-case-convert-function) | |
678 | 684 |
679 (defcustom bibtex-autokey-titleword-abbrevs nil | 685 (defcustom bibtex-autokey-titleword-abbrevs nil |
680 "Determines exceptions to the usual abbreviation mechanism. | 686 "Determines exceptions to the usual abbreviation mechanism. |
681 An alist of (OLD-REGEXP . NEW-STRING) pairs. Case is ignored | 687 An alist of (OLD-REGEXP . NEW-STRING) pairs. Case is ignored |
682 in matching against OLD-REGEXP, and the first matching pair is used. | 688 in matching against OLD-REGEXP, and the first matching pair is used. |
845 (list (string :tag "BibTeX field") | 851 (list (string :tag "BibTeX field") |
846 (regexp :tag "Regexp") | 852 (regexp :tag "Regexp") |
847 (choice (string :tag "Replacement") | 853 (choice (string :tag "Replacement") |
848 (integer :tag "Sub-match") | 854 (integer :tag "Sub-match") |
849 (function :tag "Filter")))))))) | 855 (function :tag "Filter")))))))) |
856 (put 'bibtex-generate-url-list 'risky-local-variable t) | |
850 | 857 |
851 (defcustom bibtex-expand-strings nil | 858 (defcustom bibtex-expand-strings nil |
852 "If non-nil, expand strings when extracting the content of a BibTeX field." | 859 "If non-nil, expand strings when extracting the content of a BibTeX field." |
853 :group 'bibtex | 860 :group 'bibtex |
854 :type 'boolean) | 861 :type 'boolean) |
1162 1 font-lock-comment-face) | 1169 1 font-lock-comment-face) |
1163 ;; field names | 1170 ;; field names |
1164 (,(concat "^[ \t]*\\(" bibtex-field-name "\\)[ \t]*=") | 1171 (,(concat "^[ \t]*\\(" bibtex-field-name "\\)[ \t]*=") |
1165 1 font-lock-variable-name-face) | 1172 1 font-lock-variable-name-face) |
1166 ;; url | 1173 ;; url |
1167 bibtex-font-lock-url bibtex-font-lock-crossref) | 1174 (bibtex-font-lock-url) (bibtex-font-lock-crossref)) |
1168 "*Default expressions to highlight in BibTeX mode.") | 1175 "*Default expressions to highlight in BibTeX mode.") |
1169 | 1176 |
1170 (defvar bibtex-font-lock-url-regexp | 1177 (defvar bibtex-font-lock-url-regexp |
1171 ;; Assume that field names begin at the beginning of a line. | 1178 ;; Assume that field names begin at the beginning of a line. |
1172 (concat "^[ \t]*" | 1179 (concat "^[ \t]*" |
2083 ((string-match "\\([^ ]+\\) *\\'" fullname) | 2090 ((string-match "\\([^ ]+\\) *\\'" fullname) |
2084 ;; name is of the form "First Middle Last" or "Last" | 2091 ;; name is of the form "First Middle Last" or "Last" |
2085 ;; --> take the last token | 2092 ;; --> take the last token |
2086 (match-string 1 fullname)) | 2093 (match-string 1 fullname)) |
2087 (t (error "Name `%s' is incorrectly formed" fullname))))) | 2094 (t (error "Name `%s' is incorrectly formed" fullname))))) |
2088 (funcall bibtex-autokey-name-case-convert | 2095 (funcall bibtex-autokey-name-case-convert-function |
2089 (bibtex-autokey-abbrev name bibtex-autokey-name-length)))) | 2096 (bibtex-autokey-abbrev name bibtex-autokey-name-length)))) |
2090 | 2097 |
2091 (defun bibtex-autokey-get-year () | 2098 (defun bibtex-autokey-get-year () |
2092 "Return year field contents as a string obeying `bibtex-autokey-year-length'." | 2099 "Return year field contents as a string obeying `bibtex-autokey-year-length'." |
2093 (let ((yearfield (bibtex-autokey-get-field "year"))) | 2100 (let ((yearfield (bibtex-autokey-get-field "year"))) |
2145 (not (string-match (concat "\\`\\(?:" (caar alist) "\\)\\'") | 2152 (not (string-match (concat "\\`\\(?:" (caar alist) "\\)\\'") |
2146 titleword))) | 2153 titleword))) |
2147 (setq alist (cdr alist))) | 2154 (setq alist (cdr alist))) |
2148 (if alist | 2155 (if alist |
2149 (cdar alist) | 2156 (cdar alist) |
2150 (funcall bibtex-autokey-titleword-case-convert | 2157 (funcall bibtex-autokey-titleword-case-convert-function |
2151 (bibtex-autokey-abbrev titleword bibtex-autokey-titleword-length))))) | 2158 (bibtex-autokey-abbrev titleword bibtex-autokey-titleword-length))))) |
2152 | 2159 |
2153 (defun bibtex-generate-autokey () | 2160 (defun bibtex-generate-autokey () |
2154 "Generate automatically a key for a BibTeX entry. | 2161 "Generate automatically a key for a BibTeX entry. |
2155 Use the author/editor, the year and the title field. | 2162 Use the author/editor, the year and the title field. |
2165 use all names. | 2172 use all names. |
2166 4. Use only the last names to form the name part. From these last names, | 2173 4. Use only the last names to form the name part. From these last names, |
2167 take at least `bibtex-autokey-name-length' characters (truncate only | 2174 take at least `bibtex-autokey-name-length' characters (truncate only |
2168 after a consonant or at a word end). | 2175 after a consonant or at a word end). |
2169 5. Convert all last names using the function | 2176 5. Convert all last names using the function |
2170 `bibtex-autokey-name-case-convert'. | 2177 `bibtex-autokey-name-case-convert-function'. |
2171 6. Build the name part of the key by concatenating all abbreviated last | 2178 6. Build the name part of the key by concatenating all abbreviated last |
2172 names with the string `bibtex-autokey-name-separator' between any two. | 2179 names with the string `bibtex-autokey-name-separator' between any two. |
2173 If there are more names in the name field than names used in the name | 2180 If there are more names in the name field than names used in the name |
2174 part, append the string `bibtex-autokey-additional-names'. | 2181 part, append the string `bibtex-autokey-additional-names'. |
2175 | 2182 |
2197 for further detail). | 2204 for further detail). |
2198 4. From every title word not generated by an abbreviation, take at least | 2205 4. From every title word not generated by an abbreviation, take at least |
2199 `bibtex-autokey-titleword-length' characters (truncate only after | 2206 `bibtex-autokey-titleword-length' characters (truncate only after |
2200 a consonant or at a word end). | 2207 a consonant or at a word end). |
2201 5. Convert all title words using the function | 2208 5. Convert all title words using the function |
2202 `bibtex-autokey-titleword-case-convert'. | 2209 `bibtex-autokey-titleword-case-convert-function'. |
2203 6. Build the title part by concatenating all abbreviated title words with | 2210 6. Build the title part by concatenating all abbreviated title words with |
2204 the string `bibtex-autokey-titleword-separator' between any two. | 2211 the string `bibtex-autokey-titleword-separator' between any two. |
2205 | 2212 |
2206 Concatenate the key: | 2213 Concatenate the key: |
2207 1. Concatenate `bibtex-autokey-prefix-string', the name part, the year | 2214 1. Concatenate `bibtex-autokey-prefix-string', the name part, the year |
2529 (defun bibtex-summary () | 2536 (defun bibtex-summary () |
2530 "Return summary of current BibTeX entry. | 2537 "Return summary of current BibTeX entry. |
2531 Used as default value of `bibtex-summary-function'." | 2538 Used as default value of `bibtex-summary-function'." |
2532 ;; It would be neat to customize this function. How? | 2539 ;; It would be neat to customize this function. How? |
2533 (if (looking-at bibtex-entry-maybe-empty-head) | 2540 (if (looking-at bibtex-entry-maybe-empty-head) |
2534 (let* ((bibtex-autokey-name-case-convert 'identity) | 2541 (let* ((bibtex-autokey-name-case-convert-function 'identity) |
2535 (bibtex-autokey-name-length 'infty) | 2542 (bibtex-autokey-name-length 'infty) |
2536 (bibtex-autokey-names 1) | 2543 (bibtex-autokey-names 1) |
2537 (bibtex-autokey-names-stretch 0) | 2544 (bibtex-autokey-names-stretch 0) |
2538 (bibtex-autokey-name-separator " ") | 2545 (bibtex-autokey-name-separator " ") |
2539 (bibtex-autokey-additional-names " etal") | 2546 (bibtex-autokey-additional-names " etal") |
2540 (names (bibtex-autokey-get-names)) | 2547 (names (bibtex-autokey-get-names)) |
2541 (bibtex-autokey-year-length 4) | 2548 (bibtex-autokey-year-length 4) |
2542 (year (bibtex-autokey-get-year)) | 2549 (year (bibtex-autokey-get-year)) |
2543 (bibtex-autokey-titlewords 5) | 2550 (bibtex-autokey-titlewords 5) |
2544 (bibtex-autokey-titlewords-stretch 2) | 2551 (bibtex-autokey-titlewords-stretch 2) |
2545 (bibtex-autokey-titleword-case-convert 'identity) | 2552 (bibtex-autokey-titleword-case-convert-function 'identity) |
2546 (bibtex-autokey-titleword-length 5) | 2553 (bibtex-autokey-titleword-length 5) |
2547 (bibtex-autokey-titleword-separator " ") | 2554 (bibtex-autokey-titleword-separator " ") |
2548 (title (bibtex-autokey-get-title)) | 2555 (title (bibtex-autokey-get-title)) |
2549 (journal (bibtex-autokey-get-field | 2556 (journal (bibtex-autokey-get-field |
2550 "journal" bibtex-autokey-transcriptions)) | 2557 "journal" bibtex-autokey-transcriptions)) |
2783 (bibtex-beginning-of-entry))))) | 2790 (bibtex-beginning-of-entry))))) |
2784 (setq imenu-generic-expression | 2791 (setq imenu-generic-expression |
2785 (list (list nil bibtex-entry-head bibtex-key-in-head)) | 2792 (list (list nil bibtex-entry-head bibtex-key-in-head)) |
2786 imenu-case-fold-search t) | 2793 imenu-case-fold-search t) |
2787 (make-local-variable 'choose-completion-string-functions) | 2794 (make-local-variable 'choose-completion-string-functions) |
2788 (make-local-variable 'completion-ignore-case) | |
2789 ;; XEmacs needs easy-menu-add, Emacs does not care | 2795 ;; XEmacs needs easy-menu-add, Emacs does not care |
2790 (easy-menu-add bibtex-edit-menu) | 2796 (easy-menu-add bibtex-edit-menu) |
2791 (easy-menu-add bibtex-entry-menu) | 2797 (easy-menu-add bibtex-entry-menu) |
2792 (run-mode-hooks 'bibtex-mode-hook)) | 2798 (run-mode-hooks 'bibtex-mode-hook)) |
2793 | 2799 |
4153 (= pnt (match-end 0))))) | 4159 (= pnt (match-end 0))))) |
4154 (setq compl 'key))))) | 4160 (setq compl 'key))))) |
4155 | 4161 |
4156 (cond ((eq compl 'key) | 4162 (cond ((eq compl 'key) |
4157 ;; key completion: no cleanup needed | 4163 ;; key completion: no cleanup needed |
4158 (setq choose-completion-string-functions nil | 4164 (setq choose-completion-string-functions nil) |
4159 completion-ignore-case nil) | 4165 (let (completion-ignore-case) |
4160 (bibtex-complete-internal (bibtex-global-key-alist))) | 4166 (bibtex-complete-internal (bibtex-global-key-alist)))) |
4161 | 4167 |
4162 ((eq compl 'crossref-key) | 4168 ((eq compl 'crossref-key) |
4163 ;; crossref key completion | 4169 ;; crossref key completion |
4164 ;; | 4170 ;; |
4165 ;; If we quit the *Completions* buffer without requesting | 4171 ;; If we quit the *Completions* buffer without requesting |
4166 ;; a completion, `choose-completion-string-functions' is still | 4172 ;; a completion, `choose-completion-string-functions' is still |
4167 ;; non-nil. Therefore, `choose-completion-string-functions' is | 4173 ;; non-nil. Therefore, `choose-completion-string-functions' is |
4168 ;; always set (either to non-nil or nil) when a new completion | 4174 ;; always set (either to non-nil or nil) when a new completion |
4169 ;; is requested. | 4175 ;; is requested. |
4170 ;; Also, `choose-completion-delete-max-match' requires | 4176 (let (completion-ignore-case) |
4171 ;; that we set `completion-ignore-case' (i.e., binding via `let' | 4177 (setq choose-completion-string-functions |
4172 ;; is not sufficient). | 4178 (lambda (choice buffer mini-p base-size) |
4173 (setq completion-ignore-case nil | 4179 (setq choose-completion-string-functions nil) |
4174 choose-completion-string-functions | 4180 (choose-completion-string choice buffer base-size) |
4175 (lambda (choice buffer mini-p base-size) | 4181 (bibtex-complete-crossref-cleanup choice) |
4176 (setq choose-completion-string-functions nil) | 4182 t)) ; needed by choose-completion-string-functions |
4177 (choose-completion-string choice buffer base-size) | 4183 (bibtex-complete-crossref-cleanup |
4178 (bibtex-complete-crossref-cleanup choice) | 4184 (bibtex-complete-internal (bibtex-global-key-alist))))) |
4179 t)) ; needed by choose-completion-string-functions | |
4180 | |
4181 (bibtex-complete-crossref-cleanup (bibtex-complete-internal | |
4182 (bibtex-global-key-alist)))) | |
4183 | 4185 |
4184 ((eq compl 'string) | 4186 ((eq compl 'string) |
4185 ;; string key completion: no cleanup needed | 4187 ;; string key completion: no cleanup needed |
4186 (setq choose-completion-string-functions nil | 4188 (setq choose-completion-string-functions nil) |
4187 completion-ignore-case t) | 4189 (let ((completion-ignore-case t)) |
4188 (bibtex-complete-internal bibtex-strings)) | 4190 (bibtex-complete-internal bibtex-strings))) |
4189 | 4191 |
4190 (compl | 4192 (compl |
4191 ;; string completion | 4193 ;; string completion |
4192 (setq completion-ignore-case t | 4194 (let ((completion-ignore-case t)) |
4193 choose-completion-string-functions | 4195 (setq choose-completion-string-functions |
4194 `(lambda (choice buffer mini-p base-size) | 4196 `(lambda (choice buffer mini-p base-size) |
4195 (setq choose-completion-string-functions nil) | 4197 (setq choose-completion-string-functions nil) |
4196 (choose-completion-string choice buffer base-size) | 4198 (choose-completion-string choice buffer base-size) |
4197 (bibtex-complete-string-cleanup choice ',compl) | 4199 (bibtex-complete-string-cleanup choice ',compl) |
4198 t)) ; needed by choose-completion-string-functions | 4200 t)) ; needed by choose-completion-string-functions |
4199 (bibtex-complete-string-cleanup (bibtex-complete-internal compl) | 4201 (bibtex-complete-string-cleanup (bibtex-complete-internal compl) |
4200 compl)) | 4202 compl))) |
4201 | 4203 |
4202 (t (setq choose-completion-string-functions nil | 4204 (t (setq choose-completion-string-functions nil) |
4203 completion-ignore-case nil) ; default | |
4204 (error "Point outside key or BibTeX field"))))) | 4205 (error "Point outside key or BibTeX field"))))) |
4205 | 4206 |
4206 (defun bibtex-Article () | 4207 (defun bibtex-Article () |
4207 "Insert a new BibTeX @Article entry; see also `bibtex-entry'." | 4208 "Insert a new BibTeX @Article entry; see also `bibtex-entry'." |
4208 (interactive "*") | 4209 (interactive "*") |
4332 (if (stringp (car scheme)) | 4333 (if (stringp (car scheme)) |
4333 (setq fmt (pop scheme))) | 4334 (setq fmt (pop scheme))) |
4334 (dolist (step scheme) | 4335 (dolist (step scheme) |
4335 (setq field (cdr (assoc-string (car step) fields-alist t))) | 4336 (setq field (cdr (assoc-string (car step) fields-alist t))) |
4336 (if (string-match (nth 1 step) field) | 4337 (if (string-match (nth 1 step) field) |
4337 (setq field (cond ((functionp (nth 2 step)) | 4338 (push (cond ((functionp (nth 2 step)) |
4338 (funcall (nth 2 step) field)) | 4339 (funcall (nth 2 step) field)) |
4339 ((numberp (nth 2 step)) | 4340 ((numberp (nth 2 step)) |
4340 (match-string (nth 2 step) field)) | 4341 (match-string (nth 2 step) field)) |
4341 (t | 4342 (t |
4342 (replace-match (nth 2 step) t nil field)))) | 4343 (replace-match (nth 2 step) t nil field))) |
4344 obj) | |
4343 ;; If the scheme is set up correctly, | 4345 ;; If the scheme is set up correctly, |
4344 ;; we should never reach this point | 4346 ;; we should never reach this point |
4345 (error "Match failed: %s" field)) | 4347 (error "Match failed: %s" field))) |
4346 (push field obj)) | |
4347 (if fmt (apply 'format fmt (nreverse obj)) | 4348 (if fmt (apply 'format fmt (nreverse obj)) |
4348 (apply 'concat (nreverse obj))))) | 4349 (apply 'concat (nreverse obj))))) |
4349 (browse-url (message "%s" url)))) | 4350 (browse-url (message "%s" url)))) |
4350 (unless url (message "No URL known."))))) | 4351 (unless url (message "No URL known."))))) |
4351 | 4352 |