1 ;;; bib-mode.el --- 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 the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, 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.
35 "Major mode for editing bib files."
39 (defcustom bib-file
"~/my-bibliography.bib"
40 "Default name of file used by `addbib'."
44 (defcustom unread-bib-file
"~/to-be-read.bib"
45 "Default name of file used by `unread-bib' in Bib mode."
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
)
56 "Set up editor to add to troff bibliography file specified
57 by global variable `bib-file'. See description of `bib-mode'."
60 (goto-char (point-max))
64 (define-derived-mode bib-mode text-mode
"Bib"
65 "Mode for editing `lookbib' style bibliographies.
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.
70 journal papers: A* T D J V N P K W X
71 articles in books & proceedings: A* T D B E* I C P K W X
72 tech reports: A* T D R I C K W X
73 books: A* T D I C K W X
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
81 R eport number or 'phd thesis' or 'masters thesis' or 'draft' or
82 'unnumbered' or 'unpublished'
83 W here can be found locally (login name, or ailib, etc.)
84 X comments (not used in indexing)
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'.
119 "Describes bibliographic database format.
120 A line beginning with the car of an entry is followed by one beginning
123 (defun bib-find-key (slots)
128 (progn (previous-line 1) (bib-find-key bib-assoc
))))
129 ((looking-at (car (car slots
)))
131 (t (bib-find-key (cdr slots
)))
135 (defcustom bib-auto-capitalize t
136 "*True to automatically capitalize appropriate fields in Bib mode."
140 (defconst bib-capitalized-fields
"%[AETCBIJR]")
142 (defun return-key-bib ()
143 "Magic when user hits return, used by `bib-mode'."
146 (let (empty new-key beg-current end-current
)
148 (setq empty
(looking-at "%. $"))
156 (setq end-current
(point))
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
))
163 (bib-capitalize-title-region (+ (point) 3) end-current
)))
164 (goto-char beg-current
)
173 "Set mark at beginning of current or previous bib entry, point at end."
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
)
181 (re-search-forward "^ *$" nil
2)
183 (beginning-of-line nil
))
186 "Append current or previous entry to file of unread papers
187 named by variable `unread-bib-file'."
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
)))
195 (defvar bib-capitalize-title-stop-words
197 "the\\|and\\|of\\|is\\|a\\|an\\|of\\|for\\|in\\|to\\|in\\|on\\|at\\|"
198 "by\\|with\\|that\\|its")
199 "Words not to be capitalized in a title (unless the first word).")
201 (defvar bib-capitalize-title-stop-regexp
202 (concat "\\(" bib-capitalize-title-stop-words
"\\)\\(\\b\\|'\\)"))
204 (defun bib-capitalize-title-region (begin end
)
205 "Like `capitalize-region', but don't capitalize stop words, except the first."
207 (let ((case-fold-search nil
) (orig-syntax-table (syntax-table)))
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]")
216 (while (re-search-forward "\\<" nil t
)
217 (if (looking-at "[A-Z][a-z]*[A-Z]")
219 (if (let ((case-fold-search t
))
220 (looking-at bib-capitalize-title-stop-regexp
))
222 (capitalize-word 1)))
224 (set-syntax-table orig-syntax-table
))))
227 (defun bib-capitalize-title (s)
228 "Like `capitalize', but don't capitalize stop words, except the first."
230 (set-buffer (get-buffer-create "$$$Scratch$$$"))
233 (bib-capitalize-title-region (point-min) (point-max))
238 ;;; bib-mode.el ends here