2001-07-15 16:15:35 +00:00
|
|
|
;;; bib-mode.el --- major mode for editing bib files
|
1992-05-30 23:54:21 +00:00
|
|
|
|
2009-01-10 23:17:44 +00:00
|
|
|
;; Copyright (C) 1989, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
|
2010-01-13 00:35:10 -08:00
|
|
|
;; 2009, 2010 Free Software Foundation, Inc.
|
1992-07-22 04:22:30 +00:00
|
|
|
|
2009-01-10 23:17:44 +00:00
|
|
|
;; Author: Henry Kautz
|
|
|
|
;; (according to authors.el)
|
1992-07-16 21:47:34 +00:00
|
|
|
;; Maintainer: FSF
|
|
|
|
;; Keywords: bib
|
|
|
|
|
1991-02-04 22:07:47 +00:00
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
2008-05-06 04:34:22 +00:00
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
1991-02-04 22:07:47 +00:00
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2008-05-06 04:34:22 +00:00
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
1991-02-04 22:07:47 +00:00
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2008-05-06 04:34:22 +00:00
|
|
|
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
1991-02-04 22:07:47 +00:00
|
|
|
|
1993-03-22 03:27:18 +00:00
|
|
|
;;; Commentary:
|
1991-02-04 22:07:47 +00:00
|
|
|
|
|
|
|
;; GNU Emacs code to help maintain databases compatible with (troff)
|
2003-02-04 13:30:45 +00:00
|
|
|
;; refer and lookbib. The file bib-file should be set to your
|
1991-02-04 22:07:47 +00:00
|
|
|
;; bibliography file. Keys are automagically inserted as you type,
|
|
|
|
;; and appropriate keys are presented for various kinds of entries.
|
|
|
|
|
1993-03-22 03:27:18 +00:00
|
|
|
;;; Code:
|
2001-07-15 16:15:35 +00:00
|
|
|
|
1998-02-22 17:34:42 +00:00
|
|
|
(defgroup bib nil
|
|
|
|
"Major mode for editing bib files."
|
|
|
|
:prefix "bib-"
|
2003-08-20 18:32:51 +00:00
|
|
|
:group 'external
|
1998-02-22 17:34:42 +00:00
|
|
|
:group 'wp)
|
1993-03-22 03:27:18 +00:00
|
|
|
|
1998-02-22 17:34:42 +00:00
|
|
|
(defcustom bib-file "~/my-bibliography.bib"
|
|
|
|
"Default name of file used by `addbib'."
|
|
|
|
:type 'file
|
|
|
|
:group 'bib)
|
1991-02-04 22:07:47 +00:00
|
|
|
|
1998-02-22 17:34:42 +00:00
|
|
|
(defcustom unread-bib-file "~/to-be-read.bib"
|
|
|
|
"Default name of file used by `unread-bib' in Bib mode."
|
|
|
|
:type 'file
|
|
|
|
:group 'bib)
|
1991-02-04 22:07:47 +00:00
|
|
|
|
|
|
|
(defvar bib-mode-map (copy-keymap text-mode-map))
|
|
|
|
(define-key bib-mode-map "\C-M" 'return-key-bib)
|
|
|
|
(define-key bib-mode-map "\C-c\C-u" 'unread-bib)
|
|
|
|
(define-key bib-mode-map "\C-c\C-@" 'mark-bib)
|
|
|
|
(define-key bib-mode-map "\e`" 'abbrev-mode)
|
|
|
|
|
|
|
|
(defun addbib ()
|
2003-02-04 13:30:45 +00:00
|
|
|
"Set up editor to add to troff bibliography file specified
|
1991-02-04 22:07:47 +00:00
|
|
|
by global variable `bib-file'. See description of `bib-mode'."
|
|
|
|
(interactive)
|
|
|
|
(find-file bib-file)
|
|
|
|
(goto-char (point-max))
|
|
|
|
(bib-mode)
|
|
|
|
)
|
2003-02-04 13:30:45 +00:00
|
|
|
|
2001-10-13 19:22:43 +00:00
|
|
|
(define-derived-mode bib-mode text-mode "Bib"
|
2003-02-04 13:30:45 +00:00
|
|
|
"Mode for editing `lookbib' style bibliographies.
|
1991-02-04 22:07:47 +00:00
|
|
|
Hit RETURN to get next % field key.
|
|
|
|
If you want to ignore this field, just hit RETURN again.
|
|
|
|
Use `text-mode' to turn this feature off.
|
|
|
|
|
|
|
|
journal papers: A* T D J V N P K W X
|
2003-02-04 13:30:45 +00:00
|
|
|
articles in books & proceedings: A* T D B E* I C P K W X
|
1991-02-04 22:07:47 +00:00
|
|
|
tech reports: A* T D R I C K W X
|
|
|
|
books: A* T D I C K W X
|
|
|
|
|
|
|
|
Fields:
|
|
|
|
|
|
|
|
A uthor T itle D ate J ournal
|
|
|
|
V olume N umber P age K eywords
|
|
|
|
B in book or proceedings E ditor C ity & state
|
|
|
|
I nstitution, school, or publisher
|
2003-02-04 13:30:45 +00:00
|
|
|
R eport number or 'phd thesis' or 'masters thesis' or 'draft' or
|
1991-02-04 22:07:47 +00:00
|
|
|
'unnumbered' or 'unpublished'
|
|
|
|
W here can be found locally (login name, or ailib, etc.)
|
|
|
|
X comments (not used in indexing)
|
|
|
|
|
|
|
|
\\[unread-bib] appends current entry to a different file (for example,
|
|
|
|
a file of papers to be read in the future), given by the value of the
|
|
|
|
variable `unread-bib-file'.
|
|
|
|
\\[mark-bib] marks current or previous entry.
|
|
|
|
Abbreviations are saved in `bib-mode-abbrev-table'.
|
|
|
|
Hook can be stored in `bib-mode-hook'.
|
|
|
|
Field keys given by variable `bib-assoc'.
|
|
|
|
|
|
|
|
Commands:
|
2001-10-13 19:22:43 +00:00
|
|
|
\\{bib-mode-map}"
|
|
|
|
(abbrev-mode 1))
|
|
|
|
|
|
|
|
(defconst bib-assoc
|
|
|
|
'((" *$" . "%A ")
|
|
|
|
("%A ." . "%A ")
|
|
|
|
("%A $" . "%T ")
|
|
|
|
("%T " . "%D ")
|
|
|
|
("%D " . "%J ")
|
|
|
|
("%J ." . "%V ")
|
|
|
|
("%V " . "%N ")
|
|
|
|
("%N " . "%P ")
|
|
|
|
("%P " . "%K ")
|
|
|
|
("%K " . "%W ")
|
|
|
|
("%W " . "%X ")
|
|
|
|
("%X " . "")
|
|
|
|
("%J $" . "%B ")
|
|
|
|
("%B ." . "%E ")
|
|
|
|
("%E ." . "%E ")
|
|
|
|
("%E $" . "%I ")
|
|
|
|
("%I " . "%C ")
|
|
|
|
("%C " . "%P ")
|
|
|
|
("%B $" . "%R ")
|
|
|
|
("%R " . "%I "))
|
|
|
|
"Describes bibliographic database format.
|
|
|
|
A line beginning with the car of an entry is followed by one beginning
|
|
|
|
with the cdr.")
|
1991-02-04 22:07:47 +00:00
|
|
|
|
|
|
|
(defun bib-find-key (slots)
|
|
|
|
(cond
|
|
|
|
((null slots)
|
|
|
|
(if (bobp)
|
|
|
|
""
|
2007-10-19 18:41:09 +00:00
|
|
|
(progn (forward-line -1) (bib-find-key bib-assoc))))
|
1991-02-04 22:07:47 +00:00
|
|
|
((looking-at (car (car slots)))
|
|
|
|
(cdr (car slots)))
|
|
|
|
(t (bib-find-key (cdr slots)))
|
|
|
|
))
|
|
|
|
|
|
|
|
|
1998-02-22 17:34:42 +00:00
|
|
|
(defcustom bib-auto-capitalize t
|
|
|
|
"*True to automatically capitalize appropriate fields in Bib mode."
|
|
|
|
:type 'boolean
|
|
|
|
:group 'bib)
|
1991-02-04 22:07:47 +00:00
|
|
|
|
|
|
|
(defconst bib-capitalized-fields "%[AETCBIJR]")
|
|
|
|
|
|
|
|
(defun return-key-bib ()
|
|
|
|
"Magic when user hits return, used by `bib-mode'."
|
|
|
|
(interactive)
|
|
|
|
(if (eolp)
|
|
|
|
(let (empty new-key beg-current end-current)
|
|
|
|
(beginning-of-line)
|
|
|
|
(setq empty (looking-at "%. $"))
|
|
|
|
(if (not empty)
|
|
|
|
(progn
|
|
|
|
(end-of-line)
|
|
|
|
(newline)
|
|
|
|
(forward-line -1)
|
|
|
|
))
|
|
|
|
(end-of-line)
|
|
|
|
(setq end-current (point))
|
|
|
|
(beginning-of-line)
|
|
|
|
(setq beg-current (point))
|
|
|
|
(setq new-key (bib-find-key bib-assoc))
|
|
|
|
(if (and (not empty) bib-auto-capitalize
|
|
|
|
(looking-at bib-capitalized-fields))
|
|
|
|
(save-excursion
|
1996-09-22 21:48:30 +00:00
|
|
|
(bib-capitalize-title-region (+ (point) 3) end-current)))
|
1991-02-04 22:07:47 +00:00
|
|
|
(goto-char beg-current)
|
|
|
|
(if empty
|
|
|
|
(kill-line nil)
|
|
|
|
(forward-line 1)
|
|
|
|
)
|
2001-11-26 16:18:39 +00:00
|
|
|
(insert new-key))
|
1991-02-04 22:07:47 +00:00
|
|
|
(newline)))
|
|
|
|
|
|
|
|
(defun mark-bib ()
|
|
|
|
"Set mark at beginning of current or previous bib entry, point at end."
|
|
|
|
(interactive)
|
|
|
|
(beginning-of-line nil)
|
|
|
|
(if (looking-at "^ *$") (re-search-backward "[^ \n]" nil 2))
|
|
|
|
(re-search-backward "^ *$" nil 2)
|
|
|
|
(re-search-forward "^%")
|
|
|
|
(beginning-of-line nil)
|
|
|
|
(push-mark (point))
|
|
|
|
(re-search-forward "^ *$" nil 2)
|
2007-10-19 18:41:09 +00:00
|
|
|
(forward-line 1)
|
1991-02-04 22:07:47 +00:00
|
|
|
(beginning-of-line nil))
|
|
|
|
|
|
|
|
(defun unread-bib ()
|
|
|
|
"Append current or previous entry to file of unread papers
|
|
|
|
named by variable `unread-bib-file'."
|
|
|
|
(interactive)
|
|
|
|
(mark-bib)
|
|
|
|
(if (get-file-buffer unread-bib-file)
|
|
|
|
(append-to-buffer (get-file-buffer unread-bib-file) (mark) (point))
|
|
|
|
(append-to-file (mark) (point) unread-bib-file)))
|
|
|
|
|
|
|
|
|
1996-09-22 21:48:30 +00:00
|
|
|
(defvar bib-capitalize-title-stop-words
|
1991-02-04 22:07:47 +00:00
|
|
|
(concat
|
|
|
|
"the\\|and\\|of\\|is\\|a\\|an\\|of\\|for\\|in\\|to\\|in\\|on\\|at\\|"
|
|
|
|
"by\\|with\\|that\\|its")
|
1996-09-22 21:48:30 +00:00
|
|
|
"Words not to be capitalized in a title (unless the first word).")
|
1991-02-04 22:07:47 +00:00
|
|
|
|
1996-09-22 21:48:30 +00:00
|
|
|
(defvar bib-capitalize-title-stop-regexp
|
|
|
|
(concat "\\(" bib-capitalize-title-stop-words "\\)\\(\\b\\|'\\)"))
|
1991-02-04 22:07:47 +00:00
|
|
|
|
1996-09-22 21:48:30 +00:00
|
|
|
(defun bib-capitalize-title-region (begin end)
|
1991-02-04 22:07:47 +00:00
|
|
|
"Like `capitalize-region', but don't capitalize stop words, except the first."
|
|
|
|
(interactive "r")
|
|
|
|
(let ((case-fold-search nil) (orig-syntax-table (syntax-table)))
|
|
|
|
(unwind-protect
|
|
|
|
(save-restriction
|
|
|
|
(set-syntax-table text-mode-syntax-table)
|
|
|
|
(narrow-to-region begin end)
|
|
|
|
(goto-char (point-min))
|
|
|
|
(if (looking-at "[A-Z][a-z]*[A-Z]")
|
|
|
|
(forward-word 1)
|
|
|
|
(capitalize-word 1))
|
|
|
|
(while (re-search-forward "\\<" nil t)
|
|
|
|
(if (looking-at "[A-Z][a-z]*[A-Z]")
|
|
|
|
(forward-word 1)
|
|
|
|
(if (let ((case-fold-search t))
|
1996-09-22 21:48:30 +00:00
|
|
|
(looking-at bib-capitalize-title-stop-regexp))
|
1991-02-04 22:07:47 +00:00
|
|
|
(downcase-word 1)
|
|
|
|
(capitalize-word 1)))
|
|
|
|
))
|
|
|
|
(set-syntax-table orig-syntax-table))))
|
|
|
|
|
|
|
|
|
1996-09-22 21:48:30 +00:00
|
|
|
(defun bib-capitalize-title (s)
|
1991-02-04 22:07:47 +00:00
|
|
|
"Like `capitalize', but don't capitalize stop words, except the first."
|
* textmodes/two-column.el (2C-split):
* textmodes/texnfo-upd.el (texinfo-multi-file-included-list):
* textmodes/tex-mode.el (tex-set-buffer-directory):
* textmodes/spell.el (spell-region, spell-string):
* textmodes/reftex.el (reftex-erase-buffer):
(reftex-get-file-buffer-force, reftex-kill-temporary-buffers):
* textmodes/reftex-toc.el (reftex-toc-promote-action):
* textmodes/reftex-sel.el (reftex-get-offset, reftex-insert-docstruct)
(reftex-select-item):
* textmodes/reftex-ref.el (reftex-label-info-update)
(reftex-offer-label-menu):
* textmodes/reftex-index.el (reftex-index-change-entry)
(reftex-index-phrases-info):
* textmodes/reftex-global.el (reftex-create-tags-file)
(reftex-save-all-document-buffers, reftex-ensure-write-access):
* textmodes/reftex-dcr.el (reftex-echo-ref, reftex-echo-cite)
(reftex-view-crossref-from-bibtex):
* textmodes/reftex-cite.el (reftex-bibtex-selection-callback)
(reftex-extract-bib-entries-from-thebibliography)
(reftex-all-used-citation-keys, reftex-create-bibtex-file):
* textmodes/refbib.el (r2b-capitalize-title):
(r2b-convert-buffer, r2b-help):
* textmodes/page-ext.el (pages-directory)
(pages-directory-goto-with-mouse):
* textmodes/bibtex.el (bibtex-validate-globally):
* textmodes/bib-mode.el (bib-capitalize-title):
* textmodes/artist.el (artist-clear-buffer, artist-system):
* progmodes/xscheme.el (global-set-scheme-interaction-buffer):
(local-set-scheme-interaction-buffer, xscheme-process-filter)
(verify-xscheme-buffer, xscheme-enter-interaction-mode)
(xscheme-enter-debugger-mode, xscheme-debugger-mode-p)
(xscheme-send-control-g-interrupt, xscheme-start-process)
(xscheme-process-sentinel, xscheme-cd):
* progmodes/verilog-mode.el (verilog-read-always-signals)
(verilog-set-define, verilog-getopt-file)
(verilog-module-inside-filename-p):
* progmodes/sh-script.el:
* progmodes/python.el (python-pdbtrack-get-source-buffer)
(python-pdbtrack-grub-for-buffer, python-execute-file):
* progmodes/octave-inf.el (inferior-octave):
* progmodes/idlwave.el (idlwave-scan-user-lib-files)
(idlwave-shell-compile-helper-routines, idlwave-set-local)
(idlwave-display-completion-list-xemacs, idlwave-list-abbrevs)
(idlwave-display-completion-list-emacs, idlwave-list-load-path-shadows)
(idlwave-completion-fontify-classes, idlwave-display-calling-sequence):
* progmodes/idlw-shell.el (idlwave-shell-examine-display-clear)
(idlwave-shell-filter, idlwave-shell-examine-highlight)
(idlwave-shell-sentinel, idlwave-shell-filter-directory)
(idlwave-shell-display-line, idlwave-shell-set-bp-in-module)
(idlwave-shell-examine-display, idlwave-shell-run-region)
(idlwave-shell-filter-bp, idlwave-shell-save-and-action)
(idlwave-shell-sources-filter, idlwave-shell-goto-next-error):
* progmodes/idlw-help.el (idlwave-help-get-special-help)
(idlwave-help-get-help-buffer):
* progmodes/gud.el (gud-basic-call, gud-find-class)
(gud-tooltip-activate-mouse-motions-if-enabled):
* progmodes/gdb-mi.el (gdb-mouse-toggle-breakpoint-fringe):
* progmodes/ebrowse.el (ebrowse-member-table, ebrowse-save-tree-as)
(ebrowse-view-exit-fn, ebrowse-tags-list-members-in-file)
(ebrowse-tags-next-file):
* progmodes/ebnf2ps.el (ebnf-generate-eps, ebnf-generate-eps)
(ebnf-eps-production-list, ebnf-begin-file, ebnf-log)
(ebnf-eps-finish-and-write):
* progmodes/cpp.el (cpp-edit-save):
* progmodes/cperl-mode.el (cperl-pod-to-manpage):
* progmodes/cc-defs.el (c-emacs-features):
* progmodes/antlr-mode.el (antlr-invalidate-context-cache)
(antlr-directory-dependencies):
* progmodes/ada-xref.el (ada-gnat-parse-gpr, ada-get-ali-file-name)
(ada-run-application, ada-find-in-src-path, ada-goto-parent)
(ada-find-any-references, ada-make-filename-from-adaname)
(ada-make-body-gnatstub):
* obsolete/rnews.el (news-list-news-groups):
* obsolete/resume.el (resume-suspend-hook,resume-write-buffer-to-file):
* obsolete/iso-acc.el (iso-acc-minibuf-setup):
* net/rcirc.el (rcirc-debug):
* net/newst-treeview.el (newsticker--treeview-list-add-item)
(newsticker--treeview-list-clear, newsticker-treeview-browse-url)
(newsticker--treeview-list-update-faces, newsticker-treeview-save)
(newsticker--treeview-item-show-text, newsticker--treeview-item-show)
(newsticker--treeview-tree-update-tag,newsticker--treeview-buffer-init)
(newsticker-treeview-show-item, newsticker--treeview-unfold-node)
(newsticker--treeview-list-clear-highlight)
(newsticker--treeview-list-update-highlight)
(newsticker--treeview-list-highlight-start)
(newsticker--treeview-tree-update-highlight)
(newsticker--treeview-get-selected-item)
(newsticker-treeview-mark-list-items-old)
(newsticker--treeview-set-current-node):
* net/newst-plainview.el (newsticker--buffer-set-uptodate):
* net/newst-backend.el (newsticker--get-news-by-funcall)
(newsticker--get-news-by-wget, newsticker--image-get)
(newsticker--image-sentinel):
* net/mairix.el (mairix-rmail-fetch-field, mairix-gnus-fetch-field):
* net/eudcb-ph.el (eudc-ph-do-request, eudc-ph-open-session):
(eudc-ph-close-session):
* net/eudc.el (eudc-save-options):
* language/thai-word.el (thai-update-word-table):
* language/japan-util.el (japanese-string-conversion):
* international/titdic-cnv.el (tsang-quick-converter)
(ziranma-converter, ctlau-converter):
* international/mule-cmds.el (describe-language-environment):
* international/ja-dic-cnv.el (skkdic-convert-okuri-ari)
(skkdic-convert-postfix, skkdic-convert-prefix):
(skkdic-convert-okuri-nasi, skkdic-convert):
* emacs-lisp/re-builder.el (reb-update-overlays):
* emacs-lisp/pp.el (pp-to-string, pp-display-expression):
* emacs-lisp/gulp.el (gulp-send-requests):
* emacs-lisp/find-gc.el (trace-call-tree):
* emacs-lisp/eieio-opt.el (eieio-browse, eieio-describe-class)
(eieio-describe-generic):
* emacs-lisp/eieio-base.el (eieio-persistent-read):
* emacs-lisp/edebug.el (edebug-outside-excursion):
* emacs-lisp/debug.el (debugger-make-xrefs):
* emacs-lisp/cust-print.el (custom-prin1-to-string):
* emacs-lisp/chart.el (chart-new-buffer):
* emacs-lisp/authors.el (authors-scan-el, authors-scan-change-log):
Use with-current-buffer.
* textmodes/artist.el (artist-system): Don't call
copy-sequence on a fresh string.
* progmodes/idlw-shell.el (easymenu setup): Use dolist.
2009-10-31 02:38:34 +00:00
|
|
|
(with-current-buffer (get-buffer-create "$$$Scratch$$$")
|
|
|
|
(erase-buffer)
|
|
|
|
(insert s)
|
|
|
|
(bib-capitalize-title-region (point-min) (point-max))
|
|
|
|
(buffer-string)))
|
1992-03-16 20:39:07 +00:00
|
|
|
|
|
|
|
(provide 'bib-mode)
|
|
|
|
|
2008-04-10 14:10:46 +00:00
|
|
|
;; arch-tag: e3a97958-3c2c-487f-9557-fafc3c98452d
|
1992-05-30 23:54:21 +00:00
|
|
|
;;; bib-mode.el ends here
|