257
|
1 ;;; BibTeX mode for GNU Emacs
|
|
2 ;; Copyright (C) 1985, 1986, 1987, 1990 Free Software Foundation, Inc.
|
|
3
|
|
4 ;; This file is part of GNU Emacs.
|
|
5
|
|
6 ;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
7 ;; it under the terms of the GNU General Public License as published by
|
|
8 ;; the Free Software Foundation; either version 1, or (at your option)
|
|
9 ;; any later version.
|
|
10
|
|
11 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
12 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 ;; GNU General Public License for more details.
|
|
15
|
|
16 ;; You should have received a copy of the GNU General Public License
|
|
17 ;; along with GNU Emacs; see the file COPYING. If not, write to
|
|
18 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
19
|
561
|
20 ;;; Mike Newton (newton@gumby.cs.caltech.edu) 92.2.11
|
|
21 ;;; * Fixed bibtex-field string to allow things like:
|
|
22 ;;; author = "{S}schr\"odinger" or
|
|
23 ;;; author = "{S}schr\"{o}dinger" or
|
|
24 ;;; author = "{S}schr{\"o}dinger" or
|
|
25 ;;; NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
|
|
26 ;;; NOTE: This is the last update I plan to do.
|
|
27 ;;; NOTE: the previous version was submitted and, according to RMS,
|
|
28 ;;; accepted as the release version for ver 19.
|
|
29 ;;; NOTE: PLEASE DO NOT SEND ME ANY MORE 'PLEASE ADD THIS' MESSAGES.
|
|
30 ;;; NOTE: I am no longer taking care of this package.
|
|
31 ;;; NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
|
|
32
|
|
33 ;;; Mike Newton (newton@gumby.cs.caltech.edu) 91.1.24
|
|
34 ;;; * bibtex-make-optional-field : modified to make fields align up after
|
|
35 ;;; the OPT's have been removed.
|
|
36 ;;; * bibtex-make-optional-field : modified to check bibtex-use-OPT-prefix
|
|
37 ;;; * bibtex-make*field : modified to call new procedure:
|
|
38 ;;; * bibtex-insert-field-delimeters : which does delimeter insertion based on
|
|
39 ;;; * bibtex-curly-delimeters : a list of atoms
|
|
40 ;;; * fixed spelling of bibtex-name-alignment wherever used
|
|
41 ;;; * bibtex-inside-field : allows '}'s at end
|
|
42 ;;; * bibtex-find-text : allows '{' and '}'s at start or end
|
|
43 ;;; * bibtex-enclosing-regexp fixed for case where start-point was at end of
|
|
44 ;;; pattern.
|
|
45 ;;; * bibtex-clean-entry : allow bibtex-save-OPT to save some optional fields
|
|
46 ;;; * bibtex-move-outside-of-entry : could overwrite first line of a following
|
|
47 ;;; comment or other text if it did not look like a bibtex entry
|
|
48
|
257
|
49 ;;; Mike Newton (newton@gumby.cs.caltech.edu) 91.1.20
|
|
50 ;;; * bibtex.el/bibtex-mode : updated comments to indicate new use of
|
|
51 ;;; address, add minor explanations and fix small omissions.
|
|
52 ;;; * bibtex.el/bibtex-entry : fixed spelling of variable
|
|
53
|
|
54 ;;; Mike Newton (newton@gumby.cs.caltech.edu) 90.11.17
|
|
55 ;;; * Handle items like
|
|
56 ;;; title = poft # "Fifth Tri-quaterly" # random-conf,
|
|
57 ;;; and title = {This title is inside curlies}
|
|
58 ;;; * added user settable, always present, optional fields
|
|
59 ;;; * fixed 'bibtex-find-it's doc string's location
|
|
60 ;;; * bibtex-field-text made more general (it wouldnt handle the # construct)
|
|
61 ;;; and it now handles a small subset of the {} cases
|
|
62 ;;; * put DEA thesis back in (why get rid of good code?)
|
|
63 ;;; * merged into release 19 version code
|
|
64 ;;; * if cross-ref'ing is on, put 'pages' near top of OPTs, as the other
|
|
65 ;;; entries are unlikely to be used.
|
|
66 ;;; * skip-whitespace replaced by skip-chars-forward (also done
|
|
67 ;;; by Marc Shairo)
|
|
68
|
|
69 ;;; Bengt Martensson, March 6
|
|
70 ;;; Adapted to Bibtex 0.99 by updating the optional fields according
|
|
71 ;;; to the document BibTeXing, Oren Patashnik, dated January 31, 1988.
|
584
|
72 ;;; Updated documentation strings accordingly. Added .
|
257
|
73 ;;; If bibtex-include-OPT-crossref is non-nil, every entry will have
|
|
74 ;;; an OPTcrossref field, analogously for bibtex-include-OPTkey and
|
|
75 ;;; bibtex-include-OPTannote. Added bibtex-preamble, bound to ^C^EP,
|
|
76 ;;; and also found in X- and sun-menus. Cleaned up the sun-menu
|
|
77 ;;; stuff, and made it more uniform with the X-menu stuff. Marc: I
|
|
78 ;;; strongly suspect that I broke your parsing... (Or, more
|
|
79 ;;; correctly, BibTeX 0.99 broke it.)
|
|
80 ;;; Added bibtex-clean-entry-zap-empty-opts, defvar'd to t. If it
|
|
81 ;;; is nil, bibtex-clean-entry will leave empty optional fields alone.
|
|
82
|
|
83 ;;; Marc Shapiro 1-feb-89: integrated changes by Bengt Martensson 88-05-06:
|
|
84 ;;; Added Sun menu support. Locally bound to right mouse button in
|
|
85 ;;; bibtex-mode. Emacs 18.49 allows local mouse bindings!!
|
|
86 ;;; Commented out DEAthesis.
|
|
87
|
|
88 ;;; Marc Shapiro 6-oct-88
|
|
89 ;;; * use indent-to-column instead of inserting tabs (changes to
|
|
90 ;;; bibtex-entry, bibtex-make-entry, bibtex-make-OPT-entry, renamed to
|
|
91 ;;; bibtex-make-optional-entry)
|
|
92 ;;; * C-c C-k deletes the current OPT entry entirely
|
|
93 ;;; * C-c C-d replaces text of field with ""
|
|
94 ;;; * renamed bibtex-find-it to bibtex-find-text. With arg, now goes to
|
|
95 ;;; start of text. Fixed bugs in it.
|
|
96
|
|
97 ;;; Marc Shapiro 23-sep-88
|
|
98 ;;; * bibtex-clean-entry moves past end of entry.
|
|
99 ;;; * bibtex-clean-entry signals mandatory fields left empty.
|
|
100
|
|
101 ;;; Marc Shapiro 18-jul-88
|
|
102 ;;; * Moved all the entry type keystrokes to "C-c C-e something" (instead of
|
|
103 ;;; "C-c something" previously) to make room for more. C-c C-e is
|
|
104 ;;; supposed to stand for "entry" [idea taken from mail-mode]. Moved
|
|
105 ;;; bibtex-pop-previous to C-c C-p and bibtex-pop-next to C-c C-n.
|
|
106 ;;; * removed binding for "\e[25~"
|
|
107 ;;; * replaced bibtex-clean-optionals by bibtex-clean-entry, bound to
|
|
108 ;;; C-c C-c
|
|
109
|
|
110 ;;; Marc Shapiro 13-jul-88 [based on ideas by Sacha Krakowiak of IMAG]
|
|
111 ;;; * bibtex-pop-previous replaces current field with value of
|
|
112 ;;; similar field in previous entry. May be called n times in a row
|
|
113 ;;; (or with arg n) to pop similar field of n'th previous entry.
|
|
114 ;;; There is also a bibtex-pop-next to get similar field of next
|
|
115 ;;; entry.
|
|
116 ;;; * C-c C-k now kills all empty optional fields of current entry, and
|
|
117 ;;; removes "OPT" for those optional fields which have text.
|
|
118
|
|
119 ;;; Marc Shapiro 14-dec-87
|
|
120 ;;; Cosmetic fixes. Fixed small bug in bibtex-move-outside-of-entry.
|
|
121 ;;; Skip Montanaro <steinmetz!sprite!montanaro> 7-dec-87, Shapiro 10-dec-87
|
|
122 ;;; before inserting an entry, make sure we are outside of a bib entry
|
|
123 ;;; Marc Shapiro 3-nov-87
|
|
124 ;;; addition for France: DEAthesis
|
|
125 ;;; Marc Shapiro 19-oct-1987
|
|
126 ;;; add X window menu option; bug fixes. TAB, LFD, C-c " and C-c C-o now
|
|
127 ;;; behave consistently; deletion never occurs blindly.
|
|
128 ;;; Marc Shapiro <shapiro@inria.inria.fr> 15-oct-1986
|
|
129 ;;; align long lines nicely; C-c C-o checks for the "OPT" string;
|
|
130 ;;; TAB goes to the end of the string; use lower case; use
|
|
131 ;;; run-hooks
|
|
132
|
|
133 ;;; Bengt Martensson <ubrinf!mond!bengt> 87-06-28
|
|
134 ;;; (Bengt Martensson <bengt@mathematik.uni-Bremen.de> 87-06-28)
|
|
135 ;;; Original version
|
|
136
|
|
137 ;;; NOTE by Marc Shapiro, 14-dec-87:
|
|
138 ;;; (bibtex-x-environment) binds an X menu for bibtex mode to x-button-c-right.
|
|
139 ;;; Trouble is, in Emacs 18.44 you can't have a mode-specific mouse binding,
|
|
140 ;;; so it will remain active in all windows. Yuck!
|
|
141
|
|
142 (defvar bibtex-mode-syntax-table nil "")
|
|
143 (defvar bibtex-mode-abbrev-table nil "")
|
|
144 (define-abbrev-table 'bibtex-mode-abbrev-table ())
|
|
145 (defvar bibtex-mode-map (make-sparse-keymap) "")
|
|
146 (defvar bibtex-pop-previous-search-point nil
|
561
|
147 "Next point where bibtex-pop-previous should start looking for a similar
|
257
|
148 entry.")
|
|
149 (defvar bibtex-pop-next-search-point nil
|
561
|
150 "Next point where bibtex-pop-next should start looking for a similar
|
257
|
151 entry.")
|
|
152
|
|
153 (defvar bibtex-clean-entry-zap-empty-opts t
|
561
|
154 "*If non-nil, bibtex-clean-entry will delete all empty optional fields.")
|
257
|
155 (defvar bibtex-include-OPTcrossref t
|
561
|
156 "*If non-nil, all entries will have an OPTcrossref field.")
|
257
|
157 (defvar bibtex-include-OPTkey t
|
561
|
158 "*If non-nil, all entries will have an OPTkey field.")
|
257
|
159 (defvar bibtex-include-OPTannote t
|
561
|
160 "*If non-nil, all entries will have an OPTannote field.")
|
|
161 (defvar bibtex-use-OPT-prefix t
|
|
162 "*If non-nil, put OPT string before optionals. Usually desired!")
|
|
163 (defvar bibtex-save-OPT nil
|
|
164 "*List of atoms (representing strings) which are optional fields that
|
|
165 should not be deleted if null.")
|
|
166 (defvar bibtex-curly-delimeters nil
|
|
167 "List of atoms representing strings (in any case) that should have curly
|
|
168 braces used as their delimeters instead of double quotes.")
|
|
169
|
257
|
170
|
|
171 ;; note: the user should be allowed to have their own list of always
|
|
172 ;; available optional fields. exs: "keywords" "categories"
|
|
173 (defvar bibtex-mode-user-optional-fields nil ;no default value
|
561
|
174 "*List of optional fields that user want to have as always present
|
|
175 when making a bibtex entry. One possibility is for ``keywords''")
|
257
|
176
|
|
177
|
|
178 ;;; A bibtex file is a sequence of entries, either string definitions
|
|
179 ;;; or reference entries. A reference entry has a type part, a
|
|
180 ;;; key part, and a comma-separated sequence of fields. A string
|
|
181 ;;; entry has a single field. A field has a left and right part,
|
|
182 ;;; separated by a '='. The left part is the name, the right part is
|
|
183 ;;; the text. Here come the definitions allowing to create and/or parse
|
|
184 ;;; entries and fields:
|
|
185
|
|
186 ;;; fields
|
|
187 (defun bibtex-cfield (name text)
|
561
|
188 "Create a regexp for a bibtex field of name NAME and text TEXT"
|
257
|
189 (concat ",[ \t\n]*\\("
|
|
190 name
|
|
191 "\\)[ \t\n]*=[ \t\n]*\\("
|
|
192 text
|
|
193 "\\)"))
|
|
194 (defconst bibtex-name-in-cfield 1
|
561
|
195 "The regexp subexpression number of the name part in bibtex-cfield.")
|
257
|
196 (defconst bibtex-text-in-cfield 2
|
561
|
197 "The regexp subexpression number of the text part in bibtex-cfield.")
|
257
|
198
|
|
199 (defconst bibtex-field-name "[A-Za-z][---A-Za-z0-9:_+]*"
|
|
200 "Regexp defining the name part of a bibtex field.")
|
|
201
|
|
202 ;; bibtex-field-text must be able to handle
|
|
203 ;; title = "Proc. Fifteenth Annual" # STOC,
|
|
204 ;; month = "10~" # jan,
|
|
205 ;; year = "{\noopsort{1973c}}1981",
|
|
206 ;; month = apr # "-" # may,
|
|
207 ;; key = {Volume-2},
|
|
208 ;; note = "Volume~2 is listed under Knuth \cite{book-full}"
|
|
209 ;; i have added a few of these, but not all! -- MON
|
561
|
210 ;; 92.2.11: also must handle:
|
|
211 ;; author = "{S}schr\"odinger" or
|
|
212 ;; author = "{S}schr\"{o}dinger" or
|
|
213 ;; author = "{S}schr{\"o}dinger" or
|
|
214
|
257
|
215
|
|
216 (defconst bibtex-field-const
|
|
217 "[0-9A-Za-z][---A-Za-z0-9:_+]*"
|
|
218 "Format of a bibtex field constant.")
|
561
|
219
|
|
220 (defconst bibtex-field-string ;;was:(concat "\"[^\"]*[^\\\\]\"\\|\"\"")
|
257
|
221 (concat
|
561
|
222 "\"\\([^\"]*[\\\\][\"]\\)*[^\"]*[^\\\\]\""
|
|
223 "\\|" ;ie: OR
|
|
224 "\"\""
|
|
225 "\\|" ;ie: OR
|
|
226 "\"[^\"]*[^\\\\]\"")
|
|
227 "Match either a \"-d string or an empty string or a plain string.")
|
257
|
228 (defconst bibtex-field-string-or-const
|
|
229 (concat bibtex-field-const "\\|" bibtex-field-string)
|
561
|
230 "Match either bibtex-field-string or bibtex-field-const.")
|
257
|
231
|
|
232 ;(defconst bibtex-field-text
|
|
233 ; "\"[^\"]*[^\\\\]\"\\|\"\"\\|[0-9A-Za-z][---A-Za-z0-9:_+]*"
|
|
234 ; "Regexp defining the text part of a bibtex field: either a string, or an empty string, or a constant.")
|
|
235
|
|
236 (defconst bibtex-field-text
|
|
237 (concat
|
|
238 "\\(" bibtex-field-string-or-const "\\)"
|
|
239 "\\([ \t\n]+#[ \t\n]+\\(" bibtex-field-string-or-const "\\)\\)*\\|"
|
561
|
240 "{[^{}]*[^\\\\]}" "\\|" "{}")
|
257
|
241 "Regexp defining the text part of a bibtex field: either a string, or
|
|
242 an empty string, or a constant followed by one or more # / constant pairs.
|
561
|
243 Also matches simple {...} patterns, including the special case {}.")
|
257
|
244
|
|
245 (defconst bibtex-field
|
|
246 (bibtex-cfield bibtex-field-name bibtex-field-text)
|
|
247 "Regexp defining the format of a bibtex field")
|
|
248
|
|
249 (defconst bibtex-name-in-field bibtex-name-in-cfield
|
561
|
250 "The regexp subexpression number of the name part in bibtex-field")
|
257
|
251 (defconst bibtex-text-in-field bibtex-text-in-cfield
|
561
|
252 "The regexp subexpression number of the text part in bibtex-field")
|
257
|
253
|
|
254 ;;; references
|
|
255 (defconst bibtex-reference-type
|
|
256 "@[A-Za-z]+"
|
561
|
257 "Regexp defining the type part of a bibtex reference entry")
|
|
258
|
257
|
259 (defconst bibtex-reference-head
|
|
260 (concat "^[ \t]*\\("
|
|
261 bibtex-reference-type
|
|
262 "\\)[ \t]*[({]\\("
|
|
263 bibtex-field-name
|
|
264 "\\)")
|
561
|
265 "Regexp defining format of the header line of a bibtex reference entry")
|
257
|
266 (defconst bibtex-type-in-head 1
|
561
|
267 "The regexp subexpression number of the type part in bibtex-reference-head")
|
257
|
268 (defconst bibtex-key-in-head 2
|
561
|
269 "The regexp subexpression number of the key part in
|
|
270 bibtex-reference-head")
|
257
|
271
|
|
272 (defconst bibtex-reference
|
|
273 (concat bibtex-reference-head
|
|
274 "\\([ \t\n]*" bibtex-field "\\)*"
|
|
275 "[ \t\n]*[})]")
|
561
|
276 "Regexp defining the format of a bibtex reference entry")
|
257
|
277 (defconst bibtex-type-in-reference bibtex-type-in-head
|
561
|
278 "The regexp subexpression number of the type part in bibtex-reference")
|
257
|
279 (defconst bibtex-key-in-reference bibtex-key-in-head
|
561
|
280 "The regexp subexpression number of the key part in
|
|
281 bibtex-reference")
|
257
|
282
|
561
|
283 ;;; string definitions. note bibtex-string is a constant and a defun !
|
257
|
284 (defconst bibtex-string
|
|
285 (concat "^[ \t]*@[sS][tT][rR][iI][nN][gG][ \t\n]*[({][ \t\n]*\\("
|
|
286 bibtex-field-name
|
|
287 "\\)[ \t\n]*=[ \t\n]*\\("
|
|
288 bibtex-field-text
|
|
289 "\\)[ \t\n]*[})]")
|
561
|
290 "Regexp defining the format of a bibtex string entry")
|
|
291
|
257
|
292 (defconst bibtex-name-in-string 1
|
561
|
293 "The regexp subexpression of the name part in bibtex-string")
|
257
|
294 (defconst bibtex-text-in-string 2
|
561
|
295 "The regexp subexpression of the text part in bibtex-string")
|
257
|
296
|
561
|
297 (defconst bibtex-name-alignment 2
|
257
|
298 "Alignment for the name part in BibTeX fields.
|
|
299 Chosen on aesthetic grounds only.")
|
|
300
|
|
301 (defconst bibtex-text-alignment (length " organization = ")
|
|
302 "Alignment for the text part in BibTeX fields.
|
|
303 Equal to the space needed for the longest name part.")
|
|
304
|
|
305 ;;; bibtex mode:
|
|
306
|
|
307 (defun bibtex-mode ()
|
|
308 "Major mode for editing bibtex files.
|
|
309
|
|
310 \\{bibtex-mode-map}
|
|
311
|
|
312 A command such as \\[bibtex-Book] will outline the fields for a BibTeX book entry.
|
|
313
|
|
314 The optional fields start with the string OPT, and thus ignored by BibTeX.
|
|
315 The OPT string may be removed from a field with \\[bibtex-remove-OPT].
|
|
316 \\[bibtex-kill-optional-field] kills the current optional field entirely.
|
|
317 \\[bibtex-remove-double-quotes] removes the double-quotes around the text of
|
|
318 the current field. \\[bibtex-empty-field] replaces the text of the current
|
|
319 field with the default \"\".
|
|
320
|
|
321 The command \\[bibtex-clean-entry] cleans the current entry, i.e. (i) removes
|
|
322 double-quotes from entirely numerical fields, (ii) removes OPT from all
|
|
323 non-empty optional fields, (iii) removes all empty optional fields, and (iv)
|
|
324 checks that no non-optional fields are empty.
|
|
325
|
|
326 Use \\[bibtex-find-text] to position the dot at the end of the current field.
|
|
327 Use \\[bibtex-next-field] to move to end of the next field.
|
|
328
|
|
329 \\[bibtex-x-environment] binds a mode-specific X menu to control+right
|
|
330 mouse button.
|
|
331 \\[bibtex-sun-environment] binds a mode-specific Sun menu to right
|
|
332 mouse button.
|
|
333
|
|
334 Fields:
|
|
335 address
|
|
336 Publisher's address, or for conference, location held
|
|
337 annote
|
|
338 Long annotation used for annotated bibliographies (begins sentence)
|
|
339 author
|
|
340 Name(s) of author(s), in BibTeX name format
|
|
341 booktitle
|
|
342 Book title when the thing being referenced isn't the whole book.
|
|
343 For book entries, the title field should be used instead.
|
|
344 chapter
|
|
345 Chapter number (or section or whatever).
|
|
346 crossref
|
|
347 The database key of the entry being cross referenced.
|
|
348 edition
|
|
349 Edition of a book (e.g., \"second\")
|
|
350 editor
|
|
351 Name(s) of editor(s), in BibTeX name format.
|
|
352 If there is also an author field, then the editor field should be
|
|
353 for the book or collection that the work appears in
|
|
354 howpublished
|
|
355 How something strange has been published (begins sentence)
|
|
356 institution
|
|
357 Sponsoring institution
|
|
358 journal
|
|
359 Journal name (macros are provided for many)
|
|
360 key
|
|
361 Alphabetizing, labeling and cross-refing key (needed when no
|
|
362 author or editor)
|
|
363 month
|
|
364 Month (macros are provided)
|
|
365 note
|
|
366 To help the reader find a reference (begins sentence)
|
|
367 number
|
|
368 Number of a journal or technical report
|
|
369 organization
|
|
370 Organization (sponsoring a conference)
|
|
371 pages
|
|
372 Page number or numbers (use `--' to separate a range)
|
|
373 publisher
|
|
374 Publisher name
|
|
375 school
|
|
376 School name (for theses)
|
|
377 series
|
|
378 The name of a series or set of books.
|
|
379 An individual book will will also have it's own title
|
|
380 title
|
|
381 The title of the thing being referenced
|
|
382 type
|
|
383 Type of a technical report (e.g., \"Research Note\") to be used
|
|
384 instead of the default \"Technical Report\"
|
|
385 volume
|
|
386 Volume of a journal or multivolume work
|
|
387 year
|
|
388 Year---should contain only numerals
|
|
389 ---------------------------------------------------------
|
|
390 Entry to this mode calls the value of bibtex-mode-hook if that value is
|
|
391 non-nil."
|
|
392 (interactive)
|
|
393 (kill-all-local-variables)
|
|
394 (if bibtex-mode-syntax-table
|
|
395 (set-syntax-table bibtex-mode-syntax-table)
|
|
396 (setq bibtex-mode-syntax-table (make-syntax-table))
|
|
397 (set-syntax-table bibtex-mode-syntax-table)
|
|
398 (modify-syntax-entry ?\" ".")
|
|
399 (modify-syntax-entry ?$ "$$ ")
|
|
400 (modify-syntax-entry ?% "< ")
|
|
401 (modify-syntax-entry ?' "w ")
|
|
402 (modify-syntax-entry ?@ "w ")
|
|
403 (modify-syntax-entry ?\\ "\\")
|
|
404 (modify-syntax-entry ?\f "> ")
|
|
405 (modify-syntax-entry ?\n "> ")
|
|
406 (modify-syntax-entry ?~ " "))
|
|
407 (use-local-map bibtex-mode-map)
|
|
408 (setq major-mode 'bibtex-mode)
|
|
409
|
|
410
|
|
411 (setq mode-name "BibTeX")
|
|
412 (set-syntax-table bibtex-mode-syntax-table)
|
|
413 (setq local-abbrev-table bibtex-mode-abbrev-table)
|
|
414 (make-local-variable 'paragraph-start)
|
|
415 (setq paragraph-start "^[ \f\n\t]*$")
|
|
416
|
|
417 (define-key bibtex-mode-map "\t" 'bibtex-find-text)
|
|
418 (define-key bibtex-mode-map "\n" 'bibtex-next-field)
|
|
419 (define-key bibtex-mode-map "\C-c\"" 'bibtex-remove-double-quotes)
|
|
420 (define-key bibtex-mode-map "\C-c\C-c" 'bibtex-clean-entry)
|
|
421 (define-key bibtex-mode-map "\C-c?" 'describe-mode)
|
|
422 (define-key bibtex-mode-map "\C-c\C-p" 'bibtex-pop-previous)
|
|
423 (define-key bibtex-mode-map "\C-c\C-n" 'bibtex-pop-next)
|
|
424 (define-key bibtex-mode-map "\C-c\C-k" 'bibtex-kill-optional-field)
|
|
425 (define-key bibtex-mode-map "\C-c\C-d" 'bibtex-empty-field)
|
|
426
|
|
427 (define-key bibtex-mode-map "\C-c\C-e\C-a" 'bibtex-Article)
|
|
428 (define-key bibtex-mode-map "\C-c\C-e\C-b" 'bibtex-Book)
|
|
429 (define-key bibtex-mode-map "\C-c\C-e\C-d" 'bibtex-DEAthesis)
|
|
430 (define-key bibtex-mode-map "\C-c\C-e\C-c" 'bibtex-InProceedings)
|
|
431 (define-key bibtex-mode-map "\C-c\C-e\C-i" 'bibtex-InBook)
|
|
432 (define-key bibtex-mode-map "\C-c\C-ei" 'bibtex-InCollection)
|
|
433 (define-key bibtex-mode-map "\C-c\C-eI" 'bibtex-InProceedings)
|
|
434 (define-key bibtex-mode-map "\C-c\C-e\C-m" 'bibtex-Manual)
|
|
435 (define-key bibtex-mode-map "\C-c\C-em" 'bibtex-MastersThesis)
|
|
436 (define-key bibtex-mode-map "\C-c\C-eM" 'bibtex-Misc)
|
|
437 (define-key bibtex-mode-map "\C-c\C-o" 'bibtex-remove-OPT)
|
|
438 (define-key bibtex-mode-map "\C-c\C-e\C-p" 'bibtex-PhdThesis)
|
|
439 (define-key bibtex-mode-map "\C-c\C-ep" 'bibtex-Proceedings)
|
|
440 (define-key bibtex-mode-map "\C-c\C-eP" 'bibtex-preamble)
|
|
441 (define-key bibtex-mode-map "\C-c\C-e\C-t" 'bibtex-TechReport)
|
|
442 (define-key bibtex-mode-map "\C-c\C-e\C-s" 'bibtex-string)
|
|
443 (define-key bibtex-mode-map "\C-c\C-e\C-u" 'bibtex-Unpublished)
|
|
444
|
|
445 (auto-fill-mode 1) ; nice alignements
|
|
446 (setq left-margin (+ bibtex-text-alignment 1))
|
|
447
|
|
448 (run-hooks 'bibtex-mode-hook))
|
|
449
|
|
450 (defun bibtex-move-outside-of-entry ()
|
|
451 "Make sure we are outside of a bib entry"
|
|
452 (cond ((or
|
|
453 (= (point) (point-max))
|
|
454 (= (point) (point-min))
|
|
455 (looking-at "[ \n]*@")
|
|
456 )
|
|
457 t)
|
|
458 (t
|
|
459 (backward-paragraph)
|
|
460 (forward-paragraph)))
|
561
|
461 (re-search-forward "[ \t\n]*" (point-max) t)
|
|
462 (insert "\n")
|
|
463 (forward-char -1))
|
257
|
464
|
|
465 ;;
|
|
466 ;; note: this should really take lists of strings OR of lists. in the
|
|
467 ;; second case, one can use either list. (ie:
|
|
468 ;; "name" (("crossref") ("journal" "year")) )
|
|
469 ;;
|
|
470
|
|
471 (defun bibtex-entry (entry-type required optional)
|
|
472 (bibtex-move-outside-of-entry)
|
|
473 (insert "@" entry-type "{")
|
|
474 (mapcar 'bibtex-make-field required)
|
|
475 (if bibtex-include-OPTcrossref
|
|
476 (bibtex-make-optional-field "crossref"))
|
|
477 (if bibtex-include-OPTkey
|
|
478 (bibtex-make-optional-field "key"))
|
|
479 (mapcar 'bibtex-make-optional-field optional)
|
|
480 (if bibtex-mode-user-optional-fields ;MON...
|
|
481 (mapcar 'bibtex-make-optional-field
|
|
482 bibtex-mode-user-optional-fields))
|
|
483 (if bibtex-include-OPTannote
|
|
484 (bibtex-make-optional-field "annote"))
|
|
485 (insert "\n}\n\n")
|
|
486 (forward-char -3)
|
|
487 (up-list -1)
|
|
488 (forward-char 1))
|
|
489
|
561
|
490 (defun bibtex-insert-field-delimeters (str)
|
|
491 "Insert double quotes (default) or, if STR is in the list
|
|
492 bibtex-curly-delimeters, insert curly brackets."
|
|
493 (if (and (boundp 'bibtex-curly-delimeters)
|
|
494 bibtex-curly-delimeters
|
|
495 (memq (car (read-from-string (downcase str)))
|
|
496 bibtex-curly-delimeters))
|
|
497 (insert "\{\}")
|
|
498 (insert "\"\"")))
|
|
499
|
257
|
500 (defun bibtex-make-field (str)
|
|
501 (interactive "sBibTeX entry type: ")
|
|
502 (insert ",\n")
|
561
|
503 (indent-to-column bibtex-name-alignment)
|
257
|
504 (insert str " = ")
|
|
505 (indent-to-column bibtex-text-alignment)
|
561
|
506 (bibtex-insert-field-delimeters str)
|
257
|
507 nil)
|
|
508
|
561
|
509 ;; modified to make fields align up _after_ the OPT's have been removed
|
|
510
|
257
|
511 (defun bibtex-make-optional-field (str)
|
|
512 (interactive "sOptional BibTeX entry type: ")
|
|
513 (insert ",\n")
|
561
|
514 (indent-to-column bibtex-name-alignment)
|
|
515 (insert str " = ")
|
|
516 (indent-to-column bibtex-text-alignment) ;align nicely, then,...
|
|
517 (bibtex-insert-field-delimeters str)
|
|
518 (if bibtex-use-OPT-prefix
|
|
519 (progn
|
|
520 (beginning-of-line)
|
|
521 (move-to-column bibtex-name-alignment) ;go back to name and put in OPT
|
|
522 (insert "OPT")
|
|
523 (end-of-line)))
|
257
|
524 nil)
|
|
525
|
|
526 ;; What to do about crossref? if present, journal and year are
|
|
527 ;; both optional. Due to this, i move all of them into optional. -- MON
|
|
528
|
|
529 (defun bibtex-Article ()
|
|
530 (interactive)
|
|
531 (if bibtex-include-OPTcrossref
|
|
532 (bibtex-entry "Article" '("author" "title")
|
|
533 '("journal" "year" "volume" "number" "pages"
|
|
534 "month" "note"))
|
|
535 (bibtex-entry "Article" '("author" "title" "journal" "year")
|
|
536 '("volume" "number" "pages" "month" "note"))))
|
|
537
|
|
538 (defun bibtex-Book ()
|
|
539 (interactive)
|
|
540 (bibtex-entry "Book" '("author" "title" "publisher" "year")
|
|
541 '("editor" "volume" "number" "series" "address"
|
|
542 "edition" "month" "note")))
|
|
543
|
|
544 (defun bibtex-Booklet ()
|
|
545 (interactive)
|
|
546 (bibtex-entry "Booklet" '("title")
|
|
547 '("author" "howpublished" "address" "month" "year" "note")))
|
|
548
|
|
549 ;; France: Dipl\^{o}me d'Etudes Approfondies (similar to Master's)
|
|
550 (defun bibtex-DEAthesis ()
|
|
551 (interactive)
|
|
552 (bibtex-entry "DEAthesis" '("author" "title" "school" "year")
|
|
553 '("address" "month" "note")))
|
|
554
|
|
555 (defun bibtex-InBook ()
|
|
556 (interactive)
|
|
557 (if bibtex-include-OPTcrossref
|
|
558 (bibtex-entry "InBook" '("author" "title" "chapter")
|
|
559 '("publisher" "year" "editor" "pages" "volume" "number"
|
|
560 "series" "address" "edition" "month" "type" "note"))
|
|
561 (bibtex-entry "InBook" '("author" "title" "chapter" "publisher" "year")
|
|
562 '("editor" "pages" "volume" "number" "series" "address"
|
|
563 "edition" "month" "type" "note"))))
|
|
564
|
|
565 ;; In next 2, for crossref case, put pages near beginning of
|
|
566 ;; optionals as it will be used most often -- MON
|
|
567 (defun bibtex-InCollection ()
|
|
568 (interactive)
|
|
569 (if bibtex-include-OPTcrossref
|
|
570 (bibtex-entry "InCollection" '("author" "title")
|
|
571 '("pages" "booktitle" "publisher" "year"
|
|
572 "editor" "volume" "number" "series" "type" "chapter"
|
|
573 "address" "edition" "month" "note"))
|
|
574 (bibtex-entry "InCollection" '("author" "title"
|
|
575 "booktitle" "publisher" "year")
|
|
576 '("editor" "volume" "number" "series" "type" "chapter"
|
|
577 "pages" "address" "edition" "month" "note"))))
|
|
578
|
|
579 (defun bibtex-InProceedings ()
|
|
580 (interactive)
|
|
581 (if bibtex-include-OPTcrossref
|
|
582 (bibtex-entry "InProceedings" '("author" "title")
|
|
583 '( "pages" "editor" "volume" "number" "series"
|
|
584 "booktitle" "year"
|
|
585 "organization" "publisher" "address" "month" "note"))
|
|
586 (bibtex-entry "InProceedings" '("author" "title" "booktitle" "year")
|
|
587 '("editor" "volume" "number" "series" "pages"
|
|
588 "organization" "publisher" "address" "month" "note"))))
|
|
589
|
|
590 (defun bibtex-Manual ()
|
|
591 (interactive)
|
|
592 (bibtex-entry "Manual" '("title")
|
|
593 '("author" "organization" "address" "edition" "year"
|
|
594 "month" "note")))
|
|
595
|
|
596 (defun bibtex-MastersThesis ()
|
|
597 (interactive)
|
|
598 (bibtex-entry "MastersThesis" '("author" "title" "school" "year")
|
|
599 '("address" "month" "note" "type")))
|
|
600
|
|
601 (defun bibtex-Misc ()
|
|
602 (interactive)
|
|
603 (bibtex-entry "Misc" '()
|
|
604 '("author" "title" "howpublished" "year" "month" "note")))
|
|
605
|
|
606 (defun bibtex-PhdThesis ()
|
|
607 (interactive)
|
|
608 (bibtex-entry "PhdThesis" '("author" "title" "school" "year")
|
|
609 '("address" "month" "type" "note")))
|
|
610
|
|
611 (defun bibtex-Proceedings ()
|
|
612 (interactive)
|
|
613 (bibtex-entry "Proceedings" '("title" "year")
|
|
614 '("editor" "volume" "number" "series" "publisher"
|
|
615 "organization" "address" "month" "note")))
|
|
616
|
|
617 (defun bibtex-TechReport ()
|
|
618 (interactive)
|
|
619 (bibtex-entry "TechReport" '("author" "title" "institution" "year")
|
|
620 '("type" "number" "address" "month" "note")))
|
|
621
|
|
622
|
|
623 (defun bibtex-Unpublished ()
|
|
624 (interactive)
|
|
625 (bibtex-entry "Unpublished" '("author" "title" "note")
|
|
626 '("year" "month")))
|
|
627
|
|
628 (defun bibtex-string ()
|
|
629 (interactive)
|
|
630 (bibtex-move-outside-of-entry)
|
|
631 (insert "@string{ = """"}\n")
|
|
632 (previous-line 1)
|
|
633 (forward-char 8))
|
|
634
|
|
635 (defun bibtex-preamble ()
|
|
636 (interactive)
|
|
637 (bibtex-move-outside-of-entry)
|
|
638 (insert "@Preamble{}\n")
|
|
639 (previous-line 1)
|
|
640 (forward-char 10))
|
|
641
|
|
642 (defun bibtex-next-field (arg)
|
|
643 "Finds end of text of next BibTeX field; with arg, to its beginning"
|
|
644 (interactive "P")
|
|
645 (bibtex-inside-field)
|
|
646 (let ((start (point)))
|
|
647 (condition-case ()
|
|
648 (progn
|
|
649 (bibtex-enclosing-field)
|
|
650 (goto-char (match-end 0))
|
|
651 (forward-char 2))
|
|
652 (error
|
|
653 (goto-char start)
|
|
654 (end-of-line)
|
|
655 (forward-char 1))))
|
|
656 (bibtex-find-text arg))
|
|
657
|
|
658 (defun bibtex-find-text (arg)
|
|
659 "Go to end of text of current field; with arg, go to beginning."
|
|
660 (interactive "P")
|
|
661 (bibtex-inside-field)
|
|
662 (bibtex-enclosing-field)
|
|
663 (if arg
|
|
664 (progn
|
|
665 (goto-char (match-beginning bibtex-text-in-field))
|
561
|
666 (if (or (looking-at "\"") (looking-at "{"))
|
257
|
667 (forward-char 1)))
|
|
668 (goto-char (match-end bibtex-text-in-field))
|
561
|
669 (if (or (= (preceding-char) ?\") (= (preceding-char) ?}))
|
257
|
670 (forward-char -1))))
|
|
671
|
|
672 (defun bibtex-remove-OPT ()
|
|
673 "Removes the 'OPT' starting optional arguments and goes to end of text"
|
|
674 (interactive)
|
|
675 (bibtex-inside-field)
|
|
676 (bibtex-enclosing-field)
|
|
677 (save-excursion
|
|
678 (goto-char (match-beginning bibtex-name-in-field))
|
|
679 (if (looking-at "OPT")
|
|
680 (delete-char (length "OPT"))))
|
|
681 (bibtex-inside-field))
|
|
682
|
|
683 (defun bibtex-inside-field ()
|
|
684 "Try to avoid point being at end of a bibtex field."
|
|
685 (interactive)
|
|
686 (end-of-line)
|
|
687 (skip-chars-backward " \t") ;delete these chars? -- MON
|
|
688 (cond ((= (preceding-char) ?,)
|
|
689 (forward-char -1)))
|
561
|
690 (cond ((or (= (preceding-char) ?\") (= (preceding-char) ?\}))
|
257
|
691 (forward-char -1)))) ;only go back if quote
|
|
692
|
|
693
|
|
694 (defun bibtex-remove-double-quotes ()
|
|
695 "Removes """" around string."
|
|
696 (interactive)
|
|
697 (save-excursion
|
|
698 (bibtex-inside-field)
|
|
699 (bibtex-enclosing-field)
|
|
700 (let ((start (match-beginning bibtex-text-in-field))
|
|
701 (stop (match-end bibtex-text-in-field)))
|
|
702 (goto-char stop)
|
|
703 (forward-char -1)
|
|
704 (if (looking-at "\"")
|
|
705 (delete-char 1))
|
|
706 (goto-char start)
|
|
707 (if (looking-at "\"")
|
|
708 (delete-char 1)))))
|
|
709
|
|
710 (defun bibtex-kill-optional-field ()
|
|
711 "Kill the entire enclosing optional BibTeX field"
|
|
712 (interactive)
|
|
713 (bibtex-inside-field)
|
|
714 (bibtex-enclosing-field)
|
|
715 (goto-char (match-beginning bibtex-name-in-field))
|
|
716 (let ((the-end (match-end 0))
|
|
717 (the-beginning (match-beginning 0)))
|
|
718 (if (looking-at "OPT")
|
|
719 (progn
|
|
720 (goto-char the-end)
|
|
721 (skip-chars-forward " \t\n,")
|
|
722 (kill-region the-beginning the-end))
|
|
723 (error "Mandatory fields can't be killed"))))
|
|
724
|
|
725 (defun bibtex-empty-field ()
|
|
726 "Delete the text part of the current field, replace with empty text"
|
|
727 (interactive)
|
|
728 (bibtex-inside-field)
|
|
729 (bibtex-enclosing-field)
|
|
730 (goto-char (match-beginning bibtex-text-in-field))
|
|
731 (kill-region (point) (match-end bibtex-text-in-field))
|
|
732 (insert "\"\"")
|
|
733 (bibtex-find-text t))
|
|
734
|
|
735
|
|
736 (defun bibtex-pop-previous (arg)
|
|
737 "Replace text of current field with the text of similar field in previous entry.
|
|
738 With arg, go up ARG entries. Repeated, goes up so many times. May be
|
|
739 intermixed with \\[bibtex-pop-next] (bibtex-pop-next)."
|
|
740 (interactive "p")
|
|
741 (bibtex-inside-field)
|
|
742 (save-excursion
|
|
743 ; parse current field
|
|
744 (bibtex-enclosing-field)
|
|
745 (let ((start-old-text (match-beginning bibtex-text-in-field))
|
|
746 (stop-old-text (match-end bibtex-text-in-field))
|
|
747 (start-name (match-beginning bibtex-name-in-field))
|
|
748 (stop-name (match-end bibtex-name-in-field))
|
|
749 (new-text))
|
|
750 (goto-char start-name)
|
|
751 ; construct regexp for previous field with same name as this one
|
|
752 (let ((matching-entry
|
|
753 (bibtex-cfield
|
|
754 (buffer-substring (if (looking-at "OPT")
|
|
755 (+ (point) (length "OPT"))
|
|
756 (point))
|
|
757 stop-name)
|
|
758 bibtex-field-text)))
|
|
759
|
|
760 ; if executed several times in a row, start each search where the
|
|
761 ; last one finished
|
|
762 (cond ((or (eq last-command 'bibtex-pop-previous)
|
|
763 (eq last-command 'bibtex-pop-next))
|
|
764 t
|
|
765 )
|
|
766 (t
|
|
767 (bibtex-enclosing-reference)
|
|
768 (setq bibtex-pop-previous-search-point (match-beginning 0))
|
|
769 (setq bibtex-pop-next-search-point (match-end 0))))
|
|
770 (goto-char bibtex-pop-previous-search-point)
|
|
771
|
|
772 ; Now search for arg'th previous similar field
|
|
773 (cond
|
|
774 ((re-search-backward matching-entry (point-min) t arg)
|
|
775 (setq new-text
|
|
776 (buffer-substring (match-beginning bibtex-text-in-cfield)
|
|
777 (match-end bibtex-text-in-cfield)))
|
|
778 ; Found a matching field. Remember boundaries.
|
|
779 (setq bibtex-pop-next-search-point (match-end 0))
|
|
780 (setq bibtex-pop-previous-search-point (match-beginning 0))
|
|
781 (bibtex-flash-head)
|
|
782 ; Go back to where we started, delete old text, and pop new.
|
|
783 (goto-char stop-old-text)
|
|
784 (delete-region start-old-text stop-old-text)
|
|
785 (insert new-text))
|
|
786 (t ; search failed
|
|
787 (error "No previous matching BibTeX field."))))))
|
|
788 (setq this-command 'bibtex-pop-previous))
|
|
789
|
|
790 (defun bibtex-pop-next (arg)
|
|
791 "Replace text of current field with the text of similar field in next entry.
|
|
792 With arg, go up ARG entries. Repeated, goes up so many times. May be
|
|
793 intermixed with \\[bibtex-pop-previous] (bibtex-pop-previous)."
|
|
794 (interactive "p")
|
|
795 (bibtex-inside-field)
|
|
796 (save-excursion
|
|
797 ; parse current field
|
|
798 (bibtex-enclosing-field)
|
|
799 (let ((start-old-text (match-beginning bibtex-text-in-field))
|
|
800 (stop-old-text (match-end bibtex-text-in-field))
|
|
801 (start-name (match-beginning bibtex-name-in-field))
|
|
802 (stop-name (match-end bibtex-name-in-field))
|
|
803 (new-text))
|
|
804 (goto-char start-name)
|
|
805 ; construct regexp for next field with same name as this one,
|
|
806 ; ignoring possible OPT's
|
|
807 (let ((matching-entry
|
|
808 (bibtex-cfield
|
|
809 (buffer-substring (if (looking-at "OPT")
|
|
810 (+ (point) (length "OPT"))
|
|
811 (point))
|
|
812 stop-name)
|
|
813 bibtex-field-text)))
|
|
814
|
|
815 ; if executed several times in a row, start each search where the
|
|
816 ; last one finished
|
|
817 (cond ((or (eq last-command 'bibtex-pop-next)
|
|
818 (eq last-command 'bibtex-pop-previous))
|
|
819 t
|
|
820 )
|
|
821 (t
|
|
822 (bibtex-enclosing-reference)
|
|
823 (setq bibtex-pop-previous-search-point (match-beginning 0))
|
|
824 (setq bibtex-pop-next-search-point (match-end 0))))
|
|
825 (goto-char bibtex-pop-next-search-point)
|
|
826
|
|
827 ; Now search for arg'th next similar field
|
|
828 (cond
|
|
829 ((re-search-forward matching-entry (point-max) t arg)
|
|
830 (setq new-text
|
|
831 (buffer-substring (match-beginning bibtex-text-in-cfield)
|
|
832 (match-end bibtex-text-in-cfield)))
|
|
833 ; Found a matching field. Remember boundaries.
|
|
834 (setq bibtex-pop-next-search-point (match-end 0))
|
|
835 (setq bibtex-pop-previous-search-point (match-beginning 0))
|
|
836 (bibtex-flash-head)
|
|
837 ; Go back to where we started, delete old text, and pop new.
|
|
838 (goto-char stop-old-text)
|
|
839 (delete-region start-old-text stop-old-text)
|
|
840 (insert new-text))
|
|
841 (t ; search failed
|
|
842 (error "No next matching BibTeX field."))))))
|
|
843 (setq this-command 'bibtex-pop-next))
|
|
844
|
|
845 (defun bibtex-flash-head ()
|
|
846 "Flash at BibTeX reference head before point, if exists. (Moves point)."
|
|
847 (let ((flash))
|
|
848 (cond ((re-search-backward bibtex-reference-head (point-min) t)
|
|
849 (goto-char (match-beginning bibtex-type-in-head))
|
|
850 (setq flash (match-end bibtex-key-in-reference)))
|
|
851 (t
|
|
852 (end-of-line)
|
|
853 (skip-chars-backward " \t")
|
|
854 (setq flash (point))
|
|
855 (beginning-of-line)
|
|
856 (skip-chars-forward " \t")))
|
|
857 (if (pos-visible-in-window-p (point))
|
|
858 (sit-for 1)
|
|
859 (message "From: %s"
|
|
860 (buffer-substring (point) flash)))))
|
|
861
|
|
862
|
|
863
|
|
864 (defun bibtex-enclosing-field ()
|
|
865 "Search for BibTeX field enclosing point.
|
|
866 Point moves to end of field; also, use match-beginning and match-end
|
|
867 to parse the field."
|
|
868 (condition-case errname
|
|
869 (bibtex-enclosing-regexp bibtex-field)
|
|
870 (search-failed
|
|
871 (error "Can't find enclosing BibTeX field."))))
|
|
872
|
|
873 (defun bibtex-enclosing-reference ()
|
|
874 "Search for BibTeX reference enclosing point.
|
|
875 Point moves to end of reference; also, use match-beginning and match-end
|
|
876 to parse the reference."
|
|
877 (condition-case errname
|
|
878 (bibtex-enclosing-regexp bibtex-reference)
|
|
879 (search-failed
|
|
880 (error "Can't find enclosing BibTeX reference."))))
|
|
881
|
|
882 (defun bibtex-enclosing-regexp (regexp)
|
|
883 "Search for REGEXP enclosing point.
|
|
884 Point moves to end of REGEXP. See also match-beginning and match-end.
|
|
885 If an enclosing REGEXP is not found, signals search-failed; point is left in
|
|
886 an undefined location.
|
|
887
|
|
888 [Doesn't something like this exist already?]"
|
|
889
|
|
890 (interactive "sRegexp: ")
|
|
891 ; compute reasonable limits for the loop
|
|
892 (let* ((initial (point))
|
|
893 (right (if (re-search-forward regexp (point-max) t)
|
|
894 (match-end 0)
|
|
895 (point-max)))
|
|
896 (left
|
|
897 (progn
|
|
898 (goto-char initial)
|
|
899 (if (re-search-backward regexp (point-min) t)
|
|
900 (match-beginning 0)
|
|
901 (point-min)))))
|
|
902 ; within the prescribed limits, loop until a match is found
|
|
903 (goto-char left)
|
|
904 (re-search-forward regexp right nil 1)
|
|
905 (if (> (match-beginning 0) initial)
|
|
906 (signal 'search-failed (list regexp)))
|
561
|
907 (while (< (match-end 0) initial) ;<= --> < -- MON
|
257
|
908 (re-search-forward regexp right nil 1)
|
|
909 (if (> (match-beginning 0) initial)
|
|
910 (signal 'search-failed (list regexp))))
|
|
911 ))
|
|
912
|
|
913 (defun bibtex-clean-entry ()
|
|
914 "For all optional fields of current BibTeX entry: if empty, kill the whole field; otherwise, remove the \"OPT\" string in the name; if text numerical, remove double-quotes. For all mandatory fields: if empty, signal error."
|
|
915 (interactive)
|
|
916 (bibtex-enclosing-reference)
|
|
917 (goto-char (match-beginning 0))
|
|
918 (let ((start (point)))
|
|
919 (save-restriction
|
|
920 (narrow-to-region start (match-end 0))
|
|
921 (while (re-search-forward bibtex-field (point-max) t 1)
|
|
922 (let ((begin-field (match-beginning 0))
|
|
923 (end-field (match-end 0))
|
|
924 (begin-name (match-beginning bibtex-name-in-field))
|
|
925 (end-name (match-end bibtex-name-in-field))
|
|
926 (begin-text (match-beginning bibtex-text-in-field))
|
|
927 (end-text (match-end bibtex-text-in-field))
|
|
928 )
|
|
929 (goto-char begin-name)
|
|
930 (cond ((and
|
|
931 (looking-at "OPT")
|
|
932 bibtex-clean-entry-zap-empty-opts)
|
|
933 (goto-char begin-text)
|
561
|
934 (if (and (looking-at "\"\"") ; empty: delete whole field
|
|
935 (boundp 'bibtex-save-OPT)
|
|
936 bibtex-save-OPT
|
|
937 (not (memq (car (read-from-string
|
|
938 (buffer-substring
|
|
939 (+ begin-name 3)
|
|
940 end-name)))
|
|
941 bibtex-save-OPT)))
|
257
|
942 (delete-region begin-field end-field)
|
561
|
943 ;; otherwise: not empty, delete "OPT"
|
257
|
944 (goto-char begin-name)
|
|
945 (delete-char (length "OPT"))
|
|
946 (goto-char begin-field) ; and loop to go through next test
|
|
947 ))
|
|
948 (t
|
|
949 (goto-char begin-text)
|
|
950 (cond ((looking-at "\"[0-9]+\"") ; if numerical,
|
|
951 (goto-char end-text)
|
|
952 (delete-char -1) ; delete enclosing double-quotes
|
|
953 (goto-char begin-text)
|
|
954 (delete-char 1)
|
|
955 (goto-char end-field) ; go to end for next search
|
|
956 (forward-char -2) ; to compensate for the 2 quotes deleted
|
|
957 )
|
|
958 ((looking-at "\"\"") ; if empty quotes, complain
|
|
959 (forward-char 1)
|
|
960 (if (not (or (equal (buffer-substring
|
|
961 begin-name
|
|
962 (+ begin-name 3))
|
|
963 "OPT")
|
|
964 (equal (buffer-substring
|
|
965 begin-name
|
|
966 (+ begin-name 3))
|
561
|
967 "opt")
|
|
968 (memq (car (read-from-string
|
|
969 (buffer-substring
|
|
970 begin-name
|
|
971 end-name)))
|
|
972 bibtex-save-OPT)))
|
257
|
973 (error "Mandatory field ``%s'' is empty"
|
|
974 (buffer-substring begin-name end-name))))
|
|
975 (t
|
|
976 (goto-char end-field))))))))
|
|
977 (goto-char start)
|
|
978 (skip-chars-forward "@a-zA-Z")
|
|
979 (bibtex-enclosing-reference)
|
|
980 (goto-char (match-end 0))
|
|
981 (skip-chars-forward " \t\n")))
|
|
982
|
|
983
|
|
984
|
|
985 ;;; X window menus for bibtex mode
|
|
986
|
|
987 (defun bibtex-x-help (arg)
|
|
988 "Mouse commands for BibTeX mode"
|
|
989
|
|
990 (let ((selection
|
|
991 (x-popup-menu
|
|
992 arg
|
|
993 '("BibTeX commands"
|
|
994 ("BibTeX entry types"
|
|
995 (" article in conference Proceedings " . bibtex-InProceedings)
|
|
996 (" Article in journal " . bibtex-Article)
|
|
997 (" Book " . bibtex-Book)
|
|
998 (" Booklet " . bibtex-Booklet)
|
|
999 (" Conference " . bibtex-InProceedings)
|
|
1000 (" Master's Thesis " . bibtex-MastersThesis)
|
|
1001 (" DEA Thesis " . bibtex-DEAthesis)
|
|
1002 (" Phd. Thesis " . bibtex-PhdThesis)
|
|
1003 (" Technical Report " . bibtex-TechReport)
|
|
1004 (" technical Manual " . bibtex-Manual)
|
|
1005 (" conference Proceedings " . bibtex-Proceedings)
|
|
1006 (" a chapter in a Book " . bibtex-InBook)
|
|
1007 (" an article in a Collection " . bibtex-InCollection)
|
|
1008 (" miscellaneous " . bibtex-Misc)
|
|
1009 (" unpublished " . bibtex-Unpublished)
|
|
1010 (" string " . bibtex-string)
|
|
1011 (" preamble " . bibtex-preamble)
|
|
1012 )
|
|
1013 ("Moving around and editing"
|
|
1014 (" next field " . bibtex-next-field)
|
|
1015 (" to end of field " . bibtex-find-text)
|
|
1016 ("snatch from similar preceding field" . bibtex-pop-previous)
|
|
1017 ("snatch from similar following field" . bibtex-pop-next)
|
|
1018 (" remove OPT " . bibtex-remove-OPT)
|
|
1019 (" remove quotes "
|
|
1020 . bibtex-remove-double-quotes)
|
|
1021 (" clean up entry " . bibtex-clean-entry)
|
|
1022 )
|
|
1023 ("help"
|
|
1024 (" describe BibTeX mode " . describe-mode)
|
|
1025 )))))
|
|
1026 (and selection (call-interactively selection))))
|
|
1027
|
|
1028 (defun bibtex-x-environment ()
|
|
1029 "Set up X menus for BibTeX mode. Call it as bibtex-mode-hook, or interactively"
|
|
1030 (interactive)
|
|
1031 (require 'x-mouse)
|
|
1032 (define-key mouse-map x-button-c-right 'bibtex-x-help)
|
|
1033 )
|
|
1034
|
|
1035
|
|
1036
|
|
1037 ;; Please don't send anything to bug-gnu-emacs about these Sunwindows functions
|
|
1038 ;; since we aren't interested. See etc/SUN-SUPPORT for the reasons why
|
|
1039 ;; we consider this nothing but a distraction from our work.
|
|
1040
|
|
1041 (if (fboundp 'defmenu)
|
|
1042 (progn
|
|
1043
|
|
1044 (defmenu bibtex-sun-entry-menu
|
|
1045 ("Article In Conf. Proc."
|
|
1046 (lambda () (eval-in-window *menu-window* (bibtex-InProceedings))))
|
|
1047 ("Article In Journal"
|
|
1048 (lambda () (eval-in-window *menu-window* (bibtex-Article))))
|
|
1049 ("Book"
|
|
1050 (lambda () (eval-in-window *menu-window* (bibtex-Book))))
|
|
1051 ("Booklet"
|
|
1052 (lambda () (eval-in-window *menu-window* (bibtex-Booklet))))
|
|
1053 ("Master's Thesis"
|
|
1054 (lambda () (eval-in-window *menu-window* (bibtex-MastersThesis))))
|
|
1055 ;;("DEA Thesis" bibtex-DEAthesis)
|
|
1056 ("PhD. Thesis"
|
|
1057 (lambda () (eval-in-window *menu-window* (bibtex-PhdThesis))))
|
|
1058 ("Technical Report"
|
|
1059 (lambda () (eval-in-window *menu-window* (bibtex-TechReport))))
|
|
1060 ("Technical Manual"
|
|
1061 (lambda () (eval-in-window *menu-window* (bibtex-Manual))))
|
|
1062 ("Conference Proceedings"
|
|
1063 (lambda () (eval-in-window *menu-window* (bibtex-Proceedings))))
|
|
1064 ("In A Book"
|
|
1065 (lambda () (eval-in-window *menu-window* (bibtex-InBook))))
|
|
1066 ("In A Collection"
|
|
1067 (lambda () (eval-in-window *menu-window* (bibtex-InCollection))))
|
|
1068 ("Miscellaneous"
|
|
1069 (lambda () (eval-in-window *menu-window* (bibtex-Misc))))
|
|
1070 ("Unpublished"
|
|
1071 (lambda () (eval-in-window *menu-window* (bibtex-Unpublished)))))
|
|
1072
|
|
1073 (defmenu bibtex-sun-menu
|
|
1074 ("BibTeX menu")
|
|
1075 ("add entry" . bibtex-sun-entry-menu)
|
|
1076 ("add string"
|
|
1077 (lambda () (eval-in-window *menu-window* (bibtex-string))))
|
|
1078 ;("next field" bibtex-next-position)
|
|
1079 ;("to end of field" bibtex-find-it)
|
|
1080 ; ("remove OPT"
|
|
1081 ; (lambda () (eval-in-window *menu-window* (bibtex-remove-opt))))
|
|
1082 ; ("remove quotes"
|
|
1083 ; (lambda () (eval-in-window *menu-window* (bibtex-remove-double-quotes))))
|
|
1084 ; ("remove this line"
|
|
1085 ; (lambda () (eval-in-window *menu-window* (kill-current-line))))
|
|
1086 ("describe BibTeX mode"
|
|
1087 (lambda () (eval-in-window *menu-window* (describe-mode))))
|
|
1088 ("Main Emacs menu" . emacs-menu))
|
|
1089
|
|
1090 (defun bibtex-sun-menu-eval (window x y)
|
|
1091 "Pop-up menu of BibTeX commands."
|
|
1092 (sun-menu-evaluate window (1+ x) (1- y) 'bibtex-sun-menu))
|
|
1093
|
|
1094 (defun bibtex-sun-environment ()
|
|
1095 "Set up sun menus for BibTeX mode. Call it as bibtex-mode-hook, or interactively"
|
|
1096 (interactive)
|
|
1097 (local-set-mouse '(text right) 'bibtex-sun-menu-eval))
|
|
1098
|
|
1099 )) ; matches (if...
|
|
1100
|
|
1101 ;;; ------------- end bibtex-mode.el -------------------------------
|
584
|
1102
|
|
1103 (provide 'bibtex)(provide 'bibtex)
|
|
1104
|