home *** CD-ROM | disk | FTP | other *** search
- ;;
- ;; File:
- ;; texmode.mut
- ;;
- ;; Description:
- ;; Rountines to make (La)TeX input more fun.
- ;;
- ;; - No attempt has been made to be compatible with GNU emacs or another
- ;; 'smart' editor.
- ;;
- ;; - Based on the (probably) most frequently used commands of the Quick
- ;; Reference Quide in "LaTeX User's Guide & Reference Manual" by
- ;; Leslie Lamport.
- ;;
- ;; - The new paragraph commands assume that both an empty line and a line
- ;; that starts with `\[beis]` mark the begin of a paragraph (\begin,
- ;; \end, \item, \section). This can be annoying sometimes!
- ;;
- ;; - tex-format-paragraph is not as sophisticated as 'adjust-lines' in
- ;; 'adjust.mut', but it is much faster and real formatting is assumed
- ;; to be done by (La)TeX.
- ;;
- ;; - Since I like to have an almost "normal" keyboard, no attempt has
- ;; been made for very smart key bindings, just type M-\ or C-\ to
- ;; invoke a kind of LaTeX menu. Maybe command completion for
- ;; LaTeX commands is better.
- ;;
- ;; - I borrowed some stuff from 'textmode.mut'.
- ;;
- ;; History:
- ;; 920901 M.J. van der Velden (vdvelden@rcl.wau.nl)
- ;; Public Domain (Version 1.0)
- ;;
-
- (include "me2.h")
-
- (const
- TEX-FILL-COLUMN 72 ;; Column to word wrap at (0 means no wrapping)
- TEX-TAB-SIZE 4 ;; Tab size (0 means use the TAB character)
- )
-
- (small-int tex-fill-col)
-
- (defun
- ;; Try to guess what the user wants based on the next keystroke.
- tex-expand-backslash
- {
- (string what)
- (int level)
-
- (msg "\\")
-
- (switch (getchar)
- "\\" {
- (insert-text "\\")
- }
- "\"" {
- (insert-text "``''")
- (arg-prefix 2) (previous-character)
- }
- "b" {
- (ask-user)
- (what (ask "\\begin What? "))
- (if (> (current-column) 1) {
- (insert-text "{\\" what " }")
- (previous-character)
- } {
- (insert-text "\\begin{" what "}^J\\end{" what "}^J")
- (previous-line)
- (open-line)
- })
- }
- "c" {
- (msg "\\c")
- (switch (getchar)
- "a" {
- (insert-text "\\caption{}")
- (previous-character)
- }
- "h" {
- (insert-text "\\chapter{}")
- (previous-character)
- }
- "i" {
- (insert-text "\\cite{}")
- (previous-character)
- }
- )
- }
- "d" {
- (insert-text "\\documentstyle{}")
- (previous-character)
- }
- "e" {
- (insert-text "{\\em }")
- (previous-character)
- }
- "f" {
- (insert-text "\\footnote{}")
- (previous-character)
- }
- "i" {
- (insert-text "\\item ")
- }
- "l" {
- (insert-text "\\label{}")
- (previous-character)
- }
- "m" {
- (insert-text "\\maketitle^J")
- }
- "n" {
- (insert-text "\\newpage^J")
- }
- "p" {
- (insert-text "\\pagestyle{}")
- (previous-character)
- }
- "r" {
- (insert-text "\\ref{}")
- (previous-character)
- }
- "s" {
- (ask-user)
- (msg "\\section Level? ")
- (level (switch (getchar) "1" 1 "2" 2 "3" 3 default 0))
- (insert-text "\\")
- (while (>= (-= level 1) 0)
- (insert-text "sub")
- )
- (insert-text "section{}^J")
- (arg-prefix 2) (previous-character)
- }
- "t" {
- (insert-text "\\tableofcontents^J")
- }
- "v" {
- (insert-text "\\verb++")
- (previous-character)
- }
- "$" {
- (insert-text "$$")
- (previous-character)
- }
- )
- }
-
- ;; Go to the beginning of the current paragraph.
- ;; If between paragraphs then go to begin of next paragraph.
- tex-begin-of-paragraph
- {
- (beginning-of-line)
- (while (and (not (EoB)) (looking-at '\ *$'))
- (forward-line 1)
- )
-
- (while (TRUE) {
- (if (looking-at '\ *$')
- (break)
- )
- (if (looking-at '\\[beis]')
- (break)
- )
- (if (not (forward-line -1))
- (break)
- )
- })
-
- (if (looking-at '\ *$')
- (forward-line 1)
- )
- }
-
- ;; Go to the end of the current paragraph.
- tex-end-of-paragraph
- {
- (beginning-of-line)
- (while (looking-at '\ *$')
- (forward-line 1)
- )
-
- (while (not (EoB)) {
- (forward-line 1)
- (if (looking-at '\\[beis]')
- (break)
- )
- (if (looking-at '\ *$')
- (break)
- )
- })
-
- (forward-line -1)
- (end-of-line)
- }
-
- ;; Select a paragraph.
- tex-select-paragraph
- {
- (tex-begin-of-paragraph)
- (set-mark THE-MARK)
- (tex-end-of-paragraph)
- }
-
- ;; Format a paragraph, (left justify).
- ;; if wrap-solid-lines then
- ;; solid lines are wrapped
- ;; endif
- tex-format-paragraph ;; [BOOL wrap-solid-lines]
- {
- (bool wrap-solid-lines)
- (bool at-end-of-paragraph)
- (small-int right-margin)
-
- (wrap-solid-lines (if (== (nargs) 0) TRUE (arg 0)))
- (right-margin (if (== 0 (word-wrap)) (tex-fill-column) (word-wrap)))
-
- (tex-begin-of-paragraph)
- (at-end-of-paragraph FALSE)
- (while (not at-end-of-paragraph) {
- (end-of-line)
- (delete-previous-whitespace)
- (if (> (current-column) (right-margin)) {
- ;; a "long line"
- (current-column (+ (right-margin) 1))
- (while (and (> (current-column) 1) (previous-character)) {
- (if (is-space) {
- (next-character)
- (delete-previous-whitespace)
- (break)
- })
- })
- (if (== (current-column) 1) {
- ;; no space to put a newline
- (if wrap-solid-lines {
- (current-column (+ (right-margin) 1))
- (delete-whitespace)
- (newline)
- } {
- (forward-line 1)
- })
- } {
- (delete-whitespace)
- (newline)
- })
- } {
- ;; a "short" line
- (if (not (EoB)) {
- ;; break out if we are ready
- (forward-line 1)
- (beginning-of-line)
- (if (or (looking-at '\\[beis]') (looking-at '\ *$')) {
- ;; assume \begin or \end or \it (at-end-of-paragraph TRUE)
- } {
- (delete-whitespace)
- (insert-text " ")
- (beginning-of-line)
- (delete-previous-character)
- })
- } {
- (at-end-of-paragraph TRUE)
- })
- })
- })
- }
-
- ;; Fill (left justify) the current paragraph.
- ;; Run a second time to fill the next...
- tex-fill-paragraph
- {
- (tex-format-paragraph FALSE)
- }
-
- ;; Set or get the tex-fill-column.
- tex-fill-column
- {
- (if (!= 0 (nargs))
- (tex-fill-col (arg 0))
- )
- tex-fill-col
- }
-
- tex-mode MAIN
- {
- (clear-modes)
-
- (bind-local-key "newline-and-indent" "C-M" )
- (bind-local-key "tex-end-of-paragraph" "M-e" )
- (bind-local-key "tex-begin-of-paragraph" "M-a" )
- (bind-local-key "tex-select-paragraph" "M-h" )
- (bind-local-key "tex-fill-paragraph" "M-J" )
- (bind-local-key "tex-expand-backslash" "M-\\")
- (bind-local-key "tex-expand-backslash" "C-\\")
-
- (major-mode "(La)TeX")
- (tab-stops TEX-TAB-SIZE)
- (word-wrap TEX-FILL-COLUMN)
- (tex-fill-column TEX-FILL-COLUMN)
- }
- )
-