annotate lisp/modes/bib-mode.el @ 131:869e1851236b xemacs-20-1p4

Import from CVS: tag xemacs-20-1p4
author cvs
date Mon, 13 Aug 2007 09:29:07 +0200
parents ac2d302a0011
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 ;;; bib-mode.el --- bib-mode, major mode for editing bib files.
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) 1989 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 ;; Maintainer: FSF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Keywords: bib
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
8 ;; This file is part of XEmacs.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
10 ;; XEmacs is free software; you can redistribute it and/or modify it
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
11 ;; under the terms of the GNU General Public License as published by
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
15 ;; XEmacs is distributed in the hope that it will be useful, but
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
18 ;; General Public License for more details.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
23 ;; 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
25 ;;; Synched up with: FSF 19.34.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; GNU Emacs code to help maintain databases compatible with (troff)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; refer and lookbib. The file bib-file should be set to your
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;; bibliography file. Keys are automagically inserted as you type,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;; and appropriate keys are presented for various kinds of entries.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 (defvar bib-file "~/my-bibliography.bib"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 "Default name of file used by `addbib'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (defvar unread-bib-file "~/to-be-read.bib"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 "Default name of file used by `unread-bib' in Bib mode.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (defvar bib-mode-map (copy-keymap text-mode-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 (define-key bib-mode-map "\C-M" 'return-key-bib)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (define-key bib-mode-map "\C-c\C-u" 'unread-bib)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (define-key bib-mode-map "\C-c\C-@" 'mark-bib)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (define-key bib-mode-map "\e`" 'abbrev-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (defvar bib-mode-abbrev-table nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 "Abbrev table used in Bib mode")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (defun addbib ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 "Set up editor to add to troff bibliography file specified
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 by global variable `bib-file'. See description of `bib-mode'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (find-file bib-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (bib-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (defun bib-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 "Mode for editing `lookbib' style bibliographies.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 Hit RETURN to get next % field key.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 If you want to ignore this field, just hit RETURN again.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 Use `text-mode' to turn this feature off.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 journal papers: A* T D J V N P K W X
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 articles in books & proceedings: A* T D B E* I C P K W X
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 tech reports: A* T D R I C K W X
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 books: A* T D I C K W X
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 Fields:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 A uthor T itle D ate J ournal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 V olume N umber P age K eywords
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 B in book or proceedings E ditor C ity & state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 I nstitution, school, or publisher
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 R eport number or 'phd thesis' or 'masters thesis' or 'draft' or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 'unnumbered' or 'unpublished'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 W here can be found locally (login name, or ailib, etc.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 X comments (not used in indexing)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 \\[unread-bib] appends current entry to a different file (for example,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 a file of papers to be read in the future), given by the value of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 variable `unread-bib-file'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 \\[mark-bib] marks current or previous entry.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 Abbreviations are saved in `bib-mode-abbrev-table'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 Hook can be stored in `bib-mode-hook'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 Field keys given by variable `bib-assoc'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 Commands:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 \\{bib-mode-map}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (text-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (use-local-map bib-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (setq mode-name "Bib")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (setq major-mode 'bib-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (define-abbrev-table 'bib-mode-abbrev-table ())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (setq local-abbrev-table bib-mode-abbrev-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (abbrev-mode 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (run-hooks 'bib-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (defconst bib-assoc '(
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (" *$" . "%A ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 ("%A ." . "%A ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 ("%A $" . "%T ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 ("%T " . "%D ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 ("%D " . "%J ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 ("%J ." . "%V ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 ("%V " . "%N ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 ("%N " . "%P ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 ("%P " . "%K ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 ("%K " . "%W ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 ("%W " . "%X ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 ("%X " . "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 ("%J $" . "%B ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 ("%B ." . "%E ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 ("%E ." . "%E ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 ("%E $" . "%I ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 ("%I " . "%C ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 ("%C " . "%P ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 ("%B $" . "%R ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 ("%R " . "%I ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 "Describes bibliographic database format. A line beginning with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 the car of an entry is followed by one beginning with the cdr.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (defun bib-find-key (slots)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 ((null slots)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (if (bobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (progn (previous-line 1) (bib-find-key bib-assoc))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 ((looking-at (car (car slots)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (cdr (car slots)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (t (bib-find-key (cdr slots)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (defvar bib-auto-capitalize t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 "*True to automatically capitalize appropriate fields in Bib mode.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (defconst bib-capitalized-fields "%[AETCBIJR]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (defun return-key-bib ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 "Magic when user hits return, used by `bib-mode'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (if (eolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (let (empty new-key beg-current end-current)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (setq empty (looking-at "%. $"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (if (not empty)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (forward-line -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (setq end-current (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (setq beg-current (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (setq new-key (bib-find-key bib-assoc))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (if (and (not empty) bib-auto-capitalize
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (looking-at bib-capitalized-fields))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (capitalize-title-region (+ (point) 3) end-current)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (goto-char beg-current)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (if empty
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (kill-line nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (insert-string new-key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (newline)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (defun mark-bib ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 "Set mark at beginning of current or previous bib entry, point at end."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (beginning-of-line nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (if (looking-at "^ *$") (re-search-backward "[^ \n]" nil 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (re-search-backward "^ *$" nil 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (re-search-forward "^%")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (beginning-of-line nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (push-mark (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (re-search-forward "^ *$" nil 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (next-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (beginning-of-line nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (defun unread-bib ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 "Append current or previous entry to file of unread papers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 named by variable `unread-bib-file'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (mark-bib)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (if (get-file-buffer unread-bib-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (append-to-buffer (get-file-buffer unread-bib-file) (mark) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (append-to-file (mark) (point) unread-bib-file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (defvar capitalize-title-stop-words
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 "the\\|and\\|of\\|is\\|a\\|an\\|of\\|for\\|in\\|to\\|in\\|on\\|at\\|"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 "by\\|with\\|that\\|its")
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
204 "Words not to be capitalized in a title (unless they're the first word
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 in the title).")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (defvar capitalize-title-stop-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (concat "\\(" capitalize-title-stop-words "\\)\\(\\b\\|'\\)"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (defun capitalize-title-region (begin end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 "Like `capitalize-region', but don't capitalize stop words, except the first."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (interactive "r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (let ((case-fold-search nil) (orig-syntax-table (syntax-table)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (set-syntax-table text-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (narrow-to-region begin end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (if (looking-at "[A-Z][a-z]*[A-Z]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (forward-word 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (capitalize-word 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (while (re-search-forward "\\<" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (if (looking-at "[A-Z][a-z]*[A-Z]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (forward-word 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (if (let ((case-fold-search t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (looking-at capitalize-title-stop-regexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (downcase-word 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (capitalize-word 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (set-syntax-table orig-syntax-table))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (defun capitalize-title (s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 "Like `capitalize', but don't capitalize stop words, except the first."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (set-buffer (get-buffer-create "$$$Scratch$$$"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (insert s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (capitalize-title-region (point-min) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (buffer-string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (provide 'bib-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 ;;; bib-mode.el ends here