Mercurial > emacs
annotate lisp/textmodes/bib-mode.el @ 95872:7d6cf08604f7
*** empty log message ***
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Fri, 13 Jun 2008 04:17:08 +0000 |
parents | f4a69fedbd46 |
children | a9dc0e7c3f2b |
rev | line source |
---|---|
38412
253f761ad37b
Some fixes to follow coding conventions in files maintained by FSF.
Pavel Janík <Pavel@Janik.cz>
parents:
20959
diff
changeset
|
1 ;;; bib-mode.el --- major mode for editing bib files |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
2 |
74509 | 3 ;; Copyright (C) 1989, 2001, 2002, 2003, 2004, 2005, |
79719 | 4 ;; 2006, 2007, 2008 Free Software Foundation, Inc. |
845 | 5 |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
6 ;; Maintainer: FSF |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
7 ;; Keywords: bib |
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
8 |
187 | 9 ;; This file is part of GNU Emacs. |
10 | |
94670
f4a69fedbd46
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
11 ;; GNU Emacs is free software: you can redistribute it and/or modify |
187 | 12 ;; it under the terms of the GNU General Public License as published by |
94670
f4a69fedbd46
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
13 ;; the Free Software Foundation, either version 3 of the License, or |
f4a69fedbd46
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
14 ;; (at your option) any later version. |
187 | 15 |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
94670
f4a69fedbd46
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
187 | 23 |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
845
diff
changeset
|
24 ;;; Commentary: |
187 | 25 |
26 ;; GNU Emacs code to help maintain databases compatible with (troff) | |
49599
5ade352e8d1c
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
41564
diff
changeset
|
27 ;; refer and lookbib. The file bib-file should be set to your |
187 | 28 ;; bibliography file. Keys are automagically inserted as you type, |
29 ;; and appropriate keys are presented for various kinds of entries. | |
30 | |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
845
diff
changeset
|
31 ;;; Code: |
38412
253f761ad37b
Some fixes to follow coding conventions in files maintained by FSF.
Pavel Janík <Pavel@Janik.cz>
parents:
20959
diff
changeset
|
32 |
20959 | 33 (defgroup bib nil |
34 "Major mode for editing bib files." | |
35 :prefix "bib-" | |
52282 | 36 :group 'external |
20959 | 37 :group 'wp) |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
845
diff
changeset
|
38 |
20959 | 39 (defcustom bib-file "~/my-bibliography.bib" |
40 "Default name of file used by `addbib'." | |
41 :type 'file | |
42 :group 'bib) | |
187 | 43 |
20959 | 44 (defcustom unread-bib-file "~/to-be-read.bib" |
45 "Default name of file used by `unread-bib' in Bib mode." | |
46 :type 'file | |
47 :group 'bib) | |
187 | 48 |
49 (defvar bib-mode-map (copy-keymap text-mode-map)) | |
50 (define-key bib-mode-map "\C-M" 'return-key-bib) | |
51 (define-key bib-mode-map "\C-c\C-u" 'unread-bib) | |
52 (define-key bib-mode-map "\C-c\C-@" 'mark-bib) | |
53 (define-key bib-mode-map "\e`" 'abbrev-mode) | |
54 | |
55 (defun addbib () | |
49599
5ade352e8d1c
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
41564
diff
changeset
|
56 "Set up editor to add to troff bibliography file specified |
187 | 57 by global variable `bib-file'. See description of `bib-mode'." |
58 (interactive) | |
59 (find-file bib-file) | |
60 (goto-char (point-max)) | |
61 (bib-mode) | |
62 ) | |
49599
5ade352e8d1c
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
41564
diff
changeset
|
63 |
39896
258ac90a4fed
Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
64 (define-derived-mode bib-mode text-mode "Bib" |
49599
5ade352e8d1c
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
41564
diff
changeset
|
65 "Mode for editing `lookbib' style bibliographies. |
187 | 66 Hit RETURN to get next % field key. |
67 If you want to ignore this field, just hit RETURN again. | |
68 Use `text-mode' to turn this feature off. | |
69 | |
70 journal papers: A* T D J V N P K W X | |
49599
5ade352e8d1c
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
41564
diff
changeset
|
71 articles in books & proceedings: A* T D B E* I C P K W X |
187 | 72 tech reports: A* T D R I C K W X |
73 books: A* T D I C K W X | |
74 | |
75 Fields: | |
76 | |
77 A uthor T itle D ate J ournal | |
78 V olume N umber P age K eywords | |
79 B in book or proceedings E ditor C ity & state | |
80 I nstitution, school, or publisher | |
49599
5ade352e8d1c
Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
41564
diff
changeset
|
81 R eport number or 'phd thesis' or 'masters thesis' or 'draft' or |
187 | 82 'unnumbered' or 'unpublished' |
83 W here can be found locally (login name, or ailib, etc.) | |
84 X comments (not used in indexing) | |
85 | |
86 \\[unread-bib] appends current entry to a different file (for example, | |
87 a file of papers to be read in the future), given by the value of the | |
88 variable `unread-bib-file'. | |
89 \\[mark-bib] marks current or previous entry. | |
90 Abbreviations are saved in `bib-mode-abbrev-table'. | |
91 Hook can be stored in `bib-mode-hook'. | |
92 Field keys given by variable `bib-assoc'. | |
93 | |
94 Commands: | |
39896
258ac90a4fed
Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
95 \\{bib-mode-map}" |
258ac90a4fed
Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
96 (abbrev-mode 1)) |
187 | 97 |
39896
258ac90a4fed
Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
98 (defconst bib-assoc |
258ac90a4fed
Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
99 '((" *$" . "%A ") |
258ac90a4fed
Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
100 ("%A ." . "%A ") |
258ac90a4fed
Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
101 ("%A $" . "%T ") |
258ac90a4fed
Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
102 ("%T " . "%D ") |
258ac90a4fed
Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
103 ("%D " . "%J ") |
258ac90a4fed
Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
104 ("%J ." . "%V ") |
258ac90a4fed
Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
105 ("%V " . "%N ") |
258ac90a4fed
Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
106 ("%N " . "%P ") |
258ac90a4fed
Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
107 ("%P " . "%K ") |
258ac90a4fed
Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
108 ("%K " . "%W ") |
258ac90a4fed
Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
109 ("%W " . "%X ") |
258ac90a4fed
Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
110 ("%X " . "") |
258ac90a4fed
Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
111 ("%J $" . "%B ") |
258ac90a4fed
Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
112 ("%B ." . "%E ") |
258ac90a4fed
Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
113 ("%E ." . "%E ") |
258ac90a4fed
Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
114 ("%E $" . "%I ") |
258ac90a4fed
Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
115 ("%I " . "%C ") |
258ac90a4fed
Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
116 ("%C " . "%P ") |
258ac90a4fed
Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
117 ("%B $" . "%R ") |
258ac90a4fed
Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
118 ("%R " . "%I ")) |
258ac90a4fed
Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
119 "Describes bibliographic database format. |
258ac90a4fed
Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
120 A line beginning with the car of an entry is followed by one beginning |
258ac90a4fed
Use define-derived-mode.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38412
diff
changeset
|
121 with the cdr.") |
187 | 122 |
123 (defun bib-find-key (slots) | |
124 (cond | |
125 ((null slots) | |
126 (if (bobp) | |
127 "" | |
85451
e1af3a725ca4
* textmodes/two-column.el (2C-split, 2C-merge):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78225
diff
changeset
|
128 (progn (forward-line -1) (bib-find-key bib-assoc)))) |
187 | 129 ((looking-at (car (car slots))) |
130 (cdr (car slots))) | |
131 (t (bib-find-key (cdr slots))) | |
132 )) | |
133 | |
134 | |
20959 | 135 (defcustom bib-auto-capitalize t |
136 "*True to automatically capitalize appropriate fields in Bib mode." | |
137 :type 'boolean | |
138 :group 'bib) | |
187 | 139 |
140 (defconst bib-capitalized-fields "%[AETCBIJR]") | |
141 | |
142 (defun return-key-bib () | |
143 "Magic when user hits return, used by `bib-mode'." | |
144 (interactive) | |
145 (if (eolp) | |
146 (let (empty new-key beg-current end-current) | |
147 (beginning-of-line) | |
148 (setq empty (looking-at "%. $")) | |
149 (if (not empty) | |
150 (progn | |
151 (end-of-line) | |
152 (newline) | |
153 (forward-line -1) | |
154 )) | |
155 (end-of-line) | |
156 (setq end-current (point)) | |
157 (beginning-of-line) | |
158 (setq beg-current (point)) | |
159 (setq new-key (bib-find-key bib-assoc)) | |
160 (if (and (not empty) bib-auto-capitalize | |
161 (looking-at bib-capitalized-fields)) | |
162 (save-excursion | |
16285
0aa65f31f7e4
(bib-capitalize-title-stop-words): Renamed from capit...
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
163 (bib-capitalize-title-region (+ (point) 3) end-current))) |
187 | 164 (goto-char beg-current) |
165 (if empty | |
166 (kill-line nil) | |
167 (forward-line 1) | |
168 ) | |
41564
8fab3d5b7fcf
(return-key-bib): Use insert instead of insert-string.
Pavel Janík <Pavel@Janik.cz>
parents:
39896
diff
changeset
|
169 (insert new-key)) |
187 | 170 (newline))) |
171 | |
172 (defun mark-bib () | |
173 "Set mark at beginning of current or previous bib entry, point at end." | |
174 (interactive) | |
175 (beginning-of-line nil) | |
176 (if (looking-at "^ *$") (re-search-backward "[^ \n]" nil 2)) | |
177 (re-search-backward "^ *$" nil 2) | |
178 (re-search-forward "^%") | |
179 (beginning-of-line nil) | |
180 (push-mark (point)) | |
181 (re-search-forward "^ *$" nil 2) | |
85451
e1af3a725ca4
* textmodes/two-column.el (2C-split, 2C-merge):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78225
diff
changeset
|
182 (forward-line 1) |
187 | 183 (beginning-of-line nil)) |
184 | |
185 (defun unread-bib () | |
186 "Append current or previous entry to file of unread papers | |
187 named by variable `unread-bib-file'." | |
188 (interactive) | |
189 (mark-bib) | |
190 (if (get-file-buffer unread-bib-file) | |
191 (append-to-buffer (get-file-buffer unread-bib-file) (mark) (point)) | |
192 (append-to-file (mark) (point) unread-bib-file))) | |
193 | |
194 | |
16285
0aa65f31f7e4
(bib-capitalize-title-stop-words): Renamed from capit...
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
195 (defvar bib-capitalize-title-stop-words |
187 | 196 (concat |
197 "the\\|and\\|of\\|is\\|a\\|an\\|of\\|for\\|in\\|to\\|in\\|on\\|at\\|" | |
198 "by\\|with\\|that\\|its") | |
16285
0aa65f31f7e4
(bib-capitalize-title-stop-words): Renamed from capit...
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
199 "Words not to be capitalized in a title (unless the first word).") |
187 | 200 |
16285
0aa65f31f7e4
(bib-capitalize-title-stop-words): Renamed from capit...
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
201 (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
|
202 (concat "\\(" bib-capitalize-title-stop-words "\\)\\(\\b\\|'\\)")) |
187 | 203 |
16285
0aa65f31f7e4
(bib-capitalize-title-stop-words): Renamed from capit...
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
204 (defun bib-capitalize-title-region (begin end) |
187 | 205 "Like `capitalize-region', but don't capitalize stop words, except the first." |
206 (interactive "r") | |
207 (let ((case-fold-search nil) (orig-syntax-table (syntax-table))) | |
208 (unwind-protect | |
209 (save-restriction | |
210 (set-syntax-table text-mode-syntax-table) | |
211 (narrow-to-region begin end) | |
212 (goto-char (point-min)) | |
213 (if (looking-at "[A-Z][a-z]*[A-Z]") | |
214 (forward-word 1) | |
215 (capitalize-word 1)) | |
216 (while (re-search-forward "\\<" nil t) | |
217 (if (looking-at "[A-Z][a-z]*[A-Z]") | |
218 (forward-word 1) | |
219 (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
|
220 (looking-at bib-capitalize-title-stop-regexp)) |
187 | 221 (downcase-word 1) |
222 (capitalize-word 1))) | |
223 )) | |
224 (set-syntax-table orig-syntax-table)))) | |
225 | |
226 | |
16285
0aa65f31f7e4
(bib-capitalize-title-stop-words): Renamed from capit...
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
227 (defun bib-capitalize-title (s) |
187 | 228 "Like `capitalize', but don't capitalize stop words, except the first." |
229 (save-excursion | |
230 (set-buffer (get-buffer-create "$$$Scratch$$$")) | |
231 (erase-buffer) | |
232 (insert s) | |
16285
0aa65f31f7e4
(bib-capitalize-title-stop-words): Renamed from capit...
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
233 (bib-capitalize-title-region (point-min) (point-max)) |
187 | 234 (buffer-string))) |
584 | 235 |
236 (provide 'bib-mode) | |
237 | |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
238 ;; arch-tag: e3a97958-3c2c-487f-9557-fafc3c98452d |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
584
diff
changeset
|
239 ;;; bib-mode.el ends here |