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 XEmacs.
10 ;; XEmacs is free software; you can redistribute it and/or modify it
11 ;; 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 ;; XEmacs is distributed in the hope that it will be useful, but
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ;; General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 ;;; Synched up with: FSF 19.34.
29 ;; GNU Emacs code to help maintain databases compatible with (troff)
30 ;; refer and lookbib. The file bib-file should be set to your
31 ;; bibliography file. Keys are automagically inserted as you type,
32 ;; and appropriate keys are presented for various kinds of entries.
36 (defvar bib-file "~/my-bibliography.bib"
37 "Default name of file used by `addbib'.")
39 (defvar unread-bib-file "~/to-be-read.bib"
40 "Default name of file used by `unread-bib' in Bib mode.")
42 (defvar bib-mode-map (copy-keymap text-mode-map))
43 (define-key bib-mode-map "\C-M" 'return-key-bib)
44 (define-key bib-mode-map "\C-c\C-u" 'unread-bib)
45 (define-key bib-mode-map "\C-c\C-@" 'mark-bib)
46 (define-key bib-mode-map "\e`" 'abbrev-mode)
47 (defvar bib-mode-abbrev-table nil
48 "Abbrev table used in Bib mode")
51 "Set up editor to add to troff bibliography file specified
52 by global variable `bib-file'. See description of `bib-mode'."
55 (goto-char (point-max))
61 "Mode for editing `lookbib' style bibliographies.
62 Hit RETURN to get next % field key.
63 If you want to ignore this field, just hit RETURN again.
64 Use `text-mode' to turn this feature off.
66 journal papers: A* T D J V N P K W X
67 articles in books & proceedings: A* T D B E* I C P K W X
68 tech reports: A* T D R I C K W X
69 books: A* T D I C K W X
73 A uthor T itle D ate J ournal
74 V olume N umber P age K eywords
75 B in book or proceedings E ditor C ity & state
76 I nstitution, school, or publisher
77 R eport number or 'phd thesis' or 'masters thesis' or 'draft' or
78 'unnumbered' or 'unpublished'
79 W here can be found locally (login name, or ailib, etc.)
80 X comments (not used in indexing)
82 \\[unread-bib] appends current entry to a different file (for example,
83 a file of papers to be read in the future), given by the value of the
84 variable `unread-bib-file'.
85 \\[mark-bib] marks current or previous entry.
86 Abbreviations are saved in `bib-mode-abbrev-table'.
87 Hook can be stored in `bib-mode-hook'.
88 Field keys given by variable `bib-assoc'.
95 (use-local-map bib-mode-map)
96 (setq mode-name "Bib")
97 (setq major-mode 'bib-mode)
98 (define-abbrev-table 'bib-mode-abbrev-table ())
99 (setq local-abbrev-table bib-mode-abbrev-table)
101 (run-hooks 'bib-mode-hook)
104 (defconst bib-assoc '(
127 "Describes bibliographic database format. A line beginning with
128 the car of an entry is followed by one beginning with the cdr.
131 (defun bib-find-key (slots)
136 (progn (previous-line 1) (bib-find-key bib-assoc))))
137 ((looking-at (car (car slots)))
139 (t (bib-find-key (cdr slots)))
143 (defvar bib-auto-capitalize t
144 "*True to automatically capitalize appropriate fields in Bib mode.")
146 (defconst bib-capitalized-fields "%[AETCBIJR]")
148 (defun return-key-bib ()
149 "Magic when user hits return, used by `bib-mode'."
152 (let (empty new-key beg-current end-current)
154 (setq empty (looking-at "%. $"))
162 (setq end-current (point))
164 (setq beg-current (point))
165 (setq new-key (bib-find-key bib-assoc))
166 (if (and (not empty) bib-auto-capitalize
167 (looking-at bib-capitalized-fields))
169 (capitalize-title-region (+ (point) 3) end-current)))
170 (goto-char beg-current)
175 (insert-string new-key))
179 "Set mark at beginning of current or previous bib entry, point at end."
181 (beginning-of-line nil)
182 (if (looking-at "^ *$") (re-search-backward "[^ \n]" nil 2))
183 (re-search-backward "^ *$" nil 2)
184 (re-search-forward "^%")
185 (beginning-of-line nil)
187 (re-search-forward "^ *$" nil 2)
189 (beginning-of-line nil))
192 "Append current or previous entry to file of unread papers
193 named by variable `unread-bib-file'."
196 (if (get-file-buffer unread-bib-file)
197 (append-to-buffer (get-file-buffer unread-bib-file) (mark) (point))
198 (append-to-file (mark) (point) unread-bib-file)))
201 (defvar capitalize-title-stop-words
203 "the\\|and\\|of\\|is\\|a\\|an\\|of\\|for\\|in\\|to\\|in\\|on\\|at\\|"
204 "by\\|with\\|that\\|its")
205 "Words not to be capitalized in a title (unless they're the first word
208 (defvar capitalize-title-stop-regexp
209 (concat "\\(" capitalize-title-stop-words "\\)\\(\\b\\|'\\)"))
211 (defun capitalize-title-region (begin end)
212 "Like `capitalize-region', but don't capitalize stop words, except the first."
214 (let ((case-fold-search nil) (orig-syntax-table (syntax-table)))
217 (set-syntax-table text-mode-syntax-table)
218 (narrow-to-region begin end)
219 (goto-char (point-min))
220 (if (looking-at "[A-Z][a-z]*[A-Z]")
223 (while (re-search-forward "\\<" nil t)
224 (if (looking-at "[A-Z][a-z]*[A-Z]")
226 (if (let ((case-fold-search t))
227 (looking-at capitalize-title-stop-regexp))
229 (capitalize-word 1)))
231 (set-syntax-table orig-syntax-table))))
234 (defun capitalize-title (s)
235 "Like `capitalize', but don't capitalize stop words, except the first."
237 (set-buffer (get-buffer-create "$$$Scratch$$$"))
240 (capitalize-title-region (point-min) (point-max))
245 ;;; bib-mode.el ends here