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