annotate lisp/textmodes/bib-mode.el @ 17353:71db8e3ee12f

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