aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1998-02-16 05:42:08 +0000
committerRichard M. Stallman1998-02-16 05:42:08 +0000
commitab2d0cdb53b226e63c02730231a271312e940e12 (patch)
tree773ac041a028bb5dbf9614dd376ca300b0982210
parent65c9d7855ef3883bcc8d162853775a961b9f7c73 (diff)
downloademacs-ab2d0cdb53b226e63c02730231a271312e940e12.tar.gz
emacs-ab2d0cdb53b226e63c02730231a271312e940e12.zip
(bibtex-autokey-names): Change number tag to integer.
(bibtex-include-OPTkey): Add non-nil default :value for function, so that it can be selected. (bibtex-entry-format): Replace repeat with set. (bibtex-mode-hook): Change :type to 'hook. (bibtex-clean-entry-hook): Ditto. (bibtex-add-entry-hook): Ditto. (bibtex-autokey-before-presentation-hook): Change name to -> `bibtex-autokey-before-presentation-function' as it is not hook. (bibtex-autokey-get-namefield): Remove newlines unconditionally. (bibtex-autokey): Fixed prefix. (bibtex-user-optional-fields): Better `:type'. (bibtex-autokey-names): Better `:type' and doc-fix. (bibtex-mark-active): New function, taking care of Emacs variants. (bibtex-run-with-idle-timer): Ditto. (bibtex-mode-map): Change `[(control tab)]' to `[(meta tab)]'. (bibtex-autokey-get-yearfield): Changed to accept year when year field has field-delimiters. This is quick fix, there might be better solution. (bibtex-mode): Don't call idle timer with 0 seconds. (bibtex-mode): Call easy-menu-add. (bibtex-autokey-get-yearfield): Fixed problem with parsing the year field. (bibtex-comment-start): Font locking for comments added. (autokey-name-case-convert, autokey-titleword-case-convert): Replace autokey-preserve-case, adding flexibility to case conversion of author names and titlewords. (bibtex-autokey-get-titles): Non capitalized title words are used for key generation as well. (bibtex-member-of-regexp): Case is honoured for matches now. (bibtex-autokey-titleword-ignore): Added entries provide compatibility to former behaviour. (bibtex-autokey-titleword-ignore): Title words found in this list are always ignored (previously only at the beginning of the title). Replaces bibtex-autokey-titleword-first-ignore.
-rw-r--r--lisp/textmodes/bibtex.el331
1 files changed, 194 insertions, 137 deletions
diff --git a/lisp/textmodes/bibtex.el b/lisp/textmodes/bibtex.el
index 110846a2c94..6b01e848664 100644
--- a/lisp/textmodes/bibtex.el
+++ b/lisp/textmodes/bibtex.el
@@ -3,7 +3,7 @@
3;; Copyright (C) 1992, 1994, 1995, 1996, 1997 Free Software Foundation, Inc. 3;; Copyright (C) 1992, 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
4 4
5;; Author: Stefan Schoef <schoef@offis.uni-oldenburg.de> 5;; Author: Stefan Schoef <schoef@offis.uni-oldenburg.de>
6;; Bengt Martensson <bengt@mathematik.uni-Bremen.de> 6;; Bengt Martensson <bengt@mathematik.uni-Bremen.de>
7;; Mark Shapiro <shapiro@corto.inria.fr> 7;; Mark Shapiro <shapiro@corto.inria.fr>
8;; Mike Newton <newton@gumby.cs.caltech.edu> 8;; Mike Newton <newton@gumby.cs.caltech.edu>
9;; Aaron Larson <alarson@src.honeywell.com> 9;; Aaron Larson <alarson@src.honeywell.com>
@@ -53,12 +53,12 @@
53(defgroup bibtex-autokey nil 53(defgroup bibtex-autokey nil
54 "Generates automatically a key from the author/editor and the title field" 54 "Generates automatically a key from the author/editor and the title field"
55 :group 'bibtex 55 :group 'bibtex
56 :prefix 'bibtex-autokey) 56 :prefix "bibtex-autokey-")
57 57
58(defcustom bibtex-mode-hook nil 58(defcustom bibtex-mode-hook nil
59 "List of functions to call on entry to BibTeX mode." 59 "List of functions to call on entry to BibTeX mode."
60 :group 'bibtex 60 :group 'bibtex
61 :type '(repeat function)) 61 :type 'hook)
62 62
63(defcustom bibtex-field-delimiters 'braces 63(defcustom bibtex-field-delimiters 'braces
64 "*Controls type of field delimiters used. 64 "*Controls type of field delimiters used.
@@ -91,7 +91,7 @@ If this is a function, it will be called to generate the initial field text."
91 :type '(choice (const :tag "None" nil) 91 :type '(choice (const :tag "None" nil)
92 (const :tag "Default" t) 92 (const :tag "Default" t)
93 (string :tag "Initial text") 93 (string :tag "Initial text")
94 (function :tag "Initialize Function"))) 94 (function :tag "Initialize Function" :value fun)))
95 95
96(defcustom bibtex-user-optional-fields 96(defcustom bibtex-user-optional-fields
97 '(("annote" "Personal annotation (ignored)")) 97 '(("annote" "Personal annotation (ignored)"))
@@ -101,7 +101,13 @@ CROSSREF-OPTIONAL lists in `bibtex-entry-field-alist' (see documentation
101of this variable for details)." 101of this variable for details)."
102 :group 'bibtex 102 :group 'bibtex
103 :type '(repeat 103 :type '(repeat
104 (repeat string))) 104 (group (string :tag "Field")
105 (string :tag "Comment")
106 (option (group :inline t
107 :extra-offset -4
108 (choice :tag "Init" :value ""
109 string
110 function))))))
105 111
106(defcustom bibtex-entry-format '(opts-or-alts numerical-fields) 112(defcustom bibtex-entry-format '(opts-or-alts numerical-fields)
107 "*Controls type of formatting performed by `bibtex-clean-entry'. 113 "*Controls type of formatting performed by `bibtex-clean-entry'.
@@ -130,14 +136,22 @@ The value nil means do no formatting at all."
130 :group 'bibtex 136 :group 'bibtex
131 :type '(choice (const :tag "None" nil) 137 :type '(choice (const :tag "None" nil)
132 (const :tag "All" t) 138 (const :tag "All" t)
133 (repeat symbol))) 139 (set :menu-tag "Some"
140 (const opts-or-alts)
141 (const numerical-fields)
142 (const page-dashes)
143 (const inherit-booktitle)
144 (const realign)
145 (const last-comma)
146 (const delimiters)
147 (const unify-case))))
134 148
135(defcustom bibtex-clean-entry-hook nil 149(defcustom bibtex-clean-entry-hook nil
136 "*List of functions to call when entry has been cleaned. 150 "*List of functions to call when entry has been cleaned.
137Functions are called with point inside the cleaned entry, and the buffer 151Functions are called with point inside the cleaned entry, and the buffer
138narrowed to just the entry." 152narrowed to just the entry."
139 :group 'bibtex 153 :group 'bibtex
140 :type '(repeat function)) 154 :type 'hook)
141 155
142(defcustom bibtex-sort-ignore-string-entries t 156(defcustom bibtex-sort-ignore-string-entries t
143 "*If non-nil, BibTeX @String entries are not sort-significant. 157 "*If non-nil, BibTeX @String entries are not sort-significant.
@@ -393,10 +407,12 @@ of the field, and ALTERNATIVE-FLAG (either nil or t) marks if the
393field is an alternative. ALTERNATIVE-FLAG may be t only in the 407field is an alternative. ALTERNATIVE-FLAG may be t only in the
394REQUIRED or CROSSREF-REQUIRED lists.") 408REQUIRED or CROSSREF-REQUIRED lists.")
395 409
410(defvar bibtex-comment-start "@Comment ")
411
396(defcustom bibtex-add-entry-hook nil 412(defcustom bibtex-add-entry-hook nil
397 "List of functions to call when entry has been inserted." 413 "List of functions to call when entry has been inserted."
398 :group 'bibtex 414 :group 'bibtex
399 :type '(repeat function)) 415 :type 'hook)
400 416
401(defcustom bibtex-predefined-month-strings 417(defcustom bibtex-predefined-month-strings
402 '( 418 '(
@@ -451,11 +467,12 @@ See the documentation of function `bibtex-generate-autokey' for more detail."
451 467
452(defcustom bibtex-autokey-names 1 468(defcustom bibtex-autokey-names 1
453 "*Number of names to use for the automatically generated reference key. 469 "*Number of names to use for the automatically generated reference key.
454If this is set to anything but a number, all names are used. 470If this is variable is nil, all names are used.
455Possibly more names are used according to `bibtex-autokey-names-stretch'. 471Possibly more names are used according to `bibtex-autokey-names-stretch'.
456See the documentation of function `bibtex-generate-autokey' for more detail." 472See the documentation of function `bibtex-generate-autokey' for more detail."
457 :group 'bibtex-autokey 473 :group 'bibtex-autokey
458 :type 'integer) 474 :type '(choice (const :tag "All" infty)
475 integer))
459 476
460(defcustom bibtex-autokey-names-stretch 0 477(defcustom bibtex-autokey-names-stretch 0
461 "*Number of names that can additionally be used. 478 "*Number of names that can additionally be used.
@@ -509,6 +526,16 @@ See the documentation of function `bibtex-generate-autokey' for details."
509 (list (regexp :tag "Old") 526 (list (regexp :tag "Old")
510 (string :tag "New")))) 527 (string :tag "New"))))
511 528
529(defcustom bibtex-autokey-name-case-convert 'downcase
530 "*Function called for each name to perform case conversion.
531See the documentation of function `bibtex-generate-autokey' for more detail."
532 :group 'bibtex-autokey
533 :type '(choice (const :tag "Preserve case" identity)
534 (const :tag "Downcase" downcase)
535 (const :tag "Capitalize" capitalize)
536 (const :tag "Upcase" upcase)
537 (function :tag "Conversion function")))
538
512(defcustom bibtex-autokey-name-length 'infty 539(defcustom bibtex-autokey-name-length 'infty
513 "*Number of characters from name to incorporate into key. 540 "*Number of characters from name to incorporate into key.
514If this is set to anything but a number, all characters are used. 541If this is set to anything but a number, all characters are used.
@@ -563,16 +590,26 @@ See the documentation of function `bibtex-generate-autokey' for details."
563 :group 'bibtex-autokey 590 :group 'bibtex-autokey
564 :type 'integer) 591 :type 'integer)
565 592
566(defcustom bibtex-autokey-titleword-first-ignore 593(defcustom bibtex-autokey-titleword-ignore
567 '("a" "an" "on" "the" "eine?" "der" "die" "das") 594 '("A" "An" "On" "The" "Eine?" "Der" "Die" "Das"
568 "*Determines words that may begin a title but are not to be used in the key. 595 "[^A-Z].*" ".*[^a-zA-Z0-9].*")
569Each item of the list is a regexp. If the first word of the title matchs a 596 "*Determines words from the title that are not to be used in the key.
570regexp from that list, it is not included in the title, even if it is 597Each item of the list is a regexp. If a word of the title matchs a
571capitalized. Case of regexps in this list doesn't matter. 598regexp from that list, it is not included in the title part of the key.
572See the documentation of function `bibtex-generate-autokey' for details." 599See the documentation of function `bibtex-generate-autokey' for details."
573 :group 'bibtex-autokey 600 :group 'bibtex-autokey
574 :type '(repeat regexp)) 601 :type '(repeat regexp))
575 602
603(defcustom bibtex-autokey-titleword-case-convert 'downcase
604 "*Function called for each titleword to perform case conversion.
605See the documentation of function `bibtex-generate-autokey' for more detail."
606 :group 'bibtex-autokey
607 :type '(choice (const :tag "Preserve case" identity)
608 (const :tag "Downcase" downcase)
609 (const :tag "Capitalize" capitalize)
610 (const :tag "Upcase" upcase)
611 (function :tag "Conversion function")))
612
576(defcustom bibtex-autokey-titleword-abbrevs nil 613(defcustom bibtex-autokey-titleword-abbrevs nil
577 "*Determines exceptions to the usual abbreviation mechanism. 614 "*Determines exceptions to the usual abbreviation mechanism.
578An alist of (OLD-REGEXP NEW-STRING) pairs. Case is ignored 615An alist of (OLD-REGEXP NEW-STRING) pairs. Case is ignored
@@ -618,18 +655,12 @@ See the documentation of function `bibtex-generate-autokey' for details."
618 :group 'bibtex-autokey 655 :group 'bibtex-autokey
619 :type 'string) 656 :type 'string)
620 657
621(defcustom bibtex-autokey-preserve-case nil
622 "*If non-nil, names and titlewords used aren't converted to lower case.
623See the documentation of function `bibtex-generate-autokey' for details."
624 :group 'bibtex-autokey
625 :type 'boolean)
626
627(defcustom bibtex-autokey-edit-before-use t 658(defcustom bibtex-autokey-edit-before-use t
628 "*If non-nil, user is allowed to edit the generated key before it is used." 659 "*If non-nil, user is allowed to edit the generated key before it is used."
629 :group 'bibtex-autokey 660 :group 'bibtex-autokey
630 :type 'boolean) 661 :type 'boolean)
631 662
632(defcustom bibtex-autokey-before-presentation-hook nil 663(defcustom bibtex-autokey-before-presentation-function nil
633 "Function to call before the generated key is presented. 664 "Function to call before the generated key is presented.
634If non-nil this should be a single function, which is called before 665If non-nil this should be a single function, which is called before
635the generated key is presented (in entry or, if 666the generated key is presented (in entry or, if
@@ -680,6 +711,24 @@ the value of `bibtex-text-indentation', minus 2."
680;; bibtex-font-lock-keywords is a user option as well, but since the 711;; bibtex-font-lock-keywords is a user option as well, but since the
681;; patterns used to define this variable are defined in a later 712;; patterns used to define this variable are defined in a later
682;; section of this file, it is defined later. 713;; section of this file, it is defined later.
714
715;; Special support taking care of variants
716(if (boundp 'mark-active)
717 (defun bibtex-mark-active ()
718 ;; In Emacs mark-active indicates if mark is active.
719 mark-active)
720 (defun bibtex-mark-active ()
721 ;; In XEmacs (mark) returns nil when not active.
722 (if zmacs-regions (mark) (mark t))))
723
724(if (fboundp 'run-with-idle-timer)
725 ;; timer.el is distributed with Emacs
726 (fset 'bibtex-run-with-idle-timer 'run-with-idle-timer)
727 ;; timer.el is not distributed with XEmacs
728 ;; Notice that this does not (yet) pass the arguments, but they
729 ;; are not used (yet) in bibtex.el. Fix if needed.
730 (defun bibtex-run-with-idle-timer (secs repeat function &rest args)
731 (start-itimer "bibtex" function secs (if repeat secs nil) t)))
683 732
684 733
685;; Syntax Table, Keybindings and BibTeX Entry List 734;; Syntax Table, Keybindings and BibTeX Entry List
@@ -701,7 +750,7 @@ the value of `bibtex-text-indentation', minus 2."
701 (define-key km "\t" 'bibtex-find-text) 750 (define-key km "\t" 'bibtex-find-text)
702 (define-key km "\n" 'bibtex-next-field) 751 (define-key km "\n" 'bibtex-next-field)
703 (define-key km "\M-\t" 'bibtex-complete-string) 752 (define-key km "\M-\t" 'bibtex-complete-string)
704 (define-key km [(control tab)] 'bibtex-complete-key) 753 (define-key km [(meta tab)] 'bibtex-complete-key)
705 (define-key km "\C-c\"" 'bibtex-remove-delimiters) 754 (define-key km "\C-c\"" 'bibtex-remove-delimiters)
706 (define-key km "\C-c{" 'bibtex-remove-delimiters) 755 (define-key km "\C-c{" 'bibtex-remove-delimiters)
707 (define-key km "\C-c}" 'bibtex-remove-delimiters) 756 (define-key km "\C-c}" 'bibtex-remove-delimiters)
@@ -1066,17 +1115,21 @@ the value of `bibtex-text-indentation', minus 2."
1066 1115
1067(defvar bibtex-font-lock-keywords 1116(defvar bibtex-font-lock-keywords
1068 (list 1117 (list
1118 ;; reference type and reference label
1069 (list bibtex-reference-maybe-empty-head 1119 (list bibtex-reference-maybe-empty-head
1070 (list bibtex-type-in-head 'font-lock-function-name-face) 1120 (list bibtex-type-in-head 'font-lock-function-name-face)
1071 (list bibtex-key-in-head 'font-lock-reference-face nil t)) 1121 (list bibtex-key-in-head 'font-lock-reference-face nil t))
1072 ;; reference type and reference label 1122 ;; comments
1123 (list
1124 (concat "^\\([ \t]*" bibtex-comment-start ".*\\)$")
1125 1 'font-lock-comment-face)
1126 ;; optional field names (treated as comments)
1073 (list 1127 (list
1074 (concat "^[ \t]*\\(OPT" bibtex-field-name "\\)[ \t]*=") 1128 (concat "^[ \t]*\\(OPT" bibtex-field-name "\\)[ \t]*=")
1075 1 'font-lock-comment-face) 1129 1 'font-lock-comment-face)
1076 ;; optional field names (treated as comments) 1130 ;; field names
1077 (list (concat "^[ \t]*\\(" bibtex-field-name "\\)[ \t]*=") 1131 (list (concat "^[ \t]*\\(" bibtex-field-name "\\)[ \t]*=")
1078 1 'font-lock-variable-name-face) 1132 1 'font-lock-variable-name-face)
1079 ;; field names
1080 "*Default expressions to highlight in BibTeX mode.")) 1133 "*Default expressions to highlight in BibTeX mode."))
1081;; now all needed patterns are defined 1134;; now all needed patterns are defined
1082 1135
@@ -1096,9 +1149,9 @@ the value of `bibtex-text-indentation', minus 2."
1096 1149
1097(defun bibtex-member-of-regexp (string list) 1150(defun bibtex-member-of-regexp (string list)
1098 ;; Return non-nil if STRING is exactly matched by an element of 1151 ;; Return non-nil if STRING is exactly matched by an element of
1099 ;; LIST (case ignored). The value is actually the tail of LIST whose 1152 ;; LIST. The value is actually the tail of LIST whose
1100 ;; car matches STRING. 1153 ;; car matches STRING.
1101 (let ((case-fold-search t)) 1154 (let (case-fold-search)
1102 (while 1155 (while
1103 (and list (not (string-match (concat "^" (car list) "$") string))) 1156 (and list (not (string-match (concat "^" (car list) "$") string)))
1104 (setq list (cdr list))) 1157 (setq list (cdr list)))
@@ -1734,8 +1787,8 @@ the value of `bibtex-text-indentation', minus 2."
1734 1787
1735(defun bibtex-autokey-get-namefield (min max) 1788(defun bibtex-autokey-get-namefield (min max)
1736 ;; returns the contents of the name field of the current entry 1789 ;; returns the contents of the name field of the current entry
1737 ;; does some modifications based on 1790 ;; does some modifications based on `bibtex-autokey-name-change-strings'
1738 ;; `bibtex-autokey-name-change-strings' 1791 ;; and removes newlines unconditionally
1739 (goto-char min) 1792 (goto-char min)
1740 (let ((case-fold-search t)) 1793 (let ((case-fold-search t))
1741 (if (re-search-forward 1794 (if (re-search-forward
@@ -1745,7 +1798,7 @@ the value of `bibtex-text-indentation', minus 2."
1745 (buffer-substring-no-properties 1798 (buffer-substring-no-properties
1746 (1+ (match-beginning (+ bibtex-text-in-cfield 2))) 1799 (1+ (match-beginning (+ bibtex-text-in-cfield 2)))
1747 (1- (match-end (+ bibtex-text-in-cfield 2)))) 1800 (1- (match-end (+ bibtex-text-in-cfield 2))))
1748 bibtex-autokey-name-change-strings) 1801 (append bibtex-autokey-name-change-strings '(("\n" " "))))
1749 ""))) 1802 "")))
1750 1803
1751(defun bibtex-autokey-get-names (namefield) 1804(defun bibtex-autokey-get-names (namefield)
@@ -1803,9 +1856,7 @@ the value of `bibtex-text-indentation', minus 2."
1803 ;; --> take only the first one 1856 ;; --> take only the first one
1804 (substring lastname 0 (match-beginning 0)) 1857 (substring lastname 0 (match-beginning 0))
1805 lastname))) 1858 lastname)))
1806 (if bibtex-autokey-preserve-case 1859 (funcall bibtex-autokey-name-case-convert usename)))
1807 usename
1808 (downcase usename))))
1809 1860
1810(defun bibtex-autokey-get-namelist (namefield) 1861(defun bibtex-autokey-get-namelist (namefield)
1811 ;; gets namefield, performs abbreviations on the last parts, and 1862 ;; gets namefield, performs abbreviations on the last parts, and
@@ -1824,10 +1875,12 @@ the value of `bibtex-text-indentation', minus 2."
1824 (let ((case-fold-search t)) 1875 (let ((case-fold-search t))
1825 (goto-char min) 1876 (goto-char min)
1826 (if (re-search-forward 1877 (if (re-search-forward
1827 (bibtex-cfield "year" "[0-9]+") max t) 1878 (bibtex-cfield "year" bibtex-field-text) max t)
1828 (buffer-substring-no-properties 1879 (let ((year (buffer-substring-no-properties
1829 (match-beginning bibtex-text-in-cfield) 1880 (match-beginning bibtex-text-in-cfield)
1830 (match-end bibtex-text-in-cfield)) 1881 (match-end bibtex-text-in-cfield))))
1882 (string-match "[^0-9]*\\([0-9]+\\)" year)
1883 (substring year (match-beginning 1) (match-end 1)))
1831 (if bibtex-autokey-year-use-crossref-entry 1884 (if bibtex-autokey-year-use-crossref-entry
1832 (let ((crossref-field 1885 (let ((crossref-field
1833 (progn 1886 (progn
@@ -1880,14 +1933,12 @@ the value of `bibtex-text-indentation', minus 2."
1880 titlefield))) 1933 titlefield)))
1881 1934
1882(defun bibtex-autokey-get-titles (titlestring) 1935(defun bibtex-autokey-get-titles (titlestring)
1883 ;; gathers capitalized words from titlestring into a list. Ignores 1936 ;; gathers words from titlestring into a list. Ignores
1884 ;; specific words at the beginning and use only a specific amount of 1937 ;; specific words and uses only a specific amount of words.
1885 ;; words
1886 (let (case-fold-search 1938 (let (case-fold-search
1887 titlewords 1939 titlewords
1888 titlewords-extra 1940 titlewords-extra
1889 (counter 0) 1941 (counter 0))
1890 (first t))
1891 (while (and 1942 (while (and
1892 (not (equal titlestring "")) 1943 (not (equal titlestring ""))
1893 (or 1944 (or
@@ -1895,40 +1946,32 @@ the value of `bibtex-text-indentation', minus 2."
1895 (< counter 1946 (< counter
1896 (+ bibtex-autokey-titlewords 1947 (+ bibtex-autokey-titlewords
1897 bibtex-autokey-titlewords-stretch)))) 1948 bibtex-autokey-titlewords-stretch))))
1898 (if (string-match "\\b[A-Z][A-Za-z0-9]*" titlestring) 1949 (if (string-match "\\b\\w+" titlestring)
1899 (let* ((end-match (match-end 0)) 1950 (let* ((end-match (match-end 0))
1900 (titleword 1951 (titleword
1901 (if bibtex-autokey-preserve-case 1952 (substring titlestring (match-beginning 0) end-match)))
1902 (substring 1953 (if (bibtex-member-of-regexp
1903 titlestring (match-beginning 0) end-match) 1954 titleword
1904 (downcase 1955 bibtex-autokey-titleword-ignore)
1905 (substring 1956 (setq counter (1- counter))
1906 titlestring (match-beginning 0) end-match))))) 1957 (setq
1907 (if (or 1958 titleword
1908 (not (numberp bibtex-autokey-titlewords)) 1959 (funcall bibtex-autokey-titleword-case-convert titleword))
1909 (< counter bibtex-autokey-titlewords)) 1960 (if (or (not (numberp bibtex-autokey-titlewords))
1910 (if (and 1961 (< counter bibtex-autokey-titlewords))
1911 first 1962 (setq titlewords (append titlewords (list titleword)))
1912 (bibtex-member-of-regexp 1963 (setq titlewords-extra
1913 titleword 1964 (append titlewords-extra (list titleword)))))
1914 bibtex-autokey-titleword-first-ignore))
1915 (setq counter -1)
1916 (setq
1917 titlewords (append titlewords (list titleword))))
1918 (setq
1919 titlewords-extra
1920 (append titlewords-extra (list titleword))))
1921 (setq 1965 (setq
1922 titlestring (substring titlestring end-match))) 1966 titlestring (substring titlestring end-match)))
1923 (setq titlestring "")) 1967 (setq titlestring ""))
1924 (setq first nil 1968 (setq counter (1+ counter)))
1925 counter (1+ counter))) 1969 (if (string-match "\\b\\w+" titlestring)
1926 (if (string-match "\\b[A-Z][^ ]*\\b" titlestring)
1927 titlewords 1970 titlewords
1928 (append titlewords titlewords-extra)))) 1971 (append titlewords titlewords-extra))))
1929 1972
1930(defun bibtex-autokey-get-titlelist (titlestring) 1973(defun bibtex-autokey-get-titlelist (titlestring)
1931 ;; returns all capitalized words in titlestring as a list 1974 ;; returns all words in titlestring as a list
1932 ;; does some abbreviation on the found words 1975 ;; does some abbreviation on the found words
1933 (mapcar 1976 (mapcar
1934 (lambda (titleword) 1977 (lambda (titleword)
@@ -1943,69 +1986,79 @@ the value of `bibtex-text-indentation', minus 2."
1943 (bibtex-autokey-get-titles titlestring))) 1986 (bibtex-autokey-get-titles titlestring)))
1944 1987
1945(defun bibtex-generate-autokey () 1988(defun bibtex-generate-autokey ()
1946 "Automatically generate a key from the author/editor and the title field. 1989 "Generates automatically a key from the author/editor and the title field.
1947This will only work for entries where each field begins on a separate line. 1990This will only work for entries where each field begins on a separate line.
1948The generation algorithm works as follows: 1991The generation algorithm works as follows:
1949 1. Use the value of `bibtex-autokey-prefix-string' as a prefix. 1992 1. Use the value of `bibtex-autokey-prefix-string' as a prefix.
1950 2. If there is a non-empty author (preferred) or editor field, 1993 2. If there is a non-empty author (preferred) or editor field,
1951 use it as the name part of the key. 1994 use it as the name part of the key.
1952 3. Change any substring found in `bibtex-autokey-name-change-strings' 1995 3. Change any substring found in
1953 to the corresponding new one (see documentation of this variable for 1996 `bibtex-autokey-name-change-strings' to the corresponding new
1954 further detail). 1997 one (see documentation of this variable for further detail).
1955 4. For each of at least the first `bibtex-autokey-names' names in 1998 4. For every of at least first `bibtex-autokey-names' names in
1956 the name field, determine the last name. If there are at most 1999 the name field, determine the last name. If there are maximal
1957 `bibtex-autokey-names' + `bibtex-autokey-names-stretch' 2000 `bibtex-autokey-names' + `bibtex-autokey-names-stretch'
1958 names, all names are used. 2001 names, all names are used.
1959 5. From each last name, take at least `bibtex-autokey-name-length' 2002 5. From every last name, take at least
1960 characters (abort only after a consonant or at a word end). 2003 `bibtex-autokey-name-length' characters (abort only after a
1961 6. Unless `bibtex-autokey-preserve-case' is non-nil, convert all 2004 consonant or at a word end).
1962 last names to lowercase letters. 2005 6. Convert all last names according to the conversion function
1963 7. Build the name part of the key by concatenating all abbreviated last 2006 `bibtex-autokey-name-case-convert'.
1964 names with the string `bibtex-autokey-name-separator' between any two. 2007 7. Build the name part of the key by concatenating all
1965 If there are more names than are used in the name part, prepend the 2008 abbreviated last names with the string
1966 string contained in `bibtex-autokey-additional-names'. 2009 `bibtex-autokey-name-separator' between any two. If there are
2010 more names than are used in the name part, prepend the string
2011 contained in `bibtex-autokey-additional-names'.
1967 8. Build the year part of the key by truncating the contents of 2012 8. Build the year part of the key by truncating the contents of
1968 the year field to the rightmost `bibtex-autokey-year-length' 2013 the year field to the rightmost `bibtex-autokey-year-length'
1969 digits (useful values are 2 and 4). If the year field is 2014 digits (useful values are 2 and 4). If the year field is
1970 absent, but the entry has a valid crossref field and the 2015 absent, but the entry has a valid crossref field and the
1971 variable `bibtex-autokey-year-use-crossref-entry' is non-nil, 2016 variable `bibtex-autokey-year-use-crossref-entry' is non-nil,
1972 use the year field of the crossreferenced entry instead. 2017 use the year field of the crossreferenced entry instead.
1973 9. For the title part of the key change the contents of the title field 2018 9. For the title part of the key change the contents of the
1974 of the reference according to `bibtex-autokey-titleword-change-strings' 2019 title field of the reference according to
1975 to the corresponding new one (see documentation of this variable for 2020 `bibtex-autokey-titleword-change-strings' to the
2021 corresponding new one (see documentation of this variable for
1976 further detail). 2022 further detail).
197710. Abbreviate the result to the string up to (but not including) 202310. Abbreviate the result to the string up to (but not including)
1978 the first occurrence of a regexp matched by the items of 2024 the first occurrence of a regexp matched by the items of
1979 `bibtex-autokey-title-terminators' and delete the first word if it 2025 `bibtex-autokey-title-terminators' and delete those words which
1980 appears in `bibtex-autokey-titleword-first-ignore'. Use at least the 2026 appear in `bibtex-autokey-titleword-ignore'.
1981 first `bibtex-autokey-titlewords' capitalized words from this 2027 Build the title part of the key by using at least the first
1982 abbreviated title. If the abbreviated title ends after at most 2028 `bibtex-autokey-titlewords' words from this
1983 `bibtex-autokey-titlewords' + `bibtex-autokey-titlewords-stretch' 2029 abbreviated title. If the abbreviated title ends after
1984 capitalized words, all capitalized words from the abbreviated title are 2030 maximal `bibtex-autokey-titlewords' +
1985 used. 2031 `bibtex-autokey-titlewords-stretch' words, all
198611. Unless `bibtex-autokey-preserve-case' is non-nil, convert all 2032 words from the abbreviated title are used.
1987 used title words to lowercase letters. 203311. Convert all used titlewords according to the conversion function
198812. For each word that appears in `bibtex-autokey-titleword-abbrevs', use 2034 `bibtex-autokey-titleword-case-convert'.
1989 the corresponding abbreviation (see documentation of this variable for 203512. For every used title word that appears in
1990 further detail). 2036 `bibtex-autokey-titleword-abbrevs' use the corresponding
199113. From each title word not generated by an abbreviation, take at least 2037 abbreviation (see documentation of this variable for further
1992 `bibtex-autokey-titleword-length' characters (abort only after a 2038 detail).
1993 consonant or at a word end). 203913. From every title word not generated by an abbreviation, take
199414. Build the title part of the key by concatenating all abbreviated title 2040 at least `bibtex-autokey-titleword-length' characters (abort
1995 words with the string `bibtex-autokey-titleword-separator' between any 2041 only after a consonant or at a word end).
1996 two. 204214. Build the title part of the key by concatenating all
199715. Finally, to get the key, concatenate `bibtex-autokey-prefix-string'; 2043 abbreviated title words with the string
1998 the name part; `bibtex-autokey-name-year-separator' if the name and year 2044 `bibtex-autokey-titleword-separator' between any two.
1999 are both nonempty; the year part; `bibtex-autokey-year-title-separator' 204515. At least, to get the key, concatenate
2000 if the title and either name or year are nonempty; and the title part. 2046 `bibtex-autokey-prefix-string', the name part, the year part
200116. If the value of `bibtex-autokey-before-presentation-hook' is non-nil, 2047 and the title part with `bibtex-autokey-name-year-separator'
2002 it must be a function taking one argument. This function is then 2048 between the name part and the year part if both are non-empty
2003 called with the generated key as the argument. The return value of 2049 and `bibtex-autokey-year-title-separator' between the year
2004 this function (a string) is used as the key. 2050 part and the title part if both are non-empty. If the year
2051 part is empty, but not the other two parts,
2052 `bibtex-autokey-year-title-separator' is used as well.
205316. If the value of `bibtex-autokey-before-presentation-function'
2054 is non-nil, it must be a function taking one argument. This
2055 function is then called with the generated key as the
2056 argument. The return value of this function (a string) is
2057 used as the key.
200517. If the value of `bibtex-autokey-edit-before-use' is non-nil, 205817. If the value of `bibtex-autokey-edit-before-use' is non-nil,
2006 the key is then presented in the minibuffer to the user, where 2059 the key is then presented in the minibuffer to the user,
2007 it can be edited. The key given by the user is then used." 2060 where it can be edited. The key given by the user is then
2008 2061 used."
2009 (let* ((pnt (point)) 2062 (let* ((pnt (point))
2010 (min (bibtex-beginning-of-entry)) 2063 (min (bibtex-beginning-of-entry))
2011 (max (bibtex-end-of-entry)) 2064 (max (bibtex-end-of-entry))
@@ -2062,10 +2115,10 @@ The generation algorithm works as follows:
2062 (equal titlepart ""))) 2115 (equal titlepart "")))
2063 bibtex-autokey-year-title-separator) 2116 bibtex-autokey-year-title-separator)
2064 titlepart))) 2117 titlepart)))
2065 (if bibtex-autokey-before-presentation-hook 2118 (if bibtex-autokey-before-presentation-function
2066 (setq 2119 (setq
2067 autokey 2120 autokey
2068 (funcall bibtex-autokey-before-presentation-hook autokey))) 2121 (funcall bibtex-autokey-before-presentation-function autokey)))
2069 (goto-char pnt) 2122 (goto-char pnt)
2070 autokey)) 2123 autokey))
2071 2124
@@ -2141,8 +2194,8 @@ The generation algorithm works as follows:
2141 t))))) 2194 t)))))
2142 2195
2143(defun bibtex-parse-buffers-stealthily () 2196(defun bibtex-parse-buffers-stealthily ()
2144 ;; Called by run-with-idle-timer. Whenever emacs has been idle for 2197 ;; Called by bibtex-run-with-idle-timer. Whenever emacs has been idle
2145 ;; bibtex-parse-keys-timeout seconds, all BibTeX buffers (starting 2198 ;; for bibtex-parse-keys-timeout seconds, all BibTeX buffers (starting
2146 ;; with the current) are parsed. 2199 ;; with the current) are parsed.
2147 (let ((buffers (buffer-list))) 2200 (let ((buffers (buffer-list)))
2148 (save-excursion 2201 (save-excursion
@@ -2497,21 +2550,21 @@ non-nil.
2497 filename)))) 2550 filename))))
2498 bibtex-string-files) 2551 bibtex-string-files)
2499 (if bibtex-maintain-sorted-entries 2552 (if bibtex-maintain-sorted-entries
2500 (run-with-idle-timer 2553 (bibtex-run-with-idle-timer
2501 0 nil 2554 1 nil
2502 (lambda () 2555 (lambda ()
2503 (bibtex-parse-keys nil t t)))) 2556 (bibtex-parse-keys nil t t))))
2504 ;; to get buffer parsed once if everything else (including things 2557 ;; to get buffer parsed once if everything else (including things
2505 ;; installed in bibtex-mode-hook) has done its work 2558 ;; installed in bibtex-mode-hook) has done its work
2506 (if (not bibtex-parse-idle-timer) 2559 (if (not bibtex-parse-idle-timer)
2507 (setq bibtex-parse-idle-timer 2560 (setq bibtex-parse-idle-timer
2508 (run-with-idle-timer 2561 (bibtex-run-with-idle-timer
2509 bibtex-parse-keys-timeout t 2562 bibtex-parse-keys-timeout t
2510 'bibtex-parse-buffers-stealthily))) 2563 'bibtex-parse-buffers-stealthily)))
2511 ;; Install stealthy parse function if not already installed 2564 ;; Install stealthy parse function if not already installed
2512 (set (make-local-variable 'paragraph-start) "[ \f\n\t]*$") 2565 (set (make-local-variable 'paragraph-start) "[ \f\n\t]*$")
2513 (set (make-local-variable 'comment-start) "@Comment ") 2566 (set (make-local-variable 'comment-start) bibtex-comment-start)
2514 (set (make-local-variable 'comment-start-skip) "@Comment ") 2567 (set (make-local-variable 'comment-start-skip) bibtex-comment-start)
2515 (set (make-local-variable 'comment-column) 0) 2568 (set (make-local-variable 'comment-column) 0)
2516 (set (make-local-variable 'normal-auto-fill-function) 2569 (set (make-local-variable 'normal-auto-fill-function)
2517 'bibtex-do-auto-fill) 2570 'bibtex-do-auto-fill)
@@ -2531,6 +2584,9 @@ non-nil.
2531 (setq imenu-generic-expression 2584 (setq imenu-generic-expression
2532 (list (list nil bibtex-reference-head bibtex-key-in-head))) 2585 (list (list nil bibtex-reference-head bibtex-key-in-head)))
2533 (setq imenu-case-fold-search t) 2586 (setq imenu-case-fold-search t)
2587 ;; XEmacs needs easy-menu-add, Emacs does not care
2588 (easy-menu-add bibtex-edit-menu)
2589 (easy-menu-add bibtex-entry-menu)
2534 (run-hooks 'bibtex-mode-hook)) 2590 (run-hooks 'bibtex-mode-hook))
2535 2591
2536(defun bibtex-submit-bug-report () 2592(defun bibtex-submit-bug-report ()
@@ -2579,6 +2635,7 @@ non-nil.
2579 'bibtex-autokey-additional-names 2635 'bibtex-autokey-additional-names
2580 'bibtex-autokey-transcriptions 2636 'bibtex-autokey-transcriptions
2581 'bibtex-autokey-name-change-strings 2637 'bibtex-autokey-name-change-strings
2638 'bibtex-autokey-name-case-convert
2582 'bibtex-autokey-name-length 2639 'bibtex-autokey-name-length
2583 'bibtex-autokey-name-separator 2640 'bibtex-autokey-name-separator
2584 'bibtex-autokey-year-length 2641 'bibtex-autokey-year-length
@@ -2586,16 +2643,16 @@ non-nil.
2586 'bibtex-autokey-titlewords 2643 'bibtex-autokey-titlewords
2587 'bibtex-autokey-title-terminators 2644 'bibtex-autokey-title-terminators
2588 'bibtex-autokey-titlewords-stretch 2645 'bibtex-autokey-titlewords-stretch
2589 'bibtex-autokey-titleword-first-ignore 2646 'bibtex-autokey-titleword-ignore
2647 'bibtex-autokey-titleword-case-convert
2590 'bibtex-autokey-titleword-abbrevs 2648 'bibtex-autokey-titleword-abbrevs
2591 'bibtex-autokey-titleword-change-strings 2649 'bibtex-autokey-titleword-change-strings
2592 'bibtex-autokey-titleword-length 2650 'bibtex-autokey-titleword-length
2593 'bibtex-autokey-titleword-separator 2651 'bibtex-autokey-titleword-separator
2594 'bibtex-autokey-name-year-separator 2652 'bibtex-autokey-name-year-separator
2595 'bibtex-autokey-year-title-separator 2653 'bibtex-autokey-year-title-separator
2596 'bibtex-autokey-preserve-case
2597 'bibtex-autokey-edit-before-use 2654 'bibtex-autokey-edit-before-use
2598 'bibtex-autokey-before-presentation-hook 2655 'bibtex-autokey-before-presentation-function
2599 ;; possible bugs regarding automatic labels 2656 ;; possible bugs regarding automatic labels
2600 'bibtex-entry-field-alist 2657 'bibtex-entry-field-alist
2601 ;; possible format error 2658 ;; possible format error
@@ -2887,11 +2944,11 @@ If mark is active it counts entries in region, if not in whole buffer."
2887 (interactive "P") 2944 (interactive "P")
2888 (let ((pnt (point)) 2945 (let ((pnt (point))
2889 (start-point 2946 (start-point
2890 (if mark-active 2947 (if (bibtex-mark-active)
2891 (region-beginning) 2948 (region-beginning)
2892 (bibtex-beginning-of-first-entry))) 2949 (bibtex-beginning-of-first-entry)))
2893 (end-point 2950 (end-point
2894 (if mark-active 2951 (if (bibtex-mark-active)
2895 (region-end) 2952 (region-end)
2896 (point-max))) 2953 (point-max)))
2897 (number 0) 2954 (number 0)
@@ -2903,7 +2960,7 @@ If mark is active it counts entries in region, if not in whole buffer."
2903 (bibtex-map-entries 2960 (bibtex-map-entries
2904 (lambda (current) 2961 (lambda (current)
2905 (setq number (1+ number))))) 2962 (setq number (1+ number)))))
2906 (message (concat (if mark-active "Region" "Buffer") 2963 (message (concat (if (bibtex-mark-active) "Region" "Buffer")
2907 " contains %d entries.") number) 2964 " contains %d entries.") number)
2908 (goto-char pnt))) 2965 (goto-char pnt)))
2909 2966
@@ -3080,11 +3137,11 @@ Returns t if test was successful, nil otherwise."
3080 "\\)")) 3137 "\\)"))
3081 (pnt (point)) 3138 (pnt (point))
3082 (start-point 3139 (start-point
3083 (if mark-active 3140 (if (bibtex-mark-active)
3084 (region-beginning) 3141 (region-beginning)
3085 (bibtex-beginning-of-first-entry))) 3142 (bibtex-beginning-of-first-entry)))
3086 (end-point 3143 (end-point
3087 (if mark-active 3144 (if (bibtex-mark-active)
3088 (region-end) 3145 (region-end)
3089 (point-max)))) 3146 (point-max))))
3090 (save-restriction 3147 (save-restriction
@@ -3261,7 +3318,7 @@ Returns t if test was successful, nil otherwise."
3261 (other-window -1) 3318 (other-window -1)
3262 ;; return nil 3319 ;; return nil
3263 nil) 3320 nil)
3264 (if mark-active 3321 (if (bibtex-mark-active)
3265 (message "Region is syntactically correct") 3322 (message "Region is syntactically correct")
3266 (message "Buffer is syntactically correct")) 3323 (message "Buffer is syntactically correct"))
3267 t))) 3324 t)))
@@ -3669,14 +3726,14 @@ If mark is active it reformats entries in region, if not in whole buffer."
3669 bibtex-autokey-edit-before-use 3726 bibtex-autokey-edit-before-use
3670 (bibtex-sort-ignore-string-entries t) 3727 (bibtex-sort-ignore-string-entries t)
3671 (start-point 3728 (start-point
3672 (if mark-active 3729 (if (bibtex-mark-active)
3673 (region-beginning) 3730 (region-beginning)
3674 (progn 3731 (progn
3675 (bibtex-beginning-of-first-entry) 3732 (bibtex-beginning-of-first-entry)
3676 (bibtex-skip-to-valid-entry) 3733 (bibtex-skip-to-valid-entry)
3677 (point)))) 3734 (point))))
3678 (end-point 3735 (end-point
3679 (if mark-active 3736 (if (bibtex-mark-active)
3680 (region-end) 3737 (region-end)
3681 (point-max))) 3738 (point-max)))
3682 (valid-bibtex-entry 3739 (valid-bibtex-entry
@@ -3733,7 +3790,7 @@ non-nil, read options for reformatting entries from minibuffer."
3733 (message 3790 (message
3734 "If errors occur, correct them and call `bibtex-convert-alien' again") 3791 "If errors occur, correct them and call `bibtex-convert-alien' again")
3735 (sit-for 5 nil t) 3792 (sit-for 5 nil t)
3736 (if (let (mark-active 3793 (if (let ((bibtex-mark-active)
3737 bibtex-maintain-sorted-entries) 3794 bibtex-maintain-sorted-entries)
3738 (bibtex-validate)) 3795 (bibtex-validate))
3739 (progn 3796 (progn