1 ;;; bib-mode.el --- bib-mode, major mode for editing bib files.
3 ;; Copyright (C) 1989 Free Software Foundation, Inc.
8 ;; This file is part of GNU Emacs.
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
12 ;; the Free Software Foundation; either version 2, or (at your option)
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.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
27 ;; GNU Emacs code to help maintain databases compatible with (troff)
28 ;; refer and lookbib. The file bib-file should be set to your
29 ;; bibliography file. Keys are automagically inserted as you type,
30 ;; and appropriate keys are presented for various kinds of entries.
32 (defvar bib-file
"~/my-bibliography.bib"
33 "Default name of file used by `addbib'.")
35 (defvar unread-bib-file
"~/to-be-read.bib"
36 "Default name of file used by `unread-bib' in Bib mode.")
38 (defvar bib-mode-map
(copy-keymap text-mode-map
))
39 (define-key bib-mode-map
"\C-M" 'return-key-bib
)
40 (define-key bib-mode-map
"\C-c\C-u" 'unread-bib
)
41 (define-key bib-mode-map
"\C-c\C-@" 'mark-bib
)
42 (define-key bib-mode-map
"\e`" 'abbrev-mode
)
43 (defvar bib-mode-abbrev-table nil
44 "Abbrev table used in Bib mode")
47 "Set up editor to add to troff bibliography file specified
48 by global variable `bib-file'. See description of `bib-mode'."
51 (goto-char (point-max))
56 "Mode for editing `lookbib' style bibliographies.
57 Hit RETURN to get next % field key.
58 If you want to ignore this field, just hit RETURN again.
59 Use `text-mode' to turn this feature off.
61 journal papers: A* T D J V N P K W X
62 articles in books & proceedings: A* T D B E* I C P K W X
63 tech reports: A* T D R I C K W X
64 books: A* T D I C K W X
68 A uthor T itle D ate J ournal
69 V olume N umber P age K eywords
70 B in book or proceedings E ditor C ity & state
71 I nstitution, school, or publisher
72 R eport number or 'phd thesis' or 'masters thesis' or 'draft' or
73 'unnumbered' or 'unpublished'
74 W here can be found locally (login name, or ailib, etc.)
75 X comments (not used in indexing)
77 \\[unread-bib] appends current entry to a different file (for example,
78 a file of papers to be read in the future), given by the value of the
79 variable `unread-bib-file'.
80 \\[mark-bib] marks current or previous entry.
81 Abbreviations are saved in `bib-mode-abbrev-table'.
82 Hook can be stored in `bib-mode-hook'.
83 Field keys given by variable `bib-assoc'.
90 (use-local-map bib-mode-map
)
91 (setq mode-name
"Bib")
92 (setq major-mode
'bib-mode
)
93 (define-abbrev-table 'bib-mode-abbrev-table
())
94 (setq local-abbrev-table bib-mode-abbrev-table
)
96 (run-hooks 'bib-mode-hook
)
99 (defconst bib-assoc
'(
122 "Describes bibliographic database format. A line beginning with
123 the car of an entry is followed by one beginning with the cdr.
126 (defun bib-find-key (slots)
131 (progn (previous-line 1) (bib-find-key bib-assoc
))))
132 ((looking-at (car (car slots
)))
134 (t (bib-find-key (cdr slots
)))
138 (defvar bib-auto-capitalize t
139 "*True to automatically capitalize appropriate fields in Bib mode.")
141 (defconst bib-capitalized-fields
"%[AETCBIJR]")
143 (defun return-key-bib ()
144 "Magic when user hits return, used by `bib-mode'."
147 (let (empty new-key beg-current end-current
)
149 (setq empty
(looking-at "%. $"))
157 (setq end-current
(point))
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
))
164 (capitalize-title-region (+ (point) 3) end-current
)))
165 (goto-char beg-current
)
170 (insert-string new-key
))
174 "Set mark at beginning of current or previous bib entry, point at end."
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
)
182 (re-search-forward "^ *$" nil
2)
184 (beginning-of-line nil
))
187 "Append current or previous entry to file of unread papers
188 named by variable `unread-bib-file'."
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
)))
196 (defvar capitalize-title-stop-words
198 "the\\|and\\|of\\|is\\|a\\|an\\|of\\|for\\|in\\|to\\|in\\|on\\|at\\|"
199 "by\\|with\\|that\\|its")
200 "Words not to be capitialized in a title (unless they're the first word
203 (defvar capitalize-title-stop-regexp
204 (concat "\\(" capitalize-title-stop-words
"\\)\\(\\b\\|'\\)"))
206 (defun capitalize-title-region (begin end
)
207 "Like `capitalize-region', but don't capitalize stop words, except the first."
209 (let ((case-fold-search nil
) (orig-syntax-table (syntax-table)))
212 (set-syntax-table text-mode-syntax-table
)
213 (narrow-to-region begin end
)
214 (goto-char (point-min))
215 (if (looking-at "[A-Z][a-z]*[A-Z]")
218 (while (re-search-forward "\\<" nil t
)
219 (if (looking-at "[A-Z][a-z]*[A-Z]")
221 (if (let ((case-fold-search t
))
222 (looking-at capitalize-title-stop-regexp
))
224 (capitalize-word 1)))
226 (set-syntax-table orig-syntax-table
))))
229 (defun capitalize-title (s)
230 "Like `capitalize', but don't capitalize stop words, except the first."
232 (set-buffer (get-buffer-create "$$$Scratch$$$"))
235 (capitalize-title-region (point-min) (point-max))
240 ;;; bib-mode.el ends here