annotate lisp/textmodes/bib-mode.el @ 386:6acd2a203aa8

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