;;; Mode customization file for emacs ;;; by Gary T. Leavens ;;; ;;; Last update $Date: 2009/06/03 00:31:03 $ ;;; Contents: ;;; (1) Mail related ;;; (2) Outline mode ;;; (3) LaTeX, TeX and friends ;;; (4) Various programming languages ;;; (1) Mail related ;;; auto-indent in PINE temp files (add-to-list 'auto-mode-alist '("pico\\." . text-mode)) (add-hook 'text-mode-hook (function (lambda() (fset 'open-from-exceptions (lambda () "Open my from_exceptions file." (interactive) (find-file-other-window "~/.procmail/from_exceptions") (end-of-buffer) )) (local-set-key [f12] 'open-from-exceptions) ))) ;;; rmime (MIME support for RMAIL) ;;; (add-hook 'rmail-show-message-hook 'rmime-format) (add-hook 'rmail-edit-mode-hook 'rmime-cancel) (autoload 'rmime-format "rmime" "" nil) (defun add-to-email-list (name) "Add the current message's sender to the list given by name." (save-excursion (goto-char (point-min)) (re-search-forward "^From: ") (let ((address-start (point))) (end-of-line) (copy-region-as-kill address-start (point))) (find-file-other-window name) (goto-char (point-min)) (open-line 1) (yank) (save-buffer))) (defun read-and-delete-email-file (file-name) "Have RMAIL read an email folder, and then delete it." (if (file-exists-p file-name) (progn (rmail-get-new-mail file-name) (delete-file file-name))) ) (add-hook 'rmail-mode-hook (function (lambda () (fset 'add-to-whitelist (lambda () "Add the sender to my whitelist of accepted senders of email." (interactive) (add-to-email-list "~/.procmail/whitelist"))) (fset 'add-to-blacklist (lambda () "Add the sender to my blacklist of rejected senders of email." (interactive) (add-to-email-list "~/.procmail/blacklist"))) (fset 'other-email-inboxes (lambda () "Read and delete the no-password, nonauth, and bounces files." (interactive) (read-and-delete-email-file "~/Mail/nonauth") (read-and-delete-email-file "~/Mail/no-password") (read-and-delete-email-file "~/Mail/bounces") )) (fset 'bounces (lambda () "Read and delete the bounces file." (interactive) (read-and-delete-email-file "~/Mail/bounces"))) ))) (add-hook 'rmail-mode-hook (function (lambda () (fset 'reply-to-grad-student (lambda () "Reply with my standard blurb about graduate student support." (interactive) (rmail-reply 0) (mail-cc) (beginning-of-line) (kill-line 1) (end-of-buffer) (forward-line -2) (kill-line 3) (insert-file "~/etc/correspondence/grad-student-support.email") (mail-send-and-exit 0) (switch-to-buffer "RMAIL") (rmail-delete-forward 0) ))))) ;;; Mail mode customization ;;; (add-to-list 'auto-mode-alist '("\\.mail$" . mail-mode)) (add-hook 'mail-mode-hook (function (lambda () (load "mime-compose") ; for including mime in mail messages (make-local-variable 'indent-tabs-mode) (setq indent-tabs-mode nil) (setq mail-yank-prefix "> ") (fset 'mark-mail-for-response "\M-%\C-^\C-j\C-m\C-^\C-j> \C-m!") ; obsolete (auto-fill-mode 1) (setq fill-column 72)))) (add-hook 'mail-setup-hook (function (lambda () (interactive) (mail-cc) (insert ", ") (insert user-login-name) (forward-line -1) (replace-string "CC: , " "CC: ") (mail-text) (insert "\n\n\t") (insert user-full-name) (let ((eol (point))) (beginning-of-line) (forward-word 1) (delete-region eol (point))) (mail-text)))) ;;; Supercite (mail citation) customization. ;;; ;(autoload 'sc-cite-original "supercite" "Supercite 3.1" t) ;(autoload 'sc-submit-bug-report "supercite" "Supercite 3.1" t) ;(add-hook 'mail-citation-hook 'sc-cite-original) ;(setq sc-auto-fill-region-p nil) (add-hook 'text-mode-hook (function (lambda () (auto-fill-mode) (fset 'text-comment (lambda () (interactive) (insert "[[[ -GTL]]]") (backward-char 8) )) (define-key text-mode-map "\C-c;" 'text-comment) ))) ;;; (2) Outline mode (used for lecture notes) ;;; (add-hook 'outline-mode-hook (function (lambda () (make-local-variable 'indent-tabs-mode) (make-local-variable 'fill-column) (defvar slide-fill-column "right hand side of slides") (setq slide-fill-column 42) (setq indent-tabs-mode nil) (fset 'slide (lambda () (interactive) (insert-char ?- slide-fill-column) (insert "\n") (insert "\n") (insert-char ?- slide-fill-column) (insert "\n") (forward-line -2))) ))) ;;; (3) LaTeX, TeX, and friends ;;; Latex mode ;;; (defun my-latex-mode () "Mode hook for latex mode" ;; type "M-x begin" after typing in the name of an environment ;; (C-c C-f in LaTeX mode is similar, ;; but is used after typing \begin{env}) (fset 'begin (lambda () "Start of a LaTeX command." (interactive) (let ((eol (point))) (beginning-of-line) (set-register 4 (buffer-substring (point) eol)) (insert "\\begin{") (end-of-line) (insert "}\n\n\\end{") (insert-register 4) (end-of-line) (insert "}") (forward-line -1)))) (fset 'itemize "itemize\M-xbegin\C-m\\item\C-m") (fset 'enumerate "enumerate\M-xbegin\C-m\\item\C-m") (fset 'verbatim "verbatim\M-xbegin\C-m") ;; The following are for the beamer document class (fset 'frame (lambda () (interactive) (insert "\\begin{frame}\n") (insert "\\frametitle{}\n") (insert "\\end{frame}\n") (forward-line -2) (end-of-line) (backward-char 1))) (fset 'note "\\note{}C-b") ;; The following make quick ways to enter type style changing commands (fset 'bf "\\textbf{}\C-b") ; bold (fset 'em "\\emph{\\/}\C-u3\C-b") ; emphasized (fset 'it "\\textit{\\/}\C-u3\C-b") ; italic (fset 'rm "\\textrm{}\C-b") ; roman (fset 'sc "\\textsc{}\C-b") ; small caps (fset 'sf "\\textsf{}\C-b") ; sans serif (fset 'sl "\\textsl{}\C-b") ; slanted (fset 'tt "\\texttt{}\C-b") ; typewriter (fset 'lil ; lstinline (listings package) (lambda () (interactive) (insert "\\lstinline!!") (backward-char 1)))) (add-hook 'latex-mode-hook (function (lambda () (my-latex-mode)))) ;; for AUCTeX (add-hook 'LaTeX-mode-hook (function (lambda () (my-latex-mode)))) ;;; Tex mode ;;; (defun my-tex-mode () (make-local-variable 'indent-tabs-mode) (setq indent-tabs-mode nil) (fset 'proof "\\PROOF\C-m\\QED\C-a\C-o") (fset 'math "$$\C-b") (local-set-key "\M-$" 'math)) (add-hook 'tex-mode-hook (function (lambda() (my-tex-mode) (if (not (string-equal mode-name "LaTeX")) ;; all my TeX files are actually LaTeX (run-hooks 'latex-mode-hook))))) ;; for AUCTeX (add-hook 'TeX-mode-hook (function (lambda() (my-tex-mode) (if (not (string-equal mode-name "LaTeX")) ;; all my TeX files are actually LaTeX (run-hooks 'LaTeX-mode-hook))))) ;;; PDFLaTeX mode for AUCTeX (add-hook 'PDFLaTeX-mode-hook (function (lambda () (run-hooks 'LaTeX-mode-hook)))) ;;; noweb files, ending in .nw, are considered latex files ;;; (add-to-list 'auto-mode-alist '("\\.nw$" . latex-mode)) ;;; Texinfo mode customization ;;; (add-hook 'texinfo-mode-hook (function (lambda () ;; type "M-x begin" after typing in the name ;; of an environment (fset 'begin "\C-u-1\M-@\C-u\C-xxb@\C-u\C-xgb\C-m@end \C-u\C-xgb\C-a\C-o") (fset 'itemize "itemize\M-xbegin\C-m\C-p\C-e @bullet\C-n@item\C-m") (fset 'enumerate "enumerate\M-xbegin\C-m@item\C-m") (fset 'bf "@strong{}\C-b") ; bold (fset 'em "@emph{}\C-b") ; emphasized (fset 'it "@i{}\C-b") ; italic (fset 'rm "@r{}\C-b") ; roman (fset 'sc "@sc{}\C-b") ; small caps (fset 'sf "@r{}\C-b") ; sans serif (fset 'sl "@i{}\C-b") ; slanted (fset 'tt "@code{}\C-b") ; typewriter ))) ;;; BibTeX bibliography database file mode ;;; (add-hook 'bibtex-mode-hook '(lambda () (fset 'bibtex-no-opt-no-quotes "\C-c\C-o\C-c\"") (define-key bibtex-mode-map "\C-co" 'bibtex-no-opt-no-quotes) (define-key bibtex-mode-map "\"" 'self-insert-command) (fset 'bibtex-authors [?\C-r ?{ ?\C-f escape ?w ?\C-s ?a ?u ?t ?h ?o ?r ?\C-m ?\C-s ?{ ?\C-m ?\C-y ?\C-h ?\C-h ?\C-r ?@ ?\C-m ?\C-s ?k ?e ?y ?\C-m ?\C-s ?{ ?\C-m ?\C-y ?\C-h ?\C-h ?\C-r ?{ ?\C-m escape ?f]) (define-key bibtex-mode-map "\C-c\C-[a" 'bibtex-authors) )) ;;; Some html mode stuff (add-to-list 'auto-mode-alist '("\\.shtml" . html-mode)) (add-hook 'html-mode-hook (function (lambda () (auto-fill-mode 0) (fset 'tt "\C-u6\C-b") ; typewriter ))) ;;; (4) Various programming languages ;;; CLU ;;; (defvar clu-home (or (getenv "CLUHOME") "/usr/unsup/CLU")) (add-to-list 'auto-mode-alist '("\\.clu$" . clu-mode)) (add-to-list 'auto-mode-alist '("\\.spc$" . clu-mode)) (autoload 'clu-mode "clu" "CLU mode" t nil) (setq clu-doc-file-name (concat clu-home "/emacs/CLU-DOC")) ;;; Java ;;; (add-to-list 'completion-ignored-extensions ".class") (add-to-list 'completion-ignored-extensions ".sym") ;;; The following should really be JML mode, but we don't have that yet... (add-to-list 'auto-mode-alist '("\\.refines-java$" . java-mode)) (add-to-list 'auto-mode-alist '("\\.java-refined$" . java-mode)) (add-to-list 'auto-mode-alist '("\\.spec$" . java-mode)) (add-to-list 'auto-mode-alist '("\\.spec-refined$" . java-mode)) (add-to-list 'auto-mode-alist '("\\.refines-spec$" . java-mode)) (add-to-list 'auto-mode-alist '("\\.jml$" . java-mode)) (add-to-list 'auto-mode-alist '("\\.jml-refined$" . java-mode)) (add-to-list 'auto-mode-alist '("\\.refines-jml$" . java-mode)) ;;; Also JML developers consider .*-refined-generic and .*-generic ;;; files to be Java files (add-to-list 'auto-mode-alist '("\\.java-refined-generic$" . java-mode)) (add-to-list 'auto-mode-alist '("\\.java-generic$" . java-mode)) (add-to-list 'auto-mode-alist '("\\.spec-refined-generic$" . java-mode)) (add-to-list 'auto-mode-alist '("\\.spec-generic$" . java-mode)) (add-to-list 'auto-mode-alist '("\\.jml-refined-generic$" . java-mode)) (add-to-list 'auto-mode-alist '("\\.jml-generic$" . java-mode)) ;;; And stuff generated by jmlc... (add-to-list 'auto-mode-alist '("\\.java.gen$" . java-mode)) ;;; And Multijava files (add-to-list 'auto-mode-alist '("\\.mj$" . java-mode)) ;;; I use .m4 for a preprocessor for some Java files (add-to-list 'auto-mode-alist '("\\.m4$" . java-mode)) (autoload 'camelCase-mode "~/emacs/camelCase/camelCase-mode") (add-hook 'java-mode-hook '(lambda () (local-set-key "\M-backspace" 'camelCase-backward-kill-word)) 'append) (add-hook 'java-mode-hook (function (lambda () (make-local-variable 'indent-tabs-mode) (setq indent-tabs-mode nil) (fset 'main (lambda () (interactive) (insert "public static void main(String [] argv) {") (c-indent-command) (insert "\n}") (c-indent-command) (insert "\n") (forward-line -1) (insert "System.out.println(\"\");\n") (forward-line -1) (c-indent-command) (end-of-line) (backward-char 3))) (if window-system (progn (font-lock-mode) (load "andersl-java-font-lock") ))))) ;;; AspectJ mode has the unfortunate effect of screwing up ;;; the compile command for all other modes. So I usuallly leave ;;; it turned off. ;(require 'aspectj-mode) ;;; ANTLR mode (autoload 'antlr-mode "antlr-mode" nil t) (add-to-list 'auto-mode-alist '("\\.g\\'" . antlr-mode)) (add-hook 'speedbar-load-hook ; would be too late in antlr-mode.el (lambda () (speedbar-add-supported-extension ".g"))) (add-hook 'antlr-mode-hook (function (lambda () (make-local-variable 'indent-tabs-mode) (setq indent-tabs-mode nil) (if window-system (progn (font-lock-mode)))))) ;;; Make expanded...g files default to read-only mode (add-hook 'antlr-mode-hook (function (lambda () (if (string-match "expanded.*\\.g" (buffer-name)) (toggle-read-only 1) nil)))) ;;; Smalltalk-80 programs, using GNU smalltalk (add-to-list 'auto-mode-alist '("\\.st$" . smalltalk-mode)) (add-to-list 'auto-mode-alist '("\\.cls$" . smalltalk-mode)) (autoload 'smalltalk-mode "st" nil t) (add-hook 'smalltalk-mode-hook (function (lambda () (make-local-variable 'indent-tabs-mode) (setq indent-tabs-mode nil)))) ;;; Standard ML program mode ;(require 'sml-site) ;;; Haskell mode ;;; (load "haskell-site-file" t) (add-to-list 'auto-mode-alist '("\\.has$" . haskell-mode)) (add-to-list 'auto-mode-alist '("\\.lit$" . literate-haskell-mode)) (add-hook 'haskell-mode-hook 'turn-on-haskell-decl-scan) (add-hook 'haskell-mode-hook 'turn-on-haskell-doc-mode) (add-hook 'haskell-mode-hook 'turn-on-haskell-indent) ;;; or ;;;(add-hook 'haskell-mode-hook 'turn-on-haskell-simple-indent) (add-hook 'haskell-mode-hook (function (lambda () (if window-system (progn (make-local-variable 'indent-tabs-mode) (setq indent-tabs-mode nil) (turn-on-font-lock) ; (set-face-foreground 'haskell-constructor-face "Green") ; (set-face-foreground 'haskell-keyword-face "SkyBlue") ; (set-face-foreground 'haskell-comment-face "GoldenRod") ))))) ;;; LSL mode ;;; (add-to-list 'auto-mode-alist '("\\.lsl$" . lsl-mode)) (autoload 'lsl-mode "lsl-mode" "Major mode for editing Lsl scripts." t) (add-hook 'lsl-mode-hook (lambda () (if window-system (progn (turn-on-font-lock) (set-face-foreground 'lsl-keyword-face "SkyBlue") (set-face-foreground 'lsl-operator-face "Red") (set-face-foreground 'lsl-comment-face "GoldenRod"))))) ;;; Prolog mode ;;; ; (autoload 'prolog-mode "prolog" "Major mode for editing Prolog programs." t) ; (setq prolog-system 'nil) (setq explicit-lprolog-file-name "teyjus") (autoload 'teyjus "teyjus" "Run an inferior Teyjus process." t) (autoload 'teyjus-edit-mode "teyjus" "Syntax Highlighting, etc. for Lambda Prolog" t) (add-to-list 'auto-mode-alist '("\\.mod$" . teyjus-edit-mode)) (add-to-list 'auto-mode-alist '("\\.sig$" . teyjus-edit-mode)) ;;; lambda Prolog mode (add-hook 'teyjus-edit-mode-hook '(lambda () ;; turn on fancy coloring of scheme programs (optional) (font-lock-mode) )) ;;; Oz program mode with Mozart/Oz. ;;; You have to arrange for the Oz-related emacs lisp (.el) files ;;; to be in emacs's load-path, for its bin directory to be in the PATH, ;;; and for the OZHOME environment variable to be set properly. (add-to-list 'auto-mode-alist '("\\.oz\\'" . oz-mode)) (add-to-list 'auto-mode-alist '("\\.ozg\\'" . oz-gump-mode)) (autoload 'run-oz "oz" "" t) (autoload 'oz-mode "oz" "" t) (autoload 'oz-gump-mode "oz" "" t) (autoload 'oz-new-buffer "oz" "" t) (add-hook 'oz-mode-hook '(lambda () (make-local-variable 'indent-tabs-mode) (setq indent-tabs-mode nil) )) ;;; Scala program mode (load "scala-mode-auto" t) ;;; Scheme program mode ;;; Tell emacs that files that end in .ss are Chez Scheme files. ;;; There already is a mapping for the suffix .scm. ;;; (add-to-list 'auto-mode-alist '("\\.ss$" . scheme-mode)) (add-to-list 'auto-mode-alist '("\\.def$" . scheme-mode)) (add-to-list 'auto-mode-alist '("\\.tst$" . scheme-mode)) ;;; use cmuscheme instead of the standard scheme mode. ;;; (autoload 'run-scheme "cmuscheme" "Run Scheme in an emacs buffer." t) (autoload 'scheme-mode "cmuscheme" "Mode for Scheme programming and interaction" t) ;;; Special behavior that I want for scheme program files ;;; (setq scheme-mit-dialect nil) ;;; The following uses "scheme342" as the scheme interpreter ;;; (setq scheme-program-name "sh -c scheme342") ;;; Customize scheme mode ;;; (add-hook 'scheme-mode-hook (function (lambda () (define-key scheme-mode-map "\n" 'newline) (define-key scheme-mode-map "\r" 'newline-and-indent) (put 'cases 'scheme-indent-function 2) (put 'forall 'scheme-indent-function 1) (put 'has-type 'scheme-indent-function 0) (put 'has-type-trusted 'scheme-indent-function 0) (put 'test-type 'scheme-indent-function 0) (put 'module 'scheme-indent-function 2) (if window-system (progn ;; turn on fancy coloring of scheme programs (optional) (font-lock-mode) ;; Modify the font-locked keywords to include some used in EOPL ;; (The following is for GNU emacs 20) (if (> emacs-major-version 19) (progn (setq font-lock-keywords (cons 't (cons '("\\((\\(->\\|cases\\|isa\\|forall\\|def\\(rep\\|type\\|ine-datatype\\)\\|provide\\|module\\|require\\|file\\|lib\\|test-type\\|has-type\\(\\|-trusted\\)\\)\\>\\)" (1 font-lock-keyword-face)) (cdr font-lock-keywords)))) (font-lock-fontify-buffer))) )) (fset 'untyped (lambda () (interactive) (setq scheme-program-name "sh -c scheme342untyped"))) (fset 'typed (lambda () (interactive) (setq scheme-program-name "sh -c scheme342typed"))) ))) ;;; Portable scheme debugger mode ;;; (autoload 'psd-mode "psd" "Portable Scheme Debugger mode" t nil) ;;; ;;; uncomment the following to turn on psd-mode by default when running Scheme ;(add-hook 'inferior-scheme-mode-hook ; (function (lambda () (psd-mode 1))))