Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!mcvax!inria!shapiro From: shapiro@inria.UUCP (Marc Shapiro) Newsgroups: comp.emacs Subject: bibtex-mode.el Message-ID: <563@inria.UUCP> Date: Mon, 26-Oct-87 10:30:10 EST Article-I.D.: inria.563 Posted: Mon Oct 26 10:30:10 1987 Date-Received: Thu, 29-Oct-87 01:34:38 EST Organization: INRIA, Rocquencourt. France Lines: 352 This is the third and last edition of my proposed bibtex-mode.el, a mode for editing BibTeX files. as far as I can tell there are no bugs left. It is better than the original posted on the news some time ago, and than my previous versions, because: - long lines are correctly aligned - TAB and LFD always go to the end of the current string (where editing is most likely to take place) - commands which delete always check what they delete; i.e. doing C-c C-o (for instance) twice is innocuous - an X menu is available (optionally) Have fun! Marc Shapiro INRIA; B.P. 105; 78153 Le Chesnay Cedex; France; tel.: +33 (1) 39-63-53-25 e-mail: shapiro@inria.inria.fr; or: ...!mcvax!inria!shapiro ---- (cut here) ---------------------- ;;; Simple BibTeX mode for GNU Emacs ;;; Bengt Martensson 87-06-28 ;;; changes by Marc Shapiro shapiro@inria.inria.fr 15-oct-1986 ;;; (align long lines nicely; C-c C-o checks for the "OPT" string; ;;; TAB goes to the end of the string; use lower case; use ;;; run-hooks) ;;; Marc Shapiro 19-oct-1987 ;;; add X window menu option; bug fixes. TAB, LFD, C-c " and C-c C-o now ;;; behave consistently; deletion never occurs blindly. ;;; (defvar bibtex-mode-syntax-table nil "") (defvar bibtex-mode-abbrev-table nil "") (define-abbrev-table 'bibtex-mode-abbrev-table ()) (defvar bibtex-mode-map (make-sparse-keymap) "") (defun bibtex-mode () "Major mode for editing bibtex files. A command such as \\[bibtex-Book] will outline the fields for a BibTeX book entry. The optional fields are preceded by ""OPT"", thus ignored by BibTeX. Use \\[bibtex-remove-opt] to remove ""OPT"" on the current line. Use \\[find-it] to position the dot at the end of the string on the same line. Use \\[next-position] to move to the next position to fill in. Use \\[kill-current-line] to kill the whole line. bibtex-x-environment binds X menus for the above to control+right mouse button. Commands: \\{bibtex-mode-map} Fields: address Publisher's address annote Long annotation used for annotated bibliographies (begins sentence) author Name(s) of author(s), in BibTeX name format booktitle Book title when the thing being referenced isn't the whole book. For book entries, the title field should be used instead. chapter Chapter number edition Edition of a book (e.g., ""second"") editor Name(s) of editor(s), in BibTeX name format. If there is also an author field, then the editor field should be for the book or collection that the work appears in howpublished How something strange has been published (begins sentence) institution Sponsoring institution journal Journal name (macros are provided for many) key Alphabetizing and labeling key (needed when no author or editor) month Month (macros are provided) note To help the reader find a reference (begins sentence) number Number of a journal or technical report organization Organization (sponsoring a conference) pages Page number or numbers (use `--' to separate a range) publisher Publisher name school School name (for theses) series The name of a series or set of books. An individual book will will also have it's own title title The title of the thing being referenced type Type of a Techreport (e.g., ""Research Note"") to be used instead of the default ""Technical Report"" volume Volume of a journal or multivolume work year Year---should contain only numerals --------------------------------------------------------- Entry to this mode calls the value of bibtex-mode-hook if that value is non-nil." (interactive) (kill-all-local-variables) (if (not bibtex-mode-syntax-table) (setq bibtex-mode-syntax-table (copy-syntax-table))) (set-syntax-table bibtex-mode-syntax-table) (modify-syntax-entry ?\$ "$$ ") (modify-syntax-entry ?\% "< ") (modify-syntax-entry ?\f "> ") (modify-syntax-entry ?\n "> ") (modify-syntax-entry ?' "w ") (modify-syntax-entry ?@ "w ") (use-local-map bibtex-mode-map) (setq major-mode 'bibtex-mode) (setq mode-name "BibTeX") (set-syntax-table bibtex-mode-syntax-table) (setq local-abbrev-table bibtex-mode-abbrev-table) (make-local-variable 'paragraph-start) (setq paragraph-start "^[ \f\n\t]*$") (define-key bibtex-mode-map "\t" 'find-it) (define-key bibtex-mode-map "\n" 'next-position) (define-key bibtex-mode-map "\e[25~" 'next-position) (define-key bibtex-mode-map "\C-c""" 'bibtex-remove-double-quotes) (define-key bibtex-mode-map "\C-c\eOS" 'kill-current-line) (define-key bibtex-mode-map "\C-c\C-k" 'kill-current-line) (define-key bibtex-mode-map "\C-c\C-a" 'bibtex-Article) (define-key bibtex-mode-map "\C-c\C-b" 'bibtex-Book) (define-key bibtex-mode-map "\C-cb" 'bibtex-Booklet) (define-key bibtex-mode-map "\C-c\C-c" 'bibtex-InProceedings) (define-key bibtex-mode-map "\C-c\C-i" 'bibtex-InBook) (define-key bibtex-mode-map "\C-ci" 'bibtex-InCollection) (define-key bibtex-mode-map "\C-cI" 'bibtex-InProceedings) (define-key bibtex-mode-map "\C-c\C-m" 'bibtex-Manual) (define-key bibtex-mode-map "\C-cm" 'bibtex-MastersThesis) (define-key bibtex-mode-map "\C-cM" 'bibtex-Misc) (define-key bibtex-mode-map "\C-c\C-o" 'bibtex-remove-opt) (define-key bibtex-mode-map "\C-c\C-p" 'bibtex-PhdThesis) (define-key bibtex-mode-map "\C-cp" 'bibtex-Proceedings) (define-key bibtex-mode-map "\C-c\C-t" 'bibtex-TechReport) (define-key bibtex-mode-map "\C-c\C-s" 'bibtex-string) (define-key bibtex-mode-map "\C-c\C-u" 'bibtex-Unpublished) (define-key bibtex-mode-map "\C-c?" 'describe-mode) ; nice alignements (auto-fill-mode 1) (setq left-margin 17) (run-hooks 'bibtex-mode-hook)) (defun bibtex-entry (entry-type required optional) (insert (concat "@" entry-type "{,\n\n}\n\n")) (previous-line 3) (insert (mapconcat 'make-entry required ",\n")) (if required (insert ",\n")) (insert (mapconcat 'make-opt-entry optional ",\n")) (up-list -1) (forward-char 1)) (defun make-entry (str) (interactive "s") (concat " " str " = \t""""")) (defun make-opt-entry (str) (interactive "s") (concat " OPT" str " = \t""""")) (defun bibtex-Article () (interactive) (bibtex-entry "Article" '("author" "title" "journal" "year") '("volume" "number" "pages" "month" "note"))) (defun bibtex-Book () (interactive) (bibtex-entry "Book" '("author" "title" "publisher" "year") '("editor" "volume" "series" "address" "edition" "month" "note"))) (defun bibtex-Booklet () (interactive) (bibtex-entry "Booklet" '("title") '("author" "howpublished" "address" "month" "year" "note"))) (defun bibtex-InBook () (interactive) (bibtex-entry "InBook" '("author" "title" "chapter" "publisher" "year") '("editor" "pages" "volume" "series" "address" "edition" "month" "note"))) (defun bibtex-InCollection () (interactive) (bibtex-entry "InCollection" '("author" "title" "booktitle" "publisher" "year") '("editor" "chapter" "pages" "address" "month" "note"))) (defun bibtex-InProceedings () (interactive) (bibtex-entry "InProceedings" '("author" "title" "booktitle" "year") '("editor" "pages" "organization" "publisher" "address" "month" "note"))) (defun bibtex-Manual () (interactive) (bibtex-entry "Manual" '("title") '("author" "organization" "address" "edition" "year" "month" "note"))) (defun bibtex-MastersThesis () (interactive) (bibtex-entry "MastersThesis" '("author" "title" "school" "year") '("address" "month" "note"))) (defun bibtex-Misc () (interactive) (bibtex-entry "Misc" '() '("author" "title" "howpublished" "year" "month" "note"))) (defun bibtex-PhdThesis () (interactive) (bibtex-entry "PhdThesis" '("author" "title" "school" "year") '("address" "month" "note"))) (defun bibtex-Proceedings () (interactive) (bibtex-entry "Proceedings" '("title" "year") '("editor" "publisher" "organization" "address" "month" "note"))) (defun bibtex-TechReport () (interactive) (bibtex-entry "TechReport" '("author" "title" "institution" "year") '("type" "number" "address" "month" "note"))) (defun bibtex-Unpublished () (interactive) (bibtex-entry "Unpublished" '("author" "title" "note") '("year" "month"))) (defun bibtex-string () (interactive) (insert "@string{ = """"}\n") (previous-line 1) (forward-char 8)) (defun next-position () "Finds next posion to write in." (interactive) (beginning-of-next-line) (find-it)) (defun find-it () (interactive) "Find position on current line (if possible) to add entry text." (beginning-of-line) (let ((beg (point))) (end-of-line) (search-backward "," beg t) (backward-char 1) (if (looking-at """") t (forward-char 1)) )) (defun bibtex-remove-opt () "Removes the 'OPT' starting optional arguments." (interactive) (beginning-of-line) (forward-char 2) (if (looking-at "OPT") (delete-char 3)) (find-it)) (defun kill-current-line () "Kills the current line." (interactive) (beginning-of-line) (kill-line 1)) (defun bibtex-remove-double-quotes () "Removes """" around string." (interactive) (find-it) (let ((here (point)) (eol (progn (end-of-line) (point)))) (beginning-of-line) (if (search-forward """" eol t) (progn (delete-char -1) (if (search-forward """" eol t) (delete-char -1) )) (goto-char here)) ) ) (defun beginning-of-next-line () (end-of-line) (forward-char) ) ;;; X window menus for bibtex mode (defun x-bibtex-help (arg) "Mouse commands for BibTeX mode" (let ((selection (x-popup-menu arg '("BibTeX commands" ("Document types" ("article in Conference Proceedings" . bibtex-InProceedings) ("article in journal" . bibtex-Article) ("Book" . bibtex-Book) ("Booklet" . bibtex-Booklet) ("Master's Thesis" . bibtex-MastersThesis) ("Phd. Thesis" . bibtex-PhdThesis) ("Technical Report" . bibtex-TechReport) ("technical Manual" . bibtex-Manual) ("Conference Proceedings" . bibtex-Proceedings) ("in a Book" . bibtex-InBook) ("in a Collection" . bibtex-InCollection) ("miscellaneous" . bibtex-Misc) ("unpublished" . bibtex-Unpublished) ) ("others" ("next field" . next-position) ("to end of field" . find-it) ("remove OPT" . bibtex-remove-opt) ("remove quotes" . bibtex-remove-double-quotes) ("remove this line" . kill-current-line) ("describe BibTeX mode" . describe-mode) ("string" . bibtex-string)))))) (and selection (call-interactively selection)))) (defun bibtex-x-environment () "Set up X menus for BibTeX mode. Call it as bibtex-mode-hook, or interactively" (interactive) (require 'x-mouse) (make-variable-buffer-local 'mouse-map) (define-key mouse-map x-button-c-right 'x-bibtex-help) ) --- (the end) -------------