;;; mmm-slatex.el --- MMM submode class for SLaTeX programs ;; ;; Copyright 2005 Christopher Dutchyn . ;; ;; If you use and/or change this code; please email me. The most ;; recent version will be kept (during my graduate career) at ;; . ;; ;;{{{ GPL ;; This file is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 2, or (at your option) ;; any later version. ;; This file 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 ;; along with GNU Emacs; see the file COPYING. If not, write to ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, ;; Boston, MA 02111-1307, USA. ;;}}} ;;; Commentary: ;; This file contains the definition of an MMM mode submode class for ;; editing SLaTeX programs. There are some limitations; search for ;; `!! later' in this file to examine these. ;; How to install: ;; 1. install mmm-mode (http://mmm-mode.sourceforge.net) ;; this code was written for mmm-mode-0.4.8 ;; ;; 2. copy this file into your Emacs sitelisp directory ;; ;; 3. add several lines to your .emacs file ;; ;; SLaTeX [requires MMM] ;; (require 'mmm-auto) ;; (require 'mmm-slatex) ;; (setq mmm-global-mode 'maybe) ;; (add-to-list 'mmm-mode-ext-classes-alist ;; '(latex-mode "\\.tex$" slatex)) ;; ;; Usage notes: ;; 1. several practical inserts have been supplied: ;; Key Inserts ;; --- ------- ;; C-c % / universal mmm-mode ... ignore ;; C-c % s scheme???{} mmm-slatex internal use ;; C-c % { scheme{} ;; C-c % $ schemeresult{} ;; C-c % M-s scheme???|| mmm-slatex internal use ;; C-c % | scheme|| ;; C-c % e {scheme???} mmm-slatex internal use ;; C-c % < {schemedisplay} ;; C-c % [ {schemeresponse} ;; C-c % : eval{} ;; ;; 2. The various \defscheme???token strings are bound to their ;; default tokens "scheme???". These can be changed below. ;; ;; 3. The scheme mode to use is defaulted to 'scheme-mode, but you ;; can change mmm-slatex-code-mode if you like 'quack-mode or ;; other. ;; ;; 4. As with all mmm-mode operations, MMM->Parse Buffer is useful ;; to tell emacs to find and decorate manually-entered scheme ;; subregions. ;; ;; 5. There appears to be a bug in mmm-mode-0.4.8 where a totally ;; empty subregion breaks the parser. The message I receive is ;; `Wrong type argument: integer-or-marker-p, nil'. In this ;; case, the problematic subregion will show up undecorated. ;; [Any subregions following the failed one, may remain ;; decorated because MMM-ification didn't rewrite them.] ;; Therefore, I've made the insertions automatically put insert ;; `...' as a placeholder. ;; ;; 6. At mmm-submode-decoration-level 1, all scheme code and ;; results are shown in mmm-default-submode-face. At ;; mmm-submode-decoration-level 2, scheme code is displayed in ;; mmm-code-submode-face and scheme results in ;; mmm-output-submode-face. You can customize these three ;; faces for yourself: for Emacs 21, try using the menu path ;; Options->Customize Emacs->Faces Matching Regexp ...->`mmm-*' ;; ;;; Code: (require 'mmm-vars) (require 'mmm-auto) ;;{{{ Variables (defvar mmm-slatex-code-mode 'scheme-mode "*Major mode for editing SLaTeX code chunks. This is set to SCHEME-MODE by default, but you might want to change this in the Local Variables section of your file to something more fancy, like QUACK-MODE.") ;; These are the default token matching strings. ;; If you use \defschemeXXXtoken, then modify these to conform. (defvar mmm-slatex-scheme-token "scheme") (defvar mmm-slatex-schemebox-token "schemebox") (defvar mmm-slatex-schemeregion-token "schemeregion") (defvar mmm-slatex-schemeresult-token "schemeresult") (defvar mmm-slatex-schemedisplay-token "schemedisplay") (defvar mmm-slatex-schemeresponse-token "schemeresponse") (defvar mmm-slatex-schemeresponsebox-token "schemeresponsebox") (defvar mmm-slatex-inline-front (concat "\\\\" (mmm-regexp-opt `(,mmm-slatex-scheme-token ,mmm-slatex-schemeresult-token) t)) "Regexp for inline front (not including delimiter).") (defvar mmm-slatex-inline-back (concat "~" (number-to-string (+ 1 (regexp-opt-depth mmm-slatex-inline-front)))) "Regexp for inline back delimiter (if not known already).") (defvar mmm-slatex-env-front (concat "\\\\begin *{" (mmm-regexp-opt `(,mmm-slatex-schemedisplay-token ,mmm-slatex-schemebox-token ,mmm-slatex-schemeresponse-token ,mmm-slatex-schemeresponsebox-token) t) "}") "Regexp for environment front.") ;;}}} ;;{{{ Support for mmm submode stuff (defun mmm-slatex-inline-face (string) (if (string-match mmm-slatex-schemeresult-token string) 'mmm-output-submode-face 'mmm-code-submode-face)) (defun mmm-slatex-env-face (string) (if (or (string-match mmm-slatex-schemeresponse-token string) (string-match mmm-slatex-schemeresponsebox-token string)) 'mmm-output-submode-face 'mmm-code-submode-face)) ;;}}} ;;{{{ mmm slatex submode group ;;!! later -- we currently ignore the sidecase of disabling mmm ;; submodes within {verbatim} and \verb ;;!! later -- we ignore \slatexdisable{...} and ... commands ;;!! later -- we ignore \defslatexenvstyle and default to LaTeX (mmm-add-group ;mmm-add-to-group 'slatex `(;;code chunks (scheme-inline :match-name scheme-inline :submode ,mmm-slatex-code-mode :front ,(concat mmm-slatex-inline-front "{") :back "}" :match-face mmm-slatex-inline-face :insert ((?s scheme???{} "Inline scheme[result]: " @ "\\" str "{" @ _ "..." @ "}" @) (?{ scheme{} ?s . ,mmm-slatex-scheme-token) (?$ schemeresult{} ?s . ,mmm-slatex-schemeresult-token)) :delimiter-mode latex-mode :case-fold-search nil :end-not-begin t) (scheme-inline-delim :match-name scheme-inline-delim :submode ,mmm-slatex-code-mode :front ,(concat mmm-slatex-inline-front "\\([^a-zA-Z \t{]\\)") :back ,mmm-slatex-inline-back :save-matches t :match-face mmm-slatex-inline-face :insert (((meta . ?s) scheme???XX "Inline scheme[result]: " @ "\\" str "|" @ _ "..." @ "|" @) (?| schemeXX (meta . ?s) . ,mmm-slatex-scheme-token)) :delimiter-mode latex-mode :case-fold-search nil :end-not-begin t) (scheme-env :match-name scheme-env :submode ,mmm-slatex-code-mode :front ,mmm-slatex-env-front :back "\\\\end[ \t]*{~1}" :save-matches t :match-face mmm-slatex-env-face :insert ((?e {scheme???} "Environment scheme{display|box|response [box]}: " @ "\\begin{" str "}" ?\n @ _ "..." @ ?\n "\\end{" str "}" @) (?< {schemedisplay} ?S . ,mmm-slatex-schemedisplay-token) (?[ {schemeresponse} ?S . ,mmm-slatex-schemeresponse-token)) :delimiter-mode latex-mode :case-fold-search nil) ;;!! later -- make \begin{schemeregion} ... \end{schemeregion} have ;; a background selected in rotation from a pale colour ;; list (eg. red green blue) and make code blocks stand ;; out with deeper colours ;;(scheme-region ;; :submode latex ;; :front ,(concat "\\\\begin[ \t]*{" mmm-slatex-schemeregion-token "}") ;; :back ,(concat "\\\\end[ \t]*{" mmm-slatex-schemeregion-token "}")) ;;!! later -- deal with comments within code blocks ;;!! later -- add narrow-to-region and send-to-scheme ;;evaluation chunks (eval-4-tex :match-name eval :submode ,mmm-slatex-code-mode :front "\\\\eval[ \t]*{" :back "}" :face mmm-code-submode-face :insert ((?: eval{} nil @ "\\eval{" @ _ "..." @ "}" @)) :delimiter-mode latex-mode :case-fold-search nil) )) ;;}}} ;;{{{ Set Mode Line (defun mmm-slatex-set-mode-line () (setq mmm-buffer-mode-display-name "SLaTeX")) (add-hook 'mmm-slatex-class-hook 'mmm-slatex-set-mode-line) ;;}}} (provide 'mmm-slatex) ;;; mmm-slatex.el ends here