annotate lisp/textmodes/bibtex.el @ 584:4cd7543be581

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