annotate lisp/modes/bib-mode.el @ 0:376386a54a3c r19-14

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