annotate lisp/modes/bibtex.el @ 189:489f57a838ef r20-3b21

Import from CVS: tag r20-3b21
author cvs
date Mon, 13 Aug 2007 09:57:07 +0200
parents 0293115a14e9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; bibtex.el --- BibTeX mode for GNU Emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1992 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Author: Bengt Martensson <ubrinf!mond!bengt>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Mark Shapiro <shapiro@corto.inria.fr>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; Mike Newton <newton@gumby.cs.caltech.edu>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; Aaron Larson <alarson@src.honeywell.com>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; Version: 1.3.1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; Maintainer:Aaron Larson <alarson@src.honeywell.com>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; Adapted-By: ESR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; Keywords: tex, bib
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;; You should have received a copy of the GNU General Public License
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
27 ;; along with XEmacs; see the file COPYING. If not, write to the
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
28 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
29 ;; Boston, MA 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;; TODO distribute texinfo file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;;; LCD Archive Entry:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;;; bibtex-mode|Bengt Martensson, Marc Shapiro, Aaron Larson|
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;;; alarson@src.honeywell.com|
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;;; Support for maintaining BibTeX format bibliography databases|
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;;; 93-03-29|version 1.3|~/modes/bibtex-mode.el.Z|
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;;; BUGS:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;;; 1. using regular expressions to match the entire bibtex entry dies
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;;; on long bibtex entires (e.g. those containing abstracts) since
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;;; the length of regular expression matches is fairly limited.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;;; 2. When inserting a string (with \C-C\C-E\s) hitting a TAB results
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;;; in the error message "Can't find enclosing Bibtex field" instead
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;;; of moving to the empty string. [reported by gernot@cs.unsw.oz.au]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;;; 3. Function string-equalp should be in a library file, not in this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;;; file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;;; (current keeper: alarson@src.honeywell.com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;;; previous: shapiro@corto.inria.fr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;;; Change Log:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;; Mon Mar 29 14:06:06 1993 Aaron Larson (alarson at gendibal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;; * bibtex.el: V1.3 released Mar 30, 1993
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;; (bibtex-field-name): Fix to match definition if latex manual,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 ;; specifically letters, digits, and punctuation other than comma.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ;; Underscore is retained for historical reasons.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 ;; (bibtex-make-field): Fix to work around bug in Lucid prin1-to-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;; function as reported by Martin Sjolin <marsj@ida.liu.se>.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ;; (bibtex-entry): minor code cleanup.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 ;; (bibtex-mode-map): Remove key binding (C-c n) for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ;; narrow-to-bibtex-entry, previous binding violated emacs policy of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 ;; reserving C-c followed by a letter for user customization.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 ;; revise modification history to better conform to FSF changelog
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 ;; standards.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ;; (bibtex-refile-entry): Removed. Would need disclaimer papers to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 ;; incorporate it into official sources, and unable to contact author.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 ;; Fix minor "syntax" errors in documentation strings and such found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ;; by new byte compiler. Funs bibtex-mode, bibtex-remove-double-quotes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 ;; Fri Jan 15 14:06:06 1993 Aaron Larson (alarson at gendibal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 ;; * bibtex.el: V1.2 released Feb 15 1993
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 ;; (find-bibtex-entry-location bibtex-make-field): Fixed placement of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 ;; "interactive specification". [Bug report from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 ;; mernst@theory.lcs.mit.edu]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 ;; Fixed problem where bibtex-entry would fail if user typed entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 ;; name in wrong case.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 ;; (bibtex-inside-field) Position the cursor _before_ the last comma
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ;; on a line (the comma is not necessarily "inside" the field); this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 ;; does not seem to break any existing code. ref sct@dcs.edinburgh.ac.uk
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 ;; (bibtex-enclosing-field, bibtex-enclosing-reference): leave
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 ;; point unmoved if no enclosing field/reference is found. As a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 ;; result of changes (3) and (4) bibtex-next-field works properly,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 ;; even when called from the entry key position.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 ;; (bibtex-remove-OPT): realign the '=' after removing the 'opt'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 ;; (bibtex-clean-entry): always remove any trailing comma from the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 ;; end of a bibtex entry (these commas get stripped automatically when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 ;; optional fields are killed by bibtex-kill-optional-field, but can be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 ;; left if optional fields are removed by other means).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 ;; (bibtex-x-help) Replace tab with spaces in X menu as noted by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 ;; khera@cs.duke.edu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 ;; (bibtex-refile-entry): Added (from brannon@jove.cs.caltech.edu)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 ;; (bibtex-sort-ignore-string-entries sort-bibtex-entries,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 ;; map-bibtex-entries): Added variable as requested by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 ;; gernot@cs.unsw.oz.au, required changes to funs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 ;; (bibtex-current-entry-label): Added at request of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 ;; yasuro@maekawa.is.uec.ac.jp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 ;; (bibtex-DEAthesis:) Deleted along with corresponding entry from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 ;; bibtex-x-help per shapiro@corto.inria.fr
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 ;; Moved narrow-to-bibtex-entry from C-c C-n to C-c n (the previous
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 ;; binding was in conflict with the binding for bibtex-pop-next.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 ;; bug report from [shapiro@corto.inria.fr]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 ;;; alarson@src.honeywell.com 92-Feb-13
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 ;;; 1. Made bibtex-entry user callable, now prompts for entry type (e.g.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 ;;; Article), with completion, and bound it to a key. This is now my
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 ;;; preferred way to add most entries.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 ;;; 2. Made fields of a bibtex entry derived from the alist bibtex-entry-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 ;;; field-alist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 ;;; 3. Fixed handling of escaped double quotes, e.g. "Schr{\"o}dinger".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 ;;; 4. Fixed bug where unhiding bibtex entries moved point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 ;;; 5. Made "field name" specs permit (name . value) for defaulting. E.g.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 ;;; (setq bibtex-mode-user-optional-fields '(("library" . "alarson")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 ;;; will generate the field:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 ;;; library = "alarson",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 ;;; 6. Added binding for narrow-to-bibtex-entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 ;;; 7. Adding a bibtex entry now runs hook: bibtex-add-entry-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 ;;; 8. Made bibtex-clean-entry fixup text alignment, and eliminated the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 ;;; dependency on bibtex-enclosing-reference which has a problem with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 ;;; long entries (e.g. those containing abstracts).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 ;;; alarson@src.honeywell.com 92-Jan-31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 ;;; Added support for: ispell, beginning/end of entry movement, a simple
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 ;;; outline like mode (hide the bodies of bibtex entries), support for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 ;;; sorting bibtex entries, and maintaining them in sorted order, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 ;;; simple buffer validation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 ;;; User visible functions added:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 ;;; ispell-{abstract,bibtex-entry}, {beginning,end}-of-bibtex-entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 ;;; hide-bibtex-entry-bodies, sort-bibtex-entries, validate-bibtex-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 ;;; buffer, find-bibtex-duplicates
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 ;;; user visible variables added:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 ;;; bibtex-maintain-sorted-entries
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 ;;; new local keybindings:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 ;;; " tex-insert-quote
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 ;;; C-c$ ispell-bibtex-entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 ;;; M-C-a beginning-of-bibtex-entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 ;;; M-C-e end-of-bibtex-entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 ;;; Mike Newton (newton@gumby.cs.caltech.edu) 90.11.17
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 ;;; * Handle items like
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 ;;; title = poft # "Fifth Tri-quarterly" # random-conf,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 ;;; and title = {This title is inside curlies}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 ;;; * added user settable, always present, optional fields
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 ;;; * fixed 'bibtex-find-it's doc string's location
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 ;;; * bibtex-field-text made more general (it wouldn't handle the # construct)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 ;;; and it now handles a small subset of the {} cases
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 ;;; Bengt Martensson, March 6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 ;;; Adapted to Bibtex 0.99 by updating the optional fields according
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 ;;; to the document BibTeXing, Oren Patashnik, dated January 31, 1988.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 ;;; Updated documentation strings accordingly. Added (provide 'bibtex).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 ;;; If bibtex-include-OPT-crossref is non-nil, every entry will have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 ;;; an OPTcrossref field, analogously for bibtex-include-OPTkey and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 ;;; bibtex-include-OPTannote. Added bibtex-preamble, bound to ^C^EP,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 ;;; and also found in X- and sun-menus. Cleaned up the sun-menu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 ;;; stuff, and made it more uniform with the X-menu stuff. Marc: I
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 ;;; strongly suspect that I broke your parsing... (Or, more
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 ;;; correctly, BibTeX 0.99 broke it.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 ;;; Added bibtex-clean-entry-zap-empty-opts, defvar'd to t. If it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 ;;; is nil, bibtex-clean-entry will leave empty optional fields alone.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 ;;; Marc Shapiro 1-feb-89: integrated changes by Bengt Martensson 88-05-06:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 ;;; Added Sun menu support. Locally bound to right mouse button in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 ;;; bibtex-mode. Emacs 18.49 allows local mouse bindings!!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 ;;; Commented out DEAthesis.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 ;;; Marc Shapiro 6-oct-88
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 ;;; * skip-whitespace replaced by skip-chars-forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 ;;; * use indent-to-column instead of inserting tabs (changes to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 ;;; bibtex-entry, bibtex-make-entry, bibtex-make-OPT-entry, renamed to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 ;;; bibtex-make-optional-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 ;;; * C-c C-k deletes the current OPT entry entirely
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 ;;; * C-c C-d replaces text of field with ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 ;;; * renamed bibtex-find-it to bibtex-find-text. With arg, now goes to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 ;;; start of text. Fixed bugs in it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 ;;; Marc Shapiro 23-sep-88
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 ;;; * bibtex-clean-entry moves past end of entry.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 ;;; * bibtex-clean-entry signals mandatory fields left empty.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 ;;; Marc Shapiro 18-jul-88
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 ;;; * Fixed bug in bibtex-flash-entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 ;;; * Moved all the entry type keystrokes to "C-c C-e something" (instead of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 ;;; "C-c something" previously) to make room for more. C-c C-e is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 ;;; supposed to stand for "entry" [idea taken from mail-mode]. Moved
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 ;;; bibtex-pop-previous to C-c C-p and bibtex-pop-next to C-c C-n.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 ;;; * removed binding for "\e[25~"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 ;;; * replaced bibtex-clean-optionals by bibtex-clean-entry, bound to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 ;;; C-c C-c
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 ;;; Marc Shapiro 13-jul-88 [based on ideas by Sacha Krakowiak of IMAG]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 ;;; * bibtex-pop-previous replaces current field with value of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 ;;; similar field in previous entry. May be called n times in a row
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 ;;; (or with arg n) to pop similar field of n'th previous entry.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 ;;; There is also a bibtex-pop-next to get similar field of next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 ;;; entry.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 ;;; * C-c C-k now kills all empty optional fields of current entry, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 ;;; removes "OPT" for those optional fields which have text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 ;;; Marc Shapiro 14-dec-87
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 ;;; Cosmetic fixes. Fixed small bug in bibtex-move-outside-of-entry.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 ;;; Skip Montanaro <steinmetz!sprite!montanaro> 7-dec-87, Shapiro 10-dec-87
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 ;;; before inserting an entry, make sure we are outside of a bib entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 ;;; Marc Shapiro 3-nov-87
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 ;;; addition for France: DEAthesis
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 ;;; Marc Shapiro 19-oct-1987
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 ;;; add X window menu option; bug fixes. TAB, LFD, C-c " and C-c C-o now
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 ;;; behave consistently; deletion never occurs blindly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 ;;; Marc Shapiro <shapiro@inria.inria.fr> 15-oct-1986
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 ;;; align long lines nicely; C-c C-o checks for the "OPT" string;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 ;;; TAB goes to the end of the string; use lower case; use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 ;;; run-hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 ;;; Bengt Martensson <ubrinf!mond!bengt> 87-06-28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 ;;; Bengt Martensson <bengt@mathematik.uni-Bremen.de> 87-06-28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 ;;; Original version
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 ;;; NOTE by Marc Shapiro, 14-dec-87:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 ;;; (bibtex-x-environment) binds an X menu for bibtex mode to x-button-c-right.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 ;;; Trouble is, in Emacs 18.44 you can't have a mode-specific mouse binding,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 ;;; so it will remain active in all windows. Yuck!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (provide 'bibtex)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 ;;; these guys typically don't have autoloads...[alarson:19920131.1548CST]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 ;;; Check for fboundp first so that if user autoloads them from non standard
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 ;;; places, the users bindings will take precedence.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (if (not (fboundp 'tex-insert-quote))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (autoload 'tex-insert-quote "tex-mode"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (if (not (fboundp 'sort-subr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (autoload 'sort-subr "sort"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 ;;; These should be in a more generally accessible location.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (defun string-equalp (s1 s2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 "Like string= except differences in case are ignored."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (let ((ss1 (if (symbolp s1) (symbol-name s1) s1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (ss2 (if (symbolp s2) (symbol-name s2) s2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (and (= (length ss1) (length ss2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (string-equal (upcase ss1) (upcase ss2)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 ;;; This should be moved into simple.el, and the functions there modified
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 ;;; to call it rather than doing it themselves.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (defun put-string-on-kill-ring (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 "Make STRING be the first element of the kill ring."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (setq kill-ring (cons string kill-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (if (> (length kill-ring) kill-ring-max)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (setcdr (nthcdr (1- kill-ring-max) kill-ring) nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (setq kill-ring-yank-pointer kill-ring))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (defvar bibtex-clean-entry-zap-empty-opts t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 "*If non-nil, bibtex-clean-entry will delete all empty optional fields.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (defvar bibtex-include-OPTcrossref t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 "*If non-nil, all entries will have an OPTcrossref field.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (defvar bibtex-include-OPTkey t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 "*If non-nil, all entries will have an OPTkey field.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (defvar bibtex-include-OPTannote t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 "*If non-nil, all entries will have an OPTannote field.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 ;; note: the user should be allowed to have their own list of always
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 ;; available optional fields. exs: "keywords" "categories"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (defvar bibtex-mode-user-optional-fields nil ;no default value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 "*List of optional fields that user want to have as always present
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 when making a bibtex entry. One possibility is for ``keywords''.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 Entries can be either strings or conses, in which case the car should be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 string and the cdr the value to be inserted.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (defvar bibtex-mode-syntax-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (let ((st (make-syntax-table)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 ;; [alarson:19920214.1004CST] make double quote a string quote
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (modify-syntax-entry ?\" "\"" st)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (modify-syntax-entry ?$ "$$ " st)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (modify-syntax-entry ?% "< " st)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (modify-syntax-entry ?' "w " st)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (modify-syntax-entry ?@ "w " st)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (modify-syntax-entry ?\\ "\\" st)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (modify-syntax-entry ?\f "> " st)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (modify-syntax-entry ?\n "> " st)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (modify-syntax-entry ?~ " " st)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 st))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (defvar bibtex-mode-abbrev-table nil "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (define-abbrev-table 'bibtex-mode-abbrev-table ())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (defvar bibtex-mode-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (let ((km (make-sparse-keymap)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (define-key km "\t" 'bibtex-find-text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (define-key km "\n" 'bibtex-next-field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (define-key km "\C-c\"" 'bibtex-remove-double-quotes)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (define-key km "\C-c\C-c" 'bibtex-clean-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (define-key km "\C-c?" 'describe-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (define-key km "\C-c\C-p" 'bibtex-pop-previous)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (define-key km "\C-c\C-n" 'bibtex-pop-next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (define-key km "\C-c\C-k" 'bibtex-kill-optional-field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (define-key km "\C-c\C-d" 'bibtex-empty-field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 ;; [alarson:19920131.1543CST]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (define-key km "\"" 'tex-insert-quote)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (define-key km "\C-c$" 'ispell-bibtex-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (define-key km "\M-\C-a" 'beginning-of-bibtex-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (define-key km "\M-\C-e" 'end-of-bibtex-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (define-key km "\C-c\C-b" 'bibtex-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 ; (define-key km "\C-cn" 'narrow-to-bibtex-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (define-key km "\C-c\C-e\C-a" 'bibtex-Article)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 (define-key km "\C-c\C-e\C-b" 'bibtex-Book)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 ; (define-key km "\C-c\C-e\C-d" 'bibtex-DEAthesis)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (define-key km "\C-c\C-e\C-c" 'bibtex-InProceedings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (define-key km "\C-c\C-e\C-i" 'bibtex-InBook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (define-key km "\C-c\C-ei" 'bibtex-InCollection)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (define-key km "\C-c\C-eI" 'bibtex-InProceedings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (define-key km "\C-c\C-e\C-m" 'bibtex-Manual)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 (define-key km "\C-c\C-em" 'bibtex-MastersThesis)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (define-key km "\C-c\C-eM" 'bibtex-Misc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 (define-key km "\C-c\C-o" 'bibtex-remove-OPT)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (define-key km "\C-c\C-e\C-p" 'bibtex-PhdThesis)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (define-key km "\C-c\C-ep" 'bibtex-Proceedings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (define-key km "\C-c\C-eP" 'bibtex-preamble)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (define-key km "\C-c\C-e\C-t" 'bibtex-TechReport)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (define-key km "\C-c\C-e\C-s" 'bibtex-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (define-key km "\C-c\C-e\C-u" 'bibtex-Unpublished)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (define-key km 'button3 'bibtex-menu)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 km))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (defvar bibtex-pop-previous-search-point nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 "Next point where bibtex-pop-previous should start looking for a similar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 entry.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (defvar bibtex-pop-next-search-point nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 "Next point where bibtex-pop-next should start looking for a similar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 entry.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (defvar bibtex-entry-field-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 '(
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 ("Article" . ((("author" "title" "journal" "year")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 ("volume" "number" "pages" "month" "note"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 (("author" "title")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 ("journal" "year" "volume" "number" "pages"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 "month" "note"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 ("Book" . ((("author" "title" "publisher" "year")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 ("editor" "volume" "number" "series" "address"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 "edition" "month" "note"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 ("Booklet" . ((("title")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 ("author" "howpublished" "address" "month" "year" "note"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 ;; France: Dipl\^{o}me d'Etudes Approfondies (similar to Master's)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 ; ("DEAthesis" . ((("author" "title" "school" "year")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 ; ("address" "month" "note"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 ("InBook" . ((("author" "title" "chapter" "publisher" "year")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 ("editor" "pages" "volume" "number" "series" "address"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 "edition" "month" "type" "note"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 (("author" "title" "chapter")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 ("publisher" "year" "editor" "pages" "volume" "number"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 "series" "address" "edition" "month" "type" "note"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 ("InCollection" . ((("author" "title"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 "booktitle" "publisher" "year")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 ("editor" "volume" "number" "series" "type" "chapter"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 "pages" "address" "edition" "month" "note"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 (("author" "title")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 ("booktitle" "publisher" "year"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 "editor" "volume" "number" "series" "type" "chapter"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 "pages" "address" "edition" "month" "note"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 ("InProceedings" . ((("author" "title" "booktitle" "year")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 ("editor" "volume" "number" "series" "pages"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 "organization" "publisher" "address" "month" "note"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 (("author" "title")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 ("editor" "volume" "number" "series" "pages"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 "booktitle" "year"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 "organization" "publisher" "address" "month" "note"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 ("Manual" . ((("title")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 ("author" "organization" "address" "edition" "year"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 "month" "note"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 ("MastersThesis" . ((("author" "title" "school" "year")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 ("address" "month" "note" "type"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 ("Misc" . ((()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 ("author" "title" "howpublished" "year" "month" "note"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 ("PhdThesis" . ((("author" "title" "school" "year")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 ("address" "month" "type" "note"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 ("Proceedings" . ((("title" "year")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 ("editor" "volume" "number" "series" "publisher"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 "organization" "address" "month" "note"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 ("TechReport" . ((("author" "title" "institution" "year")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 ("type" "number" "address" "month" "note"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 ("Unpublished" . ((("author" "title" "note")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 ("year" "month"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 "List of (entry-name (required optional) (crossref-required crossref-optional))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 tripples. If the third element is nil, then the first pair can be used. Required
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 and optional are lists of strings. All entry creation functions use this variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 to generate entries, and bibtex-entry ensures the entry type is valid. This
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 variable can be used for example to make bibtex manipulate a different set of entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 types, e.g. a crossreference document of organization types.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 ;;; A bibtex file is a sequence of entries, either string definitions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 ;;; or reference entries. A reference entry has a type part, a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 ;;; key part, and a comma-separated sequence of fields. A string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 ;;; entry has a single field. A field has a left and right part,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 ;;; separated by a '='. The left part is the name, the right part is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 ;;; the text. Here come the definitions allowing to create and/or parse
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 ;;; entries and fields:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 ;;; fields
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 (defun bibtex-cfield (name text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 "Create a regexp for a bibtex field of name NAME and text TEXT"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (concat ",[ \t\n]*\\("
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 "\\)[ \t\n]*=[ \t\n]*\\("
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 text
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 "\\)"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 (defconst bibtex-name-in-cfield 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 "The regexp subexpression number of the name part in bibtex-cfield.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 (defconst bibtex-text-in-cfield 2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 "The regexp subexpression number of the text part in bibtex-cfield.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 ;;; KAWATA Yasuro <yasuro@qqqq.maekawa.is.uec.ac.jp> reported bug that "/"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 ;;; was not premitted in field names. The old value of this var was:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 ;;; "[A-Za-z][---A-Za-z0-9:_+]*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 ;;; According to the LaTeX manual, page 71, the legal values are letters,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 ;;; digits, and punctuation other than comma. Section 2.1 defines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 ;;; punctuation as:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 ;;; .:;,?!`'()[]-/*@
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 ;;; and says that += can be used in normal text. Specifically #$%&~_^\{}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 ;;; are called out as special chars. Some experimentation with LaTeX
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 ;;; indicates that # and ~ definitely don't work, but that the following
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 ;;; citation does! \cite{a0.:;?!`'()[]-/*@_&$^+=|<>}. I chose here to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 ;;; permit _ since it was previously allowed, but otherwise to only handle
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 ;;; punc and +=
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 ;;; Amendment: I couldn't get a regexp with both "[]"'s and hyphen to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 ;;; work. It looks like you need them both to be the first entries in a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 ;;; regexp pattern. [alarson:19930315.0900CST]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 (defconst bibtex-field-name "[A-Za-z][---A-Za-z0-9.:;?!`'()/*@_+=]*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 "Regexp defining the name part of a bibtex field.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 ;; bibtex-field-text must be able to handle
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 ;; title = "Proc. Fifteenth Annual" # STOC,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 ;; month = "10~" # jan,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 ;; year = "{\noopsort{1973c}}1981",
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 ;; month = apr # "-" # may,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 ;; key = {Volume-2},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 ;; note = "Volume~2 is listed under Knuth \cite{book-full}"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 ;; i have added a few of these, but not all! -- MON
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 (defconst bibtex-field-const
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 "[0-9A-Za-z][---A-Za-z0-9:_+]*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 "Format of a bibtex field constant.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 (defconst bibtex-field-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 "\"[^\"]*[^\\\\]\"\\|\"\"")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 "Match either a string or an empty string.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 (defconst bibtex-field-string-or-const
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 (concat bibtex-field-const "\\|" bibtex-field-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 "Match either bibtex-field-string or bibtex-field-const.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 (defconst bibtex-field-text
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 "\\(" bibtex-field-string-or-const "\\)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 "\\([ \t\n]+#[ \t\n]+\\(" bibtex-field-string-or-const "\\)\\)*\\|"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 "{[^{}]*[^\\\\]}")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 "Regexp defining the text part of a bibtex field: either a string, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 an empty string, or a constant followed by one or more # / constant pairs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 Also matches simple {...} patterns.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 ;(defconst bibtex-field-text
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 ; "\"[^\"]*[^\\\\]\"\\|\"\"\\|[0-9A-Za-z][---A-Za-z0-9:_+]*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 ; "Regexp defining the text part of a bibtex field: either a string, or an empty string, or a constant.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 (defconst bibtex-field
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (bibtex-cfield bibtex-field-name bibtex-field-text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 "Regexp defining the format of a bibtex field")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 (defconst bibtex-name-in-field bibtex-name-in-cfield
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 "The regexp subexpression number of the name part in bibtex-field")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 (defconst bibtex-text-in-field bibtex-text-in-cfield
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 "The regexp subexpression number of the text part in bibtex-field")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 ;;; references
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 (defconst bibtex-reference-type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 "@[A-Za-z]+"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 "Regexp defining the type part of a bibtex reference entry")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 (defconst bibtex-reference-head
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 (concat "^[ \t]*\\("
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 bibtex-reference-type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 "\\)[ \t]*[({]\\("
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 bibtex-field-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 "\\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 "Regexp defining format of the header line of a bibtex reference entry")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 (defconst bibtex-type-in-head 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 "The regexp subexpression number of the type part in bibtex-reference-head")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 (defconst bibtex-key-in-head 2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 "The regexp subexpression number of the key part in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 bibtex-reference-head")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 (defconst bibtex-reference
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 (concat bibtex-reference-head
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 "\\([ \t\n]*" bibtex-field "\\)*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 "[ \t\n]*[})]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 "Regexp defining the format of a bibtex reference entry")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 (defconst bibtex-type-in-reference bibtex-type-in-head
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 "The regexp subexpression number of the type part in bibtex-reference")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 (defconst bibtex-key-in-reference bibtex-key-in-head
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 "The regexp subexpression number of the key part in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 bibtex-reference")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 ;;; strings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 (defconst bibtex-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 (concat "^[ \t]*@[sS][tT][rR][iI][nN][gG][ \t\n]*[({][ \t\n]*\\("
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 bibtex-field-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 "\\)[ \t\n]*=[ \t\n]*\\("
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 bibtex-field-text
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 "\\)[ \t\n]*[})]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 "Regexp defining the format of a bibtex string entry")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 (defconst bibtex-name-in-string 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 "The regexp subexpression of the name part in bibtex-string")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 (defconst bibtex-text-in-string 2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 "The regexp subexpression of the text part in bibtex-string")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 (defconst bibtex-name-alignment 2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 "Alignment for the name part in BibTeX fields.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 Chosen on aesthetic grounds only.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 (defconst bibtex-text-alignment (length " organization = ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 "Alignment for the text part in BibTeX fields.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 Equal to the space needed for the longest name part.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 (defun bibtex-current-entry-label (&optional include-cite kill)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 "Return the label of the bibtex entry containing, or preceding point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 Optional argument INCLUDE-CITE, if true means put a '\\cite{}' around the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 returned value. Second optional argument KILL, if true, means place the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 returned value in the kill buffer. Interactively; providing prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 argument makes INCLUDE-CITE true, and kill is true by default.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 Rationale:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 The intention is that someone will write a function that can be bound to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 a mouse key so that people entering TeX can just mouse on the bibtex entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 and have the citation key inserted at the current point (which will almost
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 certainly be in some other buffer). In the interim this function is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 marginally useful for keyboard binding and is not bound by default.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 Suggested binding is ^C-k."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 (interactive (list current-prefix-arg t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 (beginning-of-bibtex-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 (re-search-forward bibtex-reference-head (save-excursion (end-of-bibtex-entry) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 (let* ((key (buffer-substring (match-beginning bibtex-key-in-head)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 (match-end bibtex-key-in-head)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 (val (if include-cite
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 (format "\\cite{%s}" key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 key)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 (if kill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 (put-string-on-kill-ring val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 val)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 ;;; bibtex mode:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 (defun bibtex-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 "Major mode for editing bibtex files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 \\{bibtex-mode-map}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 A command such as \\[bibtex-Book] will outline the fields for a BibTeX book entry.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 The optional fields start with the string OPT, and thus ignored by BibTeX.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 The OPT string may be removed from a field with \\[bibtex-remove-OPT].
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 \\[bibtex-kill-optional-field] kills the current optional field entirely.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 \\[bibtex-remove-double-quotes] removes the double-quotes around the text of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 the current field. \\[bibtex-empty-field] replaces the text of the current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 field with the default \"\".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 The command \\[bibtex-clean-entry] cleans the current entry, i.e. (i) removes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 double-quotes from entirely numerical fields, (ii) removes OPT from all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 non-empty optional fields, (iii) removes all empty optional fields, and (iv)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 checks that no non-optional fields are empty.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 Use \\[bibtex-find-text] to position the dot at the end of the current field.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 Use \\[bibtex-next-field] to move to end of the next field.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 The following may be of interest as well:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 Functions:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 find-bibtex-duplicates
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 find-bibtex-entry-location
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 hide-bibtex-entry-bodies
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 sort-bibtex-entries
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 validate-bibtex-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 Variables:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 bibtex-clean-entry-zap-empty-opts
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 bibtex-entry-field-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 bibtex-include-OPTannote
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 bibtex-include-OPTcrossref
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 bibtex-include-OPTkey
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 bibtex-maintain-sorted-entries
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 bibtex-mode-user-optional-fields
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 Fields:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 address
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 Publisher's address
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 annote
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 Long annotation used for annotated bibliographies (begins sentence)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 author
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 Name(s) of author(s), in BibTeX name format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 booktitle
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 Book title when the thing being referenced isn't the whole book.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 For book entries, the title field should be used instead.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 chapter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 Chapter number
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 crossref
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 The database key of the entry being cross referenced.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 edition
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 Edition of a book (e.g., \"second\")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 editor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 Name(s) of editor(s), in BibTeX name format.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 If there is also an author field, then the editor field should be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 for the book or collection that the work appears in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 howpublished
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 How something strange has been published (begins sentence)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 institution
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 Sponsoring institution
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 journal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 Journal name (macros are provided for many)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 Alphabetizing and labeling key (needed when no author or editor)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 month
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 Month (macros are provided)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 note
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 To help the reader find a reference (begins sentence)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 number
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 Number of a journal or technical report
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 organization
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 Organization (sponsoring a conference)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 pages
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 Page number or numbers (use `--' to separate a range)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 publisher
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 Publisher name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 school
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 School name (for theses)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 series
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 The name of a series or set of books.
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
672 An individual book will also have its own title
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 title
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 The title of the thing being referenced
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 Type of a technical report (e.g., \"Research Note\") to be used
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 instead of the default \"Technical Report\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 volume
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 Volume of a journal or multivolume work
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 year
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 Year---should contain only numerals
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 ---------------------------------------------------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 Entry to this mode calls the value of bibtex-mode-hook if that value is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 non-nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 (kill-all-local-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 (set-syntax-table bibtex-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 (use-local-map bibtex-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 (setq major-mode 'bibtex-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 (setq mode-name "BibTeX")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 (set-syntax-table bibtex-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 (setq local-abbrev-table bibtex-mode-abbrev-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 (make-local-variable 'paragraph-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 (setq paragraph-start "^[ \f\n\t]*$")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 (auto-fill-mode 1) ; nice alignments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 (setq left-margin (+ bibtex-text-alignment 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 (run-hooks 'bibtex-mode-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 (defun bibtex-move-outside-of-entry ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 "Make sure we are outside of a bib entry"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 (cond ((or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 (= (point) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 (= (point) (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 (looking-at "[ \n]*@")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 (backward-paragraph)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 (forward-paragraph)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 (re-search-forward "[ \t\n]*" (point-max) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 (defun ispell-abstract ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 (beginning-of-bibtex-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 (re-search-forward "^[ \t]*[OPT]*abstract[ \t]*=")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 (ispell-region (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 (save-excursion (forward-sexp) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 (defun beginning-of-bibtex-entry ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 (re-search-backward "^@" nil 'move))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 (defun skip-whitespace-and-comments ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 ;; It might be a good idea to have forward-sexp with argument 0 do what
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 ;; this function tries to do, namely skip whitespace and comments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 ;; Maybe a better name for this would be skip-to-next-sexp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 ;; alternative implementation:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 ;; (let ((parse-sexp-ignore-comments t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 ;; (forward-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 ;; (forward-sexp -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 ;; but I've had problems with this not getting the parse of comments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 ;; right going backward if they contain unbalanced expressions or string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 ;; quotes. [alarson:19920217.1021CST]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 (let ((md (match-data)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 (while (cond ((looking-at "\\s>+\\|\\s +")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 ;; was whitespace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 ;; NOTE: also checked end-comment. In latex and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 ;; lisp modes, newline is an end comment, but it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 ;; should also be a whitespace char.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 (goto-char (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 ;; If looking at beginning of comment, skip to end.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 ((looking-at "\\s<")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 (re-search-forward "\\s>"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 (store-match-data md))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 ;;; [alarson:19920214.1007CST]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 (defun end-of-bibtex-entry ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 "If inside an entry, move to the end of it, otherwise move to the end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 of the next entry."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 ;; if point was previously at the end of an entry, this puts us
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 ;; inside the next entry, otherwise we remain in the current one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 (skip-whitespace-and-comments)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 ;;; (skip-chars-forward " \t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 (end-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 (beginning-of-bibtex-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 (let ((parse-sexp-ignore-comments t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 (forward-sexp) ; skip entry type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 (forward-sexp) ; skip entry body
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 ;(defun end-of-bibtex-entry ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 ; (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 ; (re-search-forward "}$" nil 'move))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 (defun ispell-bibtex-entry ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 (ispell-region (progn (beginning-of-bibtex-entry) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 (progn (end-of-bibtex-entry) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 (defun narrow-to-bibtex-entry ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 (narrow-to-region (progn (beginning-of-bibtex-entry) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 (progn (end-of-bibtex-entry) (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 (defun beginning-of-first-bibtex-entry ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 ((re-search-forward "^@" nil 'move)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 (beginning-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 ((and (bobp) (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 (message "Warning: No bibtex entries found!"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 (defun hide-bibtex-entry-bodies (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 "Hide all lines between first and last bibtex entries not beginning with @.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 With argument, show all text."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 (beginning-of-first-bibtex-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 ;; subst-char-in-region modifies the buffer, despite what the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 ;; documentation says...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 (let ((modifiedp (buffer-modified-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 (buffer-read-only nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 (if arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 (subst-char-in-region (point) (point-max) ?\r ?\n t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 (while (save-excursion (re-search-forward "\n[^@]" (point-max) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 (save-excursion (replace-regexp "\n\\([^@]\\)" "\r\\1"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 (setq selective-display (not arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 (set-buffer-modified-p modifiedp))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 (defvar bibtex-sort-ignore-string-entries nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 "*If true, bibtex @STRING entries are ignored when determining ordering
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 of the buffer (e.g. sorting, locating alphabetical position for new entries,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 etc.)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 (defun sort-bibtex-entries ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 "Sort bibtex entries alphabetically by key.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 Text before the first bibtex entry, and following the last is not affected.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 If bibtex-sort-ignore-string-entries is true, @string entries will be ignored.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 Bugs:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 1. Text between the closing brace ending one bibtex entry, and the @ starting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 the next, is considered part of the PRECEDING entry. Perhaps it should be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 part of the following entry."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 (beginning-of-first-bibtex-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 (narrow-to-region (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 (beginning-of-bibtex-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 (end-of-bibtex-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 (sort-subr nil ; reversep
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 ;; beginning of record function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 'forward-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 ;; end of record function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 (function (lambda () (and (re-search-forward "}\\s-*\n[\n \t]*@" nil 'move)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 (forward-char -2))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 ;; start of key function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 (if bibtex-sort-ignore-string-entries
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 (function (lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 (while (and (re-search-forward "^\\s-*\\([@a-zA-Z]*\\)\\s-*{\\s-*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 (string-equalp "@string"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 (buffer-substring (match-beginning 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 (match-end 1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 (function (lambda () (re-search-forward "{\\s-*") nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 ;; end of key function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 (function (lambda () (search-forward ",")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 (defun map-bibtex-entries (fun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 "Call FUN for each bibtex entry starting with the current, to the end of the file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 FUN is called with one argument, the key of the entry, and with point inside the entry.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 If bibtex-sort-ignore-string-entries is true, FUN will not be called for @string entries."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 (beginning-of-bibtex-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 (while (re-search-forward "^@[^{]*{[ \t]*\\([^, ]*\\)" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 (if (and bibtex-sort-ignore-string-entries
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 (string-equalp "@string{"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 (buffer-substring (match-beginning 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 (match-beginning 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 nil ; ignore the @string entry.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 (funcall fun (buffer-substring (match-beginning 1) (match-end 1))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 (defun find-bibtex-entry-location (entry-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 "Searches from beginning of current buffer looking for place to put the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 bibtex entry named ENTRY-NAME. Buffer is assumed to be in sorted order,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 without duplicates (see \\[sort-bibtex-entries]), if it is not, an error will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 be signalled."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 (interactive "sBibtex entry key: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 (let ((previous nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 (beginning-of-first-bibtex-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 (or (catch 'done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 (map-bibtex-entries (function (lambda (current)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 ((string-equal entry-name current)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 (error "Entry duplicates existing!"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 ((or (null previous)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 (string< previous current))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 (setq previous current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 (if (string< entry-name current)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 (beginning-of-bibtex-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 ;; Many schemes append strings to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 ;; existing entries to resolve them,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 ;; so initial substring matches may
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 ;; indicate a duplicate entry.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 (let ((idx (string-match (regexp-quote entry-name) current)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 (if (and (integerp idx)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 (zerop idx))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 (message "Warning: Entry %s may be a duplicate of %s!"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 entry-name current)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 (ding t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 (throw 'done t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 ((string-equal previous current)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 (error "Duplicate here with previous!"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 (t (error "Entries out of order here!")))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 (end-of-bibtex-entry))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 (defun validate-bibtex-buffer ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 "Find some typical errors in bibtex files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 1. At signs (@) not as first char of a line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 2. Double quotes (\") inside strings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904 3. Closing braces (}) not the last character of a line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 (let ((point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 (while (re-search-forward ".@" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 (let* ((foo (parse-partial-sexp (save-excursion (beginning-of-bibtex-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 (in-a-string (nth 3 foo)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 (if (not in-a-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 (error "At sign (@) out of place!"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 (goto-char point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 (while (search-forward "\"" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 (or (looking-at "[,}][ \t]*$")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 (char-equal (preceding-char) ?\")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 ;; some versions put closing brace on separate line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 (looking-at "[ \t]*\n}")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922 (narrow-to-region (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923 (progn (beginning-of-line) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 (looking-at "^[ \t]*[a-zA-Z]+[ \t]*=[ \t]*\"$")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 (error "Quote out of place, or missing \",\" or \"}\"!")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 (goto-char point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 ;; This is only approximate, should actually search for close braces,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 ;; then see if they are inside a string, or at the end of a line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 ;; This just gets the typical case of whitespace after a closing brace.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930 (while (search-forward "}[ \t]+$" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931 (error "Brace not last char of line!"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 (goto-char point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933 (message "Bibtex buffer appears o.k.")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935 (defun find-bibtex-duplicates ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936 "Searches forward in current buffer looking for duplicate bibtex entries.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 Buffer is assumed to be sorted, see \\[sort-bibtex-entries]"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 (let ((point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 ;; errors if things are not right...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941 (find-bibtex-entry-location (make-string 10 255))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942 (goto-char point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943 (message "No duplicates found!")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946 ;;; assoc doesn't ignore case, so we need an assoc that does...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947 (defun assoc-string-equalp (thing alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948 (or (assoc thing alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949 (while (and alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950 (not (string-equalp thing (car (car alist)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 (setq alist (cdr alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952 (car alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954 (defvar bibtex-maintain-sorted-entries nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955 "*If true, bibtex-mode will attempt to maintain all bibtex entries in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 sorted order.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958 Note that this is more a property of a file than a personal preference and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959 as such should normally be set via a file local variable entry.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961 (defun bibtex-entry (entry-type &optional required optional)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962 (interactive (let* ((completion-ignore-case t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963 (e-t (completing-read "Entry Type: " bibtex-entry-field-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964 nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 (list e-t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966 (if (and (null required) (null optional))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967 (let* ((e (assoc-string-equalp entry-type bibtex-entry-field-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968 (r-n-o (elt e 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969 (c-ref (elt e 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 (if (null e)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971 (error "Bibtex entry type %s not defined!"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
972 (if (and bibtex-include-OPTcrossref c-ref)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973 (setq required (elt c-ref 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974 optional (elt c-ref 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975 (setq required (elt r-n-o 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
976 optional (elt r-n-o 1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977 (let ((key (if bibtex-maintain-sorted-entries
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978 (read-string (format "%s key: " entry-type)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979 (if key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980 (find-bibtex-entry-location key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981 (bibtex-move-outside-of-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
982 (insert "@" entry-type "{")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
983 (if key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984 (insert key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986 (mapcar 'bibtex-make-field required)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987 (if bibtex-include-OPTcrossref
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988 (bibtex-make-optional-field "crossref"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989 (if bibtex-include-OPTkey
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990 (bibtex-make-optional-field "key"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
991 (mapcar 'bibtex-make-optional-field optional)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
992 (mapcar 'bibtex-make-optional-field
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
993 bibtex-mode-user-optional-fields)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
994 (if bibtex-include-OPTannote
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
995 (bibtex-make-optional-field "annote"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996 (insert "\n}\n\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997 (if key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998 (bibtex-next-field t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999 (run-hooks 'bibtex-add-entry-hook)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1001 ;; (defun bibtex-entry (entry-type required optional)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002 ;; (bibtex-move-outside-of-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003 ;; (insert (concat "@" entry-type "{,\n\n}\n\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004 ;; (previous-line 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005 ;; (insert (mapconcat 'bibtex-make-entry required ",\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006 ;; (if required
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007 ;; (if optional
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008 ;; (insert ",\n")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009 ;; (insert (mapconcat 'bibtex-make-OPT-entry optional ",\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010 ;; (if bibtex-mode-user-optional-fields ;MON...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011 ;; (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012 ;; (if optional
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013 ;; (insert ",\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1014 ;; (insert (mapconcat 'bibtex-make-OPT-entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1015 ;; bibtex-mode-user-optional-fields
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1016 ;; ",\n")))) ;MON
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1017 ;; (up-list -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1018 ;; (forward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1019
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1021 (defun bibtex-make-field (e-t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022 (interactive "sBibTeX entry type: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1023 (let ((name (if (consp e-t) (car e-t) e-t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024 (value (if (consp e-t) (cdr e-t) "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1025 (insert ",\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1026 (indent-to-column bibtex-name-alignment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1027 (insert name " = ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1028 (indent-to-column bibtex-text-alignment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1029 ;; lucid emacs prin1-to-string breaks the undo chain. When they fix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1030 ;; that, the hack can be removed. [alarson:19930316.0805CST]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1031 ; (insert (prin1-to-string value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1032 ;; begin hack
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1033 (insert (format (if (stringp value) "\"%s\"" "%s")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1034 value))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1035 ;; end hack
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1037
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1038 (defun bibtex-make-optional-field (e-t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1039 (interactive "sOptional BibTeX entry type: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1040 (if (consp e-t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1041 (setq e-t (cons (concat "OPT" (car e-t)) (cdr e-t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1042 (setq e-t (concat "OPT" e-t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1043 (bibtex-make-field e-t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1044
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1045 ;; What to do about crossref? if present, journal and year are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1046 ;; both optional. Due to this, i move all of them into optional. -- MON
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1047
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1048 (defun bibtex-Article ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1049 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1050 (bibtex-entry "Article"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1051
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1052 (defun bibtex-Book ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1053 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1054 (bibtex-entry "Book"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1055
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1056 (defun bibtex-Booklet ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1057 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1058 (bibtex-entry "Booklet"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1059
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1060 ;(defun bibtex-DEAthesis ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1061 ; (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1062 ; (bibtex-entry "DEAthesis"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1063
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1064 (defun bibtex-InBook ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1065 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1066 (bibtex-entry "InBook"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1067
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1068 (defun bibtex-InCollection ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1069 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1070 (bibtex-entry "InCollection"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1071
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1072 (defun bibtex-InProceedings ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1073 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1074 (bibtex-entry "InProceedings"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1075
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1076 (defun bibtex-Manual ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1077 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1078 (bibtex-entry "Manual"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1079
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1080 (defun bibtex-MastersThesis ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1081 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1082 (bibtex-entry "MastersThesis"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1083
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1084 (defun bibtex-Misc ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1085 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1086 (bibtex-entry "Misc"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1087
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1088 (defun bibtex-PhdThesis ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1089 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1090 (bibtex-entry "PhdThesis"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1091
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1092 (defun bibtex-Proceedings ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1093 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1094 (bibtex-entry "Proceedings"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1095
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1096 (defun bibtex-TechReport ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1097 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1098 (bibtex-entry "TechReport"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1099
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1100 (defun bibtex-Unpublished ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1101 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1102 (bibtex-entry "Unpublished"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1103
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1104 (defun bibtex-string ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1105 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1106 (bibtex-move-outside-of-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1107 (insert "@string{ = \"\"}\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1108 (previous-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1109 (forward-char 8))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1110
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1111 (defun bibtex-preamble ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1112 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1113 (bibtex-move-outside-of-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1114 (insert "@Preamble{}\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1115 (previous-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1116 (forward-char 10))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1118 (defun bibtex-next-field (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1119 "Finds end of text of next BibTeX field; with arg, to its beginning"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1120 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1121 (bibtex-inside-field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1122 (let ((start (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1123 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1124 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1125 (bibtex-enclosing-field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1126 (goto-char (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1127 (forward-char 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1128 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1129 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1130 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1131 (forward-char 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1132 (bibtex-find-text arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1133
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1134 ;; (defun bibtex-next-field ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1135 ;; "Finds end of text of next field."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1136 ;; (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1137 ;; (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1138 ;; (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1139 ;; (bibtex-inside-field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1140 ;; (re-search-forward ",[ \t\n]*" (point-max) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1141 ;; (bibtex-enclosing-field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1142 ;; (bibtex-inside-field))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1143 ;; (error nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1144
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1145 (defun bibtex-find-text (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1146 "Go to end of text of current field; with arg, go to beginning."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1147 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1148 (bibtex-inside-field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1149 (bibtex-enclosing-field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1150 (if arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1151 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1152 (goto-char (match-beginning bibtex-text-in-field))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1153 (if (looking-at "\"")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1154 (forward-char 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1155 (goto-char (match-end bibtex-text-in-field))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1156 (if (= (preceding-char) ?\")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1157 (forward-char -1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1158
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1159 ;; (defun bibtex-find-text ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1160 ;; "Go to end of text of current field."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1161 ;; (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1162 ;; (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1163 ;; (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1164 ;; (bibtex-inside-field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1165 ;; (bibtex-enclosing-field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1166 ;; (goto-char (match-end bibtex-text-in-field))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1167 ;; (bibtex-inside-field))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1168 ;; (error nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1169
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1170 (defun bibtex-remove-OPT ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1171 "Removes the 'OPT' starting optional arguments and goes to end of text"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1172 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1173 (bibtex-inside-field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1174 (bibtex-enclosing-field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1175 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1176 (goto-char (match-beginning bibtex-name-in-field))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1177 (if (looking-at "OPT")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1178 ;; sct@dcs.edinburgh.ac.uk
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1179 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1180 (delete-char (length "OPT"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1181 (search-forward "=")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1182 (delete-horizontal-space)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1183 (indent-to-column bibtex-text-alignment))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1184 (bibtex-inside-field))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1185
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1186 (defun bibtex-inside-field ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1187 "Try to avoid point being at end of a bibtex field."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1188 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1189 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1190 (skip-chars-backward " \t") ;MON - maybe delete these chars?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1191 (cond ((= (preceding-char) ?,)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1192 (forward-char -2))) ; -1 --> -2 sct@dcs.edinburgh.ac.uk
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1193 (cond ((= (preceding-char) ?\")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1194 (forward-char -1)))) ;MON - only go back if quote
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1195
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1196 (defun bibtex-remove-double-quotes ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1197 "Removes \"\" around string."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1198 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1199 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1200 (bibtex-inside-field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1201 (bibtex-enclosing-field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1202 (let ((start (match-beginning bibtex-text-in-field))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1203 (stop (match-end bibtex-text-in-field)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1204 (goto-char stop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1205 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1206 (if (looking-at "\"")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1207 (delete-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1208 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1209 (if (looking-at "\"")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1210 (delete-char 1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1211
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1212 (defun bibtex-kill-optional-field ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1213 "Kill the entire enclosing optional BibTeX field"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1214 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1215 (bibtex-inside-field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1216 (bibtex-enclosing-field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1217 (goto-char (match-beginning bibtex-name-in-field))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1218 (let ((the-end (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1219 (the-beginning (match-beginning 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1220 (if (looking-at "OPT")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1221 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1222 (goto-char the-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1223 (skip-chars-forward " \t\n,")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1224 (kill-region the-beginning the-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1225 (error "Mandatory fields can't be killed"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1226
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1227 (defun bibtex-empty-field ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1228 "Delete the text part of the current field, replace with empty text"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1229 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1230 (bibtex-inside-field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1231 (bibtex-enclosing-field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1232 (goto-char (match-beginning bibtex-text-in-field))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1233 (kill-region (point) (match-end bibtex-text-in-field))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1234 (insert "\"\"")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1235 (bibtex-find-text t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1236
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1237
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1238 (defun bibtex-pop-previous (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1239 "Replace text of current field with the text of similar field in previous entry.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1240 With arg, go up ARG entries. Repeated, goes up so many times. May be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1241 intermixed with \\[bibtex-pop-next] (bibtex-pop-next)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1242 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1243 (bibtex-inside-field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1244 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1245 ; parse current field
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1246 (bibtex-enclosing-field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1247 (let ((start-old-text (match-beginning bibtex-text-in-field))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1248 (stop-old-text (match-end bibtex-text-in-field))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1249 (start-name (match-beginning bibtex-name-in-field))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1250 (stop-name (match-end bibtex-name-in-field))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1251 (new-text))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1252 (goto-char start-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1253 ; construct regexp for previous field with same name as this one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1254 (let ((matching-entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1255 (bibtex-cfield
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1256 (buffer-substring (if (looking-at "OPT")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1257 (+ (point) (length "OPT"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1258 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1259 stop-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1260 bibtex-field-text)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1261
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1262 ; if executed several times in a row, start each search where the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1263 ; last one finished
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1264 (cond ((or (eq last-command 'bibtex-pop-previous)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1265 (eq last-command 'bibtex-pop-next))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1266 t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1267 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1268 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1269 (bibtex-enclosing-reference)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1270 (setq bibtex-pop-previous-search-point (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1271 (setq bibtex-pop-next-search-point (match-end 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1272 (goto-char bibtex-pop-previous-search-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1273
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1274 ; Now search for arg'th previous similar field
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1275 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1276 ((re-search-backward matching-entry (point-min) t arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1277 (setq new-text
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1278 (buffer-substring (match-beginning bibtex-text-in-cfield)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1279 (match-end bibtex-text-in-cfield)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1280 ; Found a matching field. Remember boundaries.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1281 (setq bibtex-pop-next-search-point (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1282 (setq bibtex-pop-previous-search-point (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1283 (bibtex-flash-head)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1284 ; Go back to where we started, delete old text, and pop new.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1285 (goto-char stop-old-text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1286 (delete-region start-old-text stop-old-text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1287 (insert new-text))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1288 (t ; search failed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1289 (error "No previous matching BibTeX field."))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1290 (setq this-command 'bibtex-pop-previous))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1291
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1292 (defun bibtex-pop-next (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1293 "Replace text of current field with the text of similar field in next entry.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1294 With arg, go up ARG entries. Repeated, goes up so many times. May be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1295 intermixed with \\[bibtex-pop-previous] (bibtex-pop-previous)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1296 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1297 (bibtex-inside-field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1298 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1299 ; parse current field
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1300 (bibtex-enclosing-field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1301 (let ((start-old-text (match-beginning bibtex-text-in-field))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1302 (stop-old-text (match-end bibtex-text-in-field))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1303 (start-name (match-beginning bibtex-name-in-field))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1304 (stop-name (match-end bibtex-name-in-field))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1305 (new-text))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1306 (goto-char start-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1307 ; construct regexp for next field with same name as this one,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1308 ; ignoring possible OPT's
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1309 (let ((matching-entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1310 (bibtex-cfield
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1311 (buffer-substring (if (looking-at "OPT")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1312 (+ (point) (length "OPT"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1313 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1314 stop-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1315 bibtex-field-text)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1316
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1317 ; if executed several times in a row, start each search where the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1318 ; last one finished
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1319 (cond ((or (eq last-command 'bibtex-pop-next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1320 (eq last-command 'bibtex-pop-previous))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1321 t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1322 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1323 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1324 (bibtex-enclosing-reference)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1325 (setq bibtex-pop-previous-search-point (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1326 (setq bibtex-pop-next-search-point (match-end 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1327 (goto-char bibtex-pop-next-search-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1328
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1329 ; Now search for arg'th next similar field
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1330 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1331 ((re-search-forward matching-entry (point-max) t arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1332 (setq new-text
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1333 (buffer-substring (match-beginning bibtex-text-in-cfield)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1334 (match-end bibtex-text-in-cfield)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1335 ; Found a matching field. Remember boundaries.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1336 (setq bibtex-pop-next-search-point (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1337 (setq bibtex-pop-previous-search-point (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1338 (bibtex-flash-head)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1339 ; Go back to where we started, delete old text, and pop new.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1340 (goto-char stop-old-text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1341 (delete-region start-old-text stop-old-text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1342 (insert new-text))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1343 (t ; search failed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1344 (error "No next matching BibTeX field."))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1345 (setq this-command 'bibtex-pop-next))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1346
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1347 (defun bibtex-flash-head ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1348 "Flash at BibTeX reference head before point, if exists. (Moves point)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1349 (let ((flash))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1350 (cond ((re-search-backward bibtex-reference-head (point-min) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1351 (goto-char (match-beginning bibtex-type-in-head))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1352 (setq flash (match-end bibtex-key-in-reference)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1353 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1354 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1355 (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1356 (setq flash (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1357 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1358 (skip-chars-forward " \t")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1359 (if (pos-visible-in-window-p (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1360 (sit-for 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1361 (message "From: %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1362 (buffer-substring (point) flash)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1363
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1364
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1365
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1366 (defun bibtex-enclosing-field ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1367 "Search for BibTeX field enclosing point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1368 Point moves to end of field; also, use match-beginning and match-end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1369 to parse the field."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1370 ;; sct@dcs.edinburgh.ac.uk
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1371 (let ((old-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1372 (condition-case errname
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1373 (bibtex-enclosing-regexp bibtex-field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1374 (search-failed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1375 (goto-char old-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1376 (error "Can't find enclosing BibTeX field.")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1377
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1378 (defun bibtex-enclosing-reference ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1379 "Search for BibTeX reference enclosing point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1380 Point moves to end of reference; also, use match-beginning and match-end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1381 to parse the reference."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1382 ;; sct@dcs.edinburgh.ac.uk
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1383 (let ((old-point (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1384 (condition-case errname
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1385 (bibtex-enclosing-regexp bibtex-reference)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1386 (search-failed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1387 (goto-char old-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1388 (error "Can't find enclosing BibTeX reference.")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1389
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1390 (defun bibtex-enclosing-regexp (regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1391 "Search for REGEXP enclosing point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1392 Point moves to end of REGEXP. See also match-beginning and match-end.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1393 If an enclosing REGEXP is not found, signals search-failed; point is left in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1394 an undefined location.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1395
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1396 [Doesn't something like this exist already?]"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1397
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1398 (interactive "sRegexp: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1399 ; compute reasonable limits for the loop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1400 (let* ((initial (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1401 (right (if (re-search-forward regexp (point-max) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1402 (match-end 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1403 (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1404 (left
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1405 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1406 (goto-char initial)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1407 (if (re-search-backward regexp (point-min) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1408 (match-beginning 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1409 (point-min)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1410 ; within the prescribed limits, loop until a match is found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1411 (goto-char left)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1412 (re-search-forward regexp right nil 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1413 (if (> (match-beginning 0) initial)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1414 (signal 'search-failed (list regexp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1415 (while (<= (match-end 0) initial)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1416 (re-search-forward regexp right nil 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1417 (if (> (match-beginning 0) initial)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1418 (signal 'search-failed (list regexp))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1419 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1420
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1421 (defun bibtex-clean-entry ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1422 "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."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1423 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1424 (beginning-of-bibtex-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1425 (let ((start (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1426 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1427 (narrow-to-region start (save-excursion (end-of-bibtex-entry) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1428 (while (re-search-forward bibtex-field (point-max) t 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1429 (let ((begin-field (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1430 (end-field (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1431 (begin-name (match-beginning bibtex-name-in-field))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1432 (end-name (match-end bibtex-name-in-field))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1433 (begin-text (match-beginning bibtex-text-in-field))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1434 (end-text (match-end bibtex-text-in-field))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1435 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1436 (goto-char begin-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1437 (cond ((and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1438 (looking-at "OPT")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1439 bibtex-clean-entry-zap-empty-opts)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1440 (goto-char begin-text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1441 (if (looking-at "\"\"") ; empty: delete whole field
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1442 (delete-region begin-field end-field)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1443 ; otherwise: not empty, delete "OPT"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1444 (goto-char begin-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1445 (delete-char (length "OPT"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1446 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1447 ;; fixup alignment. [alarson:19920309.2047CST]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1448 (search-forward "=")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1449 (delete-horizontal-space)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1450 (indent-to-column bibtex-text-alignment))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1451 (goto-char begin-field) ; and loop to go through next test
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1452 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1453 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1454 (goto-char begin-text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1455 (cond ((looking-at "\"[0-9]+\"") ; if numerical,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1456 (goto-char end-text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1457 (delete-char -1) ; delete enclosing double-quotes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1458 (goto-char begin-text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1459 (delete-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1460 (goto-char end-field) ; go to end for next search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1461 (forward-char -2) ; to compensate for the 2 quotes deleted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1462 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1463 ((looking-at "\"\"") ; if empty quotes, complain
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1464 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1465 (if (not (or (equal (buffer-substring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1466 begin-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1467 (+ begin-name 3))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1468 "OPT")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1469 (equal (buffer-substring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1470 begin-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1471 (+ begin-name 3))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1472 "opt")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1473 (error "Mandatory field ``%s'' is empty"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1474 (buffer-substring begin-name end-name))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1475 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1476 (goto-char end-field))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1477 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1478 (end-of-bibtex-entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1479 ;; sct@dcs.edinburgh.ac.uk
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1480 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1481 (previous-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1482 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1483 (if (eq (preceding-char) ?,)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1484 (backward-delete-char 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1485 (skip-whitespace-and-comments)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1486
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1487
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1488 ;;; Menus for bibtex mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1489
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1490 (defconst bibtex-menu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1491 '("BibTeX Commands"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1492 "Entry Types"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1493 "---"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1494 ["Article in Conference Proceedings" bibtex-InProceedings t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1495 ["Article in Journal" bibtex-Article t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1496 ["Book" bibtex-Book t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1497 ["Booklet" bibtex-Booklet t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1498 ["Conference" bibtex-InProceedings t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1499 ["Master's Thesis" bibtex-MastersThesis t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1500 ["DEA Thesis" bibtex-DEAthesis t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1501 ["Phd. Thesis" bibtex-PhdThesis t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1502 ["Technical Report" bibtex-TechReport t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1503 ["Technical Manual" bibtex-Manual t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1504 ["Conference Proceedings" bibtex-Proceedings t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1505 ["A Chapter in a Book" bibtex-InBook t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1506 ["An Article in a Collection" bibtex-InCollection t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1507 ["Miscellaneous" bibtex-Misc t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1508 ["Unpublished" bibtex-Unpublished t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1509 ["String" bibtex-string t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1510 ["Preamble" bibtex-preamble t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1511 "---"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1512 "Bibtex Edit"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1513 "---"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1514 ["Next Field" bibtex-next-field t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1515 ["To End of Field" bibtex-find-text t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1516 ["Snatch From Similar Preceding Field" bibtex-pop-previous t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1517 ["Snatch From Similar Following Field" bibtex-pop-next t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1518 ["Remove OPT" bibtex-remove-OPT t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1519 ["Remove Quotes" bibtex-remove-double-quotes t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1520 ["Clean Up Entry" bibtex-clean-entry t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1521 ["Find Duplicates" find-bibtex-duplicates t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1522 ["Sort Entries" sort-bibtex-entries t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1523 ["Validate Entries" validate-bibtex-buffer t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1524 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1525
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1526 (defun bibtex-menu ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1527 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1528 (let ((popup-menu-titles nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1529 (popup-menu bibtex-menu)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1530
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1531 ;;; bibtex.el ends here