Burki's Mathematica Mode
authorRalf Hemmecke <ralf@hemmecke.org>
Tue, 24 Sep 2013 11:21:28 +0000 (13:21 +0200)
committerRalf Hemmecke <ralf@hemmecke.org>
Tue, 24 Sep 2013 11:21:28 +0000 (13:21 +0200)
mathematica.el [new file with mode: 0644]

diff --git a/mathematica.el b/mathematica.el
new file mode 100644 (file)
index 0000000..afa3bc3
--- /dev/null
@@ -0,0 +1,724 @@
+;; mathematica.el for GNU emacs 21.2.1 -- two modes for Mathematica.
+;; Version: June 2004
+
+;; Author:     Burkhard Zimmermann
+;; Maintainer: Burkhard Zimmermann <B.Zimmermann@risc.uni-linz.ac.at>
+;; Credits: 
+;;    mathematica.el is derived from Tim Wichmann's mode mma.el.
+;;    In particular, it takes its font-lock support from there.
+
+;; This program 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 of the License, or
+;; (at your option) any later version.
+;; 
+;; This program 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 this program; if not, write to the Free Software
+;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+;; This file is not part of GNU Emacs but the same permissions apply.
+
+;; Note: Mathematica is a registered trademark of Wolfram Research, Inc.
+
+
+;; declares two modes:
+
+;; mathematica-m-mode       , for editing *.m packages.
+;; mathematica-comint-mode  , for interaction with the Matheamtica kernel (math).
+
+;; the modes are meant to be used together, they interact smoothly.
+
+;;; Commentary:
+
+;;; Installation: 
+
+;; To use mathematica-m-mode you should add the following to your .emacs file:
+;;   (autoload 'mathematica-m-mode "mathematica.el" "Mathematica package file mode" t)
+;;   (setq auto-mode-alist (cons '("\\.m\\'" . mathematica-m-mode) auto-mode-alist))
+
+
+;;; Use:
+
+;; Trick: In the Mathematica buffer, type ?* to initialize an improved dabbrev completion.
+
+;;;; Customization:
+
+;; Optionally, you may configure it using mathematica-m-mode-hook. For instance, activating
+;; the show-paren-mode for Mathematica buffers can be done as follows:
+
+;;   (setq mathematica-m-mode-hook (function (lambda () (interactive)
+;;         (setq mathematica-m-mode-hook-done 1)
+;;         (show-paren-mode)  
+;;         )))
+
+
+;;;; Notes to the Maintainer:
+
+;; bugs/todo:
+
+;; change history:
+
+;; June 21, 2004: fix for (goto-char eline); I moved it after the pop-to-buffer command.
+
+;; June 17, 2004:
+;;    fix to get the rigth window-width for the Mathematica process buffer.
+;;    
+;; June 16, 2004: 
+
+;;    3. respects the window layout of the user:
+;;       uses pop-to-buffer, and no longer switch-to-buffer.
+;;       we set pop-up-windows, a configuration variable for pop-to-buffer, to nil.
+
+;;    2. dabbrev friend buffers configured
+
+;;    1. indentation modified
+
+;;    0.
+;;    changed to dabbrev-expand,
+;;    since dabbrev-completion bugs the user with a list of possible completions in a new window.
+;; May 24, 2004: write a mode help text (appears with C-h m).
+;; May 24, 2004: dabbrev support in the *mathematica* shell buffer, too.
+;; Feb 1, 2003: add indentation support.
+
+;; Jan 30, 2003:
+;; support Mathematica's nested comments.
+;; comment delims in strings, ie " (* ", don't count.
+
+;; Jan 28, 2003: removed debug support.
+;;         removed indentation support.
+
+;; Jan 27, 2003: Started from mma.el,v 1.32 2000/06/27 16:05:19 
+;; Author: Tim Wichmann <wichmann@itwm.uni-kl.de>
+
+
+;;;; Code:
+
+(defconst mathematica-m-version "June 2004"
+  "The version of mathematica.el.
+You should add this number when reporting bugs.")
+
+(defgroup mathematica-m nil
+  "Emacs interface for editing Mathematica *.m files."
+  :group 'languages)
+
+(defvar mathematica-m-mode-syntax-table nil
+  "Syntax table used in mathematica-m mode.")
+
+(if mathematica-m-mode-syntax-table
+    ()
+  (setq mathematica-m-mode-syntax-table (make-syntax-table (standard-syntax-table)))
+; %, &, ... are used for punctuation, ie they may not appear in identifiers.
+  (modify-syntax-entry ?% "." mathematica-m-mode-syntax-table)
+  (modify-syntax-entry ?& "." mathematica-m-mode-syntax-table)
+  (modify-syntax-entry ?+ "." mathematica-m-mode-syntax-table)
+  (modify-syntax-entry ?- "." mathematica-m-mode-syntax-table)
+  (modify-syntax-entry ?/ "." mathematica-m-mode-syntax-table)
+  (modify-syntax-entry ?^ "." mathematica-m-mode-syntax-table)
+  (modify-syntax-entry ?< "." mathematica-m-mode-syntax-table)
+  (modify-syntax-entry ?= "." mathematica-m-mode-syntax-table)
+  (modify-syntax-entry ?> "." mathematica-m-mode-syntax-table)
+  (modify-syntax-entry ?| "." mathematica-m-mode-syntax-table)
+  (modify-syntax-entry ?_ "." mathematica-m-mode-syntax-table)
+; ' is used for mathematica "contexts".
+; following wichmann, we consider it punctuation.
+  (modify-syntax-entry ?\' "." mathematica-m-mode-syntax-table)
+; $ is allowed in identifiers
+  (modify-syntax-entry ?$ "_" mathematica-m-mode-syntax-table)
+; \ is an escape
+  (modify-syntax-entry ?\\ "\\" mathematica-m-mode-syntax-table)
+; " is a string quote
+; ...
+; the properties of ( are: 
+;   (: it is an open-parenthesis character. 
+;   ): its matching anticharacter is ).
+;   1: it is the first character of the comment delimiters "(**)",
+;   n:   such comments may [n]est.
+; (bug in Wichmann's mode: "n" is missing).
+  (modify-syntax-entry ?( "()1n" mathematica-m-mode-syntax-table)
+
+; the properties of ) are: 
+;   ): it is a close-parenthesis character. 
+;   (: its matching anticharacter is (.
+;   4: it is the fourth character of the "(**)"
+;   n:   such comments may [n]est.
+  (modify-syntax-entry ?) ")(4n" mathematica-m-mode-syntax-table)
+
+; * has two functions:
+; 1. punctuation
+; 2. characters 2 and 3 in the comment delimiters "(**)"
+;   n:   such comments may [n]est.
+  (modify-syntax-entry ?* ". 23n" mathematica-m-mode-syntax-table)
+
+; the properties of [ are: 
+;   (: it is an open-parenthesis character. 
+;   ]: its matching anticharacter is ].
+  (modify-syntax-entry ?\[ "(]" mathematica-m-mode-syntax-table)
+
+; the properties of ] are: 
+;   ): it is a close-parenthesis character. 
+;   [: its matching anticharacter is [.
+  (modify-syntax-entry ?\] ")[" mathematica-m-mode-syntax-table)
+
+; the properties of { are: 
+;   (: it is an open-parenthesis character. 
+;   }: its matching anticharacter is }.
+  (modify-syntax-entry ?\{ "(}" mathematica-m-mode-syntax-table)
+
+; the properties of } are: 
+;   ): it is a close-parenthesis character. 
+;   {: its matching anticharacter is {.
+  (modify-syntax-entry ?\] ")[" mathematica-m-mode-syntax-table)
+)
+
+(defvar mathematica-m-mode-map ()
+  "Key map to use in mathematica-m mode.")
+
+;(if mathematica-m-mode-map
+;    ()
+(setq mathematica-m-mode-map (make-sparse-keymap))
+; the order is upside-down, to get a nice text in the mode help,
+; i.e., the most importand command comes last.
+(define-key mathematica-m-mode-map [tab] 'mathematica-m-tab-command)
+(define-key mathematica-m-mode-map [M-right] 'indent-selection-rigidly)
+(define-key mathematica-m-mode-map [M-left]  'dedent-selection-rigidly)
+(define-key mathematica-m-mode-map [C-tab] 'switch-to-mathematica-comint)
+(define-key mathematica-m-mode-map [f3] 'mathematica-comint-start-process)
+(define-key mathematica-m-mode-map [f2] 'mathematica-comint-load)
+;)
+
+; just for testing mathematica.el:
+;(define-key mathematica-m-mode-map [f4] 'indent-relative-maybe)
+
+; Ctrl-tab in *.m
+(defun switch-to-mathematica-comint ()
+  ""
+  (interactive)
+  (pop-to-buffer "*mathematica*"))
+
+; Ctrl-tab in comint
+(defun switch-to-mathematica-m ()
+  ""
+  (interactive)
+  (pop-to-buffer mathematica-comint-last-buffer))
+
+; tab is bound by
+;    (define-key mathematica-m-mode-map [tab] 'mathematica-m-tab-command)
+; to this:
+
+(defun mathematica-m-tab-command ()
+  ""
+  (interactive)
+  (if (or (bolp) nil) ; (empty-line-p)) ; if at an empty line or at the beginning of a line, 
+; note: statt bolp haette ich lieber: wenn links vom cursor nur whitespace ist.
+     (indent-relative-maybe) ; then: indent;     ;(indent-for-tab-command) 
+     (dabbrev-expand nil) ;  otherwise: expand word. 
+                          ; the argument nil is needed. I don't know what it means. 
+  )
+)
+
+; debug code: (global-set-key [f5] 'mathematica-m-tab-command)
+
+             
+             
+; does not work the way it should.
+;(defun empty-line-p ()
+;  "Checks if the current line is empty."
+;  (save-excursion
+;    (beginning-of-line)
+;    (looking-at "[ \t]*$")))
+
+(defun indent-selection-rigidly-by (n)
+  (let ((start (point))
+       (end   (mark) ))
+    (indent-rigidly (min start end) (max start end) n) ; min and max are indeed needed here.
+    ;"preserves the shape" of the affected region, moving it as a rigid unit
+))
+
+(defun indent-selection-rigidly ()
+  ""
+  (interactive)
+  (indent-selection-rigidly-by 1))
+
+(defun dedent-selection-rigidly ()
+  ""
+  (interactive)
+  (indent-selection-rigidly-by -1))
+
+
+
+
+
+
+;;;(make-regexp '("If" "While" "Print" "Module" "With" "Block" "Switch" 
+;;;              "Return""Begin" "End" "BeginPackage" "EndPackage"
+;;;              "Which" "Do" "For" "Throw" "Catch" "Check" "Break" 
+;;;              "Continue" "Goto" "Label" "Abort" "Message"))
+;;;;;;;;
+
+;;;(make-regexp '("If" "While")) "Print" "Module" "With" "Block" "Switch" 
+;;;              "Return""Begin" "End" "BeginPackage" "EndPackage"
+;;;              "Which" "Do" "For" "Throw" "Catch" "Check" "Break" 
+;;;              "Continue" "Goto" "Label" "Abort" "Message"))
+;;;;;;;;
+
+
+; built using:
+; ?* (in mathematica) followed by (make-regexp).
+;(defvar mathematica-m-font-lock-keywords-1
+;  (list
+;   '("\\(^[a-zA-Z]\\w*\\)\\([ \t]*=[ \t]*Compile\\|\\[\\([ \t]*\\]\\|.*\\(_\\|:\\)\\)\\)"
+;     1 font-lock-function-name-face)
+;   '("\\<\\(\\$\\(Aborted\\|B\\(atch\\(Input\\|Output\\)\\|yteOrdering\\)\\|C\\(haracterEncoding\\|o\\(mmandLine\\|ntext\\(Path\\)?\\)\\|reationDate\\|urrentLink\\)\\|Display\\(Function\\)?\\|E\\(cho\\|pilog\\|xportFormats\\)\\|F\\(ailed\\|ormatType\\|rontEnd\\)\\|H\\(istoryLength\\|omeDirectory\\)\\|I\\(gnoreEOF\\|mportFormats\\|n\\(itialDirectory\\|put\\|s\\(pector\\|tallationDate\\)\\)\\|terationLimit\\)\\|L\\(a\\(nguage\\|unchDirectory\\)\\|in\\(e\\|ked\\)\\)\\|M\\(a\\(chine\\(Domain\\|Epsilon\\|ID\\|Name\\|Precision\\|Type\\)\\|x\\(ExtraPrecision\\|MachineNumber\\|Number\\|Precision\\)\\)\\|essage\\(List\\|PrePrint\\|s\\)\\|in\\(MachineNumber\\|Number\\|Precision\\)\\|oduleNumber\\)\\|N\\(ew\\(Message\\|Symbol\\)\\|otebooks\\|umberMarks\\)\\|O\\(peratingSystem\\|utput\\)\\|P\\(a\\(ckages\\|rent\\(Link\\|ProcessID\\)\\|th\\)\\|ost\\|r\\(e\\(Print\\|Read\\)?\\|ocess\\(ID\\|orType\\)\\)\\)\\|R\\(andomState\\|e\\(cursionLimit\\|leaseNumber\\)\\)\\|S\\(essionID\\|oundDisplayFunction\\|y\\(ntaxHandler\\|stem\\(CharacterEncoding\\|ID\\)?\\)\\)\\|T\\(extStyle\\|imeUnit\\|opDirectory\\)\\|U\\(rgent\\|serName\\)\\|Version\\(Number\\)?\\)\\|A\\(b\\(ort\\(Protect\\)?\\|s\\(olute\\(Dashing\\|Options\\|PointSize\\|T\\(hickness\\|ime\\)\\)\\)?\\)\\|c\\(c\\(ountingForm\\|uracy\\(Goal\\)?\\)\\|tive\\)\\|d\\(dTo\\|justmentBox\\)\\|iry\\(Ai\\(Prime\\)?\\|Bi\\(Prime\\)?\\)\\|l\\(gebraics\\|l\\|ternatives\\)\\|mbientLight\\|n\\(choredSearch\\|d\\|imationDi\\(rection\\|splayTime\\)\\)\\|p\\(art\\|p\\(e\\(llF1\\|nd\\(To\\)?\\)\\|ly\\)\\)\\|r\\(c\\(C\\(o\\(sh\\|th\\|[st]\\)\\|sch?\\)\\|S\\(ech?\\|inh?\\)\\|Tanh?\\)\\|g\\|ithmeticGeometricMean\\|ray\\)\\|s\\(pectRatio\\(Fixed\\)?\\|sumptions\\)\\|t\\(omQ\\|tributes\\)\\|uto\\(I\\(ndent\\|talicWords\\)\\|Spacing\\|matic\\)\\|xes\\(Edge\\|Label\\|Origin\\|Style\\)?\\)\\|B\\(a\\(ckground\\|seForm\\)\\|e\\(gin\\(Package\\)?\\|rnoulliB\\|ssel[IJKY]\\|ta\\(Regularized\\)?\\)\\|i\\(nomial\\|t\\(And\\|Not\\|Or\\|Xor\\)\\)\\|l\\(ank\\(NullSequence\\|Sequence\\)?\\|ock\\)\\|o\\(oleans\\|x\\(Ratios\\|Style\\|ed\\)\\)\\|reak\\|utton\\(Box\\|Data\\|E\\(valuator\\|xpandable\\)\\|F\\(rame\\|unction\\)\\|M\\(argins\\|inHeight\\)\\|Note\\(book\\)?\\|S\\(ource\\|tyle\\)\\)\\|yte\\(Count\\)?\\)\\|C\\(Form\\|MYKColor\\|a\\(ncel\\|rmichaelLambda\\|ses\\|t\\(alan\\|ch\\)\\)\\|e\\(iling\\|ll\\(AutoOverwrite\\|Baseline\\|Dingbat\\|E\\(ditDuplicate\\|valuationDuplicate\\)\\|Frame\\(Margins\\)?\\|Group\\(Data\\|ing\\)\\|Label\\(AutoDelete\\)?\\|Margins\\|Open\\|Print\\|Tags\\)?\\)\\|h\\(aracter\\(Encoding\\|Range\\|s\\)?\\|e\\(byshev[TU]\\|ck\\(Abort\\)?\\)\\|op\\)\\|ircle\\|l\\(e\\(ar\\(A\\(ll\\|ttributes\\)\\)?\\|bschGordan\\)\\|ipFill\\|ose\\)\\|o\\(efficient\\(List\\)?\\|l\\(lect\\|or\\(Function\\(Scaling\\)?\\|Output\\)\\|umn\\(Alignments\\|Form\\|Lines\\|Spacings\\|Widths\\|sEqual\\)\\)\\|mp\\(ile\\(d\\(Function\\)?\\)?\\|le\\(ment\\|x\\(Expand\\|Infinity\\|es\\|ityFunction\\)?\\)\\|o\\(s\\(e\\(List\\|Series\\)\\|ition\\)\\|undExpression\\)\\)\\|n\\(dition\\|jugate\\|st\\(ants?\\|rainedM\\(ax\\|in\\)\\)\\|t\\(exts?\\|inue\\(dFraction\\)?\\|our\\(Graphics\\|Lines\\|Plot\\|S\\(hading\\|tyle\\)\\|s\\)\\)\\|versionRules\\)\\|py\\(Directory\\|File\\|able\\)\\|s\\(Integral\\|h\\(Integral\\)?\\)\\|th\\|unt\\|[st]\\)\\|r\\(eateDirectory\\|oss\\)\\|sch?\\|uboid\\|yclotomic\\)\\|D\\(Solve\\|a\\(shing\\|te\\)\\|e\\(c\\(larePackage\\|ompose\\|rement\\)\\|dekindEta\\|f\\(ault\\(Color\\|DuplicateCellStyle\\|NewCellStyle\\)?\\|inition\\)\\|gree\\|l\\(et\\(able\\|e\\(Cases\\|Directory\\|File\\)?\\)\\|imiterFlashTime\\)\\|n\\(ominator\\|sity\\(Graphics\\|Plot\\)\\)\\|pth\\|rivative\\|t\\)\\|i\\(a\\(gonalMatrix\\|log\\(Prolog\\|Symbols\\)?\\)\\|git\\(Block\\|Count\\|Q\\)\\|mensions\\|r\\(acDelta\\|ect\\(edInfinity\\|ory\\(Name\\|Stack\\)?\\)\\)\\|s\\(creteDelta\\|k\\|p\\(atch\\|lay\\(F\\(orm\\|unction\\)\\|String\\)?\\)\\|tribute\\)\\|vi\\(de\\(By\\)?\\|sor\\(Sigma\\|s\\)\\)\\)\\|o\\(t\\|wnValues\\)\\|r\\(agAndDrop\\|op\\)\\|umpSave\\|[ot]\\)\\|E\\(d\\(geForm\\|itable\\)\\|igen\\(system\\|v\\(alues\\|ectors\\)\\)\\|l\\(ement\\|iminate\\|liptic\\(Exp\\|Log\\|NomeQ\\|Pi\\|Theta\\(Prime\\)?\\|[EFK]\\)\\)\\|n\\(code\\|d\\(OfFile\\|Package\\)?\\|gineeringForm\\|vironment\\)\\|pilog\\|qual\\|r\\(f[ci]?\\|rorBox\\)\\|uler\\(E\\|Gamma\\|Phi\\)\\|v\\(aluat\\(able\\|e\\|ionNotebook\\|or\\)\\|enQ\\)\\|x\\(cludedForms\\|it\\|p\\(IntegralEi?\\|ToTrig\\|and\\(All\\|Denominator\\|Numerator\\)?\\|o\\(nent\\(Function\\)?\\|rt\\(String\\)?\\)\\|ression\\)?\\|t\\(en\\(dedGCD\\|sion\\)\\|ract\\)\\)\\)\\|F\\(a\\(c\\(e\\(Form\\|Grids\\)\\|tor\\(Integer\\|List\\|SquareFree\\(List\\)?\\|Terms\\(List\\)?\\|ial2?\\)?\\)\\|lse\\)\\|i\\(bonacci\\|le\\(ByteCount\\|Date\\|Names\\|Type\\)\\|nd\\(List\\|Minimum\\|Root\\)?\\|rst\\|t\\|xedPoint\\(List\\)?\\)\\|l\\(at\\(ten\\(At\\)?\\)?\\|oor\\)\\|o\\(ld\\(List\\)?\\|nt\\(Color\\|Family\\|S\\(ize\\|lant\\|ubstitutions\\)\\|Tracking\\|Weight\\)\\|r\\(m\\(Box\\|at\\(Type\\)?\\)\\|tranForm\\)?\\|urier\\(CosTransform\\|SinTransform\\|Transform\\)?\\)\\|r\\(a\\(ction\\(Box\\|alPart\\)\\|me\\(Box\\|Label\\|Style\\|Ticks\\)?\\)\\|e\\(eQ\\|snel[CS]\\)\\|o\\(m\\(C\\(haracterCode\\|ontinuedFraction\\)\\|D\\(ate\\|igits\\)\\)\\|ntEndExecute\\)\\)\\|u\\(ll\\(Definition\\|Form\\|Graphics\\|Simplify\\)\\|nction\\(Expand\\|Interpolation\\)?\\)\\)\\|G\\(CD\\|a\\(mma\\(Regularized\\)?\\|ussianIntegers\\)\\|e\\(genbauerC\\|nera\\(l\\|te\\(Conditions\\|dCell\\)\\)\\|t\\)\\|laisher\\|o\\(ldenRatio\\|to\\)\\|r\\(a\\(phics\\(3D\\|Array\\|Spacing\\)?\\|yLevel\\)\\|eater\\(Equal\\)?\\|id\\(B\\(aseline\\|ox\\)\\|DefaultElement\\|Lines\\)\\|o\\(ebnerBasis\\|upPageBreakWithin\\)\\)\\)\\|H\\(TMLSave\\|armonicNumber\\|e\\(ads?\\|rmiteH\\)\\|iddenSurface\\|old\\(All\\(Complete\\)?\\|Complete\\|F\\(irst\\|orm\\)\\|Pattern\\|Rest\\)?\\|ue\\|yp\\(ergeometric\\(0F1\\(Regularized\\)?\\|1F1\\(Regularized\\)?\\|2F1\\(Regularized\\)?\\|PFQ\\(Regularized\\)?\\|U\\)\\|henation\\)\\)\\|I\\(dentity\\(Matrix\\)?\\|gnoreCase\\|m\\(age\\(Margins\\|R\\(esolution\\|otated\\)\\|Size\\)\\|p\\(lies\\|ort\\(String\\)?\\)\\)\\|n\\(String\\|crement\\|determinate\\|f\\(i\\(nity\\|x\\)\\|ormation\\)\\|itializationCell\\|ner\\|put\\(A\\(liases\\|utoReplacements\\)\\|Form\\|Notebook\\|Str\\(eam\\|ing\\)\\)?\\|s\\(ert\\|tall\\)\\|te\\(g\\(er\\(Digits\\|Exponent\\|Part\\|[Qs]\\)?\\|rate\\)\\|r\\(p\\(olati\\(ng\\(Function\\|Polynomial\\)\\|on\\)\\|retationBox\\)\\|rupt\\|section\\|val\\(Intersection\\|MemberQ\\|Union\\)?\\)\\)\\|verse\\(BetaRegularized\\|E\\(llipticNomeQ\\|rfc?\\)\\|F\\(ourier\\(CosTransform\\|SinTransform\\|Transform\\)?\\|unctions?\\)\\|GammaRegularized\\|LaplaceTransform\\|Series\\|WeierstrassP\\|ZTransform\\)?\\)\\|[fmn]\\)\\|J\\(acobi\\(Amplitude\\|P\\|Symbol\\|Zeta\\)\\|o\\(in\\|rdanDecomposition\\)\\)\\|K\\(hinchin\\|leinInvariantJ\\|roneckerDelta\\)\\|L\\(CM\\|U\\(BackSubstitution\\|Decomposition\\)\\|a\\(bel\\|guerreL\\|nguageCategory\\|placeTransform\\|st\\|tticeReduce\\)\\|e\\(afCount\\|gendre[PQ]\\|ngth\\|rchPhi\\|ss\\(Equal\\)?\\|tterQ\\|vel\\)\\|i\\(ght\\(Sources\\|ing\\)\\|mit\\(sPositioning\\)?\\|n\\(e\\(Indent\\(MaxFraction\\)?\\|Spacing\\|ar\\(Programming\\|Solve\\)\\)?\\|k\\(C\\(lose\\|onnect\\|reate\\)\\|Interrupt\\|Launch\\|Object\\|P\\(atterns\\|rotocol\\)\\|Read\\(yQ\\)?\\|Write\\|s\\)\\)\\|st\\(Co\\(n\\(tourPlot\\|volve\\)\\|rrelate\\)\\|DensityPlot\\|Interpolation\\|Pl\\(ay\\|ot\\(3D\\)?\\)\\|able\\)?\\)\\|o\\(cked\\|g\\(Gamma\\|Integral\\|icalExpand\\)?\\|werCaseQ\\)\\)\\|M\\(a\\(chineNumberQ\\|gnification\\|ke\\(Boxes\\|Expression\\)\\|ntissaExponent\\|p\\(A\\(ll\\|t\\)\\|Indexed\\|Thread\\)\\|t\\(ch\\(LocalNames\\|Q\\)\\|hieu\\(C\\(Prime\\|haracteristic\\(Exponent\\|[AB]\\)\\)\\|SPrime\\|[CS]\\)\\|rix\\(Exp\\|Form\\|Power\\|Q\\)\\)\\|x\\(Bend\\|MemoryUsed\\)\\|[px]\\)\\|e\\(ijerG\\|m\\(berQ\\|ory\\(Constrained\\|InUse\\)\\)\\|s\\(h\\(Range\\|Style\\)?\\|sage\\(List\\|Name\\|s\\)?\\)\\)\\|in\\(ors\\|us\\)?\\|o\\(d\\(ul\\(arLambda\\|e\\|us\\)\\)?\\|ebiusMu\\)\\|ulti\\(nomial\\|plicativeOrder\\)\\)\\|N\\(DSolve\\|Hold\\(All\\|First\\|Rest\\)\\|Integrate\\|Product\\|S\\(olve\\|um\\)\\|ame[Qs]\\|e\\(eds\\|gative\\|st\\(List\\|While\\(List\\)?\\)?\\)\\|o\\(n\\(Co\\(mmutativeMultiply\\|nstants\\)\\|Negative\\|Positive\\|e\\)\\|rmal\\|t\\(ebook\\(A\\(pply\\|utoSave\\)\\|C\\(lose\\|reate\\)\\|Delete\\|Find\\|Get\\|Locate\\|O\\(bject\\|pen\\)\\|P\\(rint\\|ut\\)\\|Read\\|S\\(ave\\|election\\)\\|Write\\|s\\)?\\)?\\)\\|u\\(ll\\(Records\\|Space\\|Words\\)?\\|m\\(ber\\(Form\\(at\\)?\\|M\\(arks\\|ultiplier\\)\\|P\\(adding\\|oint\\)\\|Q\\|S\\(eparator\\|igns\\)\\)?\\|er\\(ator\\|ic\\(Function\\|Q\\)\\)\\)\\)\\)\\|O\\(ddQ\\|ff\\(set\\)?\\|neIdentity\\|p\\(e\\(n\\(Append\\|Read\\|Temporary\\|Write\\)\\|rate\\)\\|tion\\(al\\|s\\)\\)\\|rder\\(edQ\\|less\\)?\\|ut\\(er\\|put\\(Form\\|Stream\\)\\)?\\|verscriptBox\\|[nr]\\)\\|P\\(a\\(d\\(Left\\|Right\\|dedForm\\)\\|ge\\(Break\\(Above\\|Below\\|Within\\)\\|Width\\)\\|r\\(a\\(graph\\(Indent\\|Spacing\\)\\|metricPlot\\(3D\\)?\\)\\|entDirectory\\|t\\(ition\\(s[PQ]\\)?\\)?\\)\\|t\\(h\\|tern\\(Test\\)?\\)\\|use\\)\\|ermutations\\|i\\|l\\(ay\\(Range\\)?\\|ot\\(3D\\|Division\\|Joined\\|Label\\|Points\\|R\\(ange\\|egion\\)\\|Style\\)?\\|us\\)\\|o\\(chhammer\\|int\\(Size\\)?\\|ly\\(Gamma\\|Log\\|gon\\(Intersections\\)?\\|nomial\\(GCD\\|LCM\\|Mod\\|Q\\(uotient\\)?\\|Re\\(duce\\|mainder\\)\\)\\)\\|s\\(iti\\(on\\|ve\\)\\|t\\(Script\\|fix\\)\\)\\|wer\\(Expand\\|Mod\\)?\\)\\|r\\(e\\(Decrement\\|Increment\\|c\\(edenceForm\\|ision\\(Goal\\)?\\)\\|fix\\|pend\\(To\\)?\\)\\|i\\(me\\(Pi\\|[Qs]\\)?\\|n\\(cipalValue\\|t\\(ingStyleEnvironment\\)?\\)\\)\\|o\\(duct\\(Log\\)?\\|log\\|tect\\(ed\\)?\\)\\)\\|seudoInverse\\|ut\\(Append\\)?\\)\\|Q\\(RDecomposition\\|u\\(it\\|otient\\)\\)\\|R\\(GBColor\\|a\\(dicalBox\\|n\\(dom\\|ge\\)\\|ster\\(Array\\)?\\|tional\\(ize\\|s\\)?\\|w\\)\\|e\\(a\\(d\\(List\\|Protected\\)\\|l\\(Digits\\|s\\)\\|[dl]\\)\\|c\\(ord\\(Lists\\|Separators\\)?\\|tangle\\)\\|duce\\|leaseHold\\|move\\|n\\(ame\\(Directory\\|File\\)\\|derAll\\)\\|p\\(eated\\(Null\\)?\\|lace\\(All\\|List\\|Part\\|Repeated\\)?\\)\\|s\\(etDirectory\\|idue\\|t\\|ultant\\)\\|turn\\|verse\\)?\\|iemannSiegel\\(Theta\\|Z\\)\\|o\\(ot\\(Reduce\\|Sum\\|s\\)?\\|tate\\(L\\(abel\\|eft\\)\\|Right\\)\\|und\\|w\\(Alignments\\|Box\\|Lines\\|MinHeight\\|Reduce\\|Spacings\\|sEqual\\)\\)\\|u\\(le\\(Delayed\\)?\\|n\\(Through\\)?\\)\\)\\|S\\(a\\(m\\(eQ\\|ple\\(Depth\\|Rate\\|dSound\\(Function\\|List\\)\\)\\)\\|ve\\)\\|c\\(a\\(led\\|n\\)\\|hurDecomposition\\|ientificForm\\|r\\(eenStyleEnvironment\\|ipt\\(BaselineShifts\\|MinSize\\|SizeMultipliers\\)\\)\\)\\|e\\(ch\\|edRandom\\|lect\\(able\\|edNotebook\\|ion\\(Animate\\|CreateCell\\|Evaluate\\(CreateCell\\)?\\|Move\\)\\)?\\|quence\\(Form\\|Hold\\)?\\|ries\\(Coefficient\\|Data\\)?\\|ssionTime\\|t\\(A\\(ccuracy\\|ttributes\\)\\|D\\(elayed\\|irectory\\)\\|FileDate\\|Options\\|Precision\\|S\\(electedNotebook\\|treamPosition\\)\\)\\|[ct]\\)\\|h\\(a\\(ding\\|llow\\|re\\)\\|o\\(rt\\|w\\(AutoStyles\\|C\\(ell\\(Bracket\\|Label\\|Tags\\)\\|ursorTracker\\)\\|PageBreaks\\|S\\(election\\|pecialCharacters\\|tringCharacters\\)\\)?\\)\\)\\|i\\(gn\\(Padding\\|ature\\)?\\|mplify\\|n\\(Integral\\|g\\(leLetterItalics\\|ularValues\\)\\|h\\(Integral\\)?\\)?\\|xJSymbol\\)\\|k\\(eleton\\|ip\\)\\|lot\\(Sequence\\)?\\|o\\(lve\\(Always\\)?\\|rt\\|und\\)\\|p\\(ellingCorrection\\|herical\\(HarmonicY\\|Region\\)\\|li\\(ce\\|t\\)\\)\\|qrt\\(Box\\)?\\|t\\(a\\(ck\\(Begin\\|Complete\\|Inhibit\\)?\\|ndardForm\\)\\|i\\(eltjesGamma\\|rlingS[12]\\)\\|r\\(eam\\(Position\\|s\\)\\|ing\\(Drop\\|Form\\|Insert\\|Join\\|Length\\|MatchQ\\|Position\\|Re\\(place\\(Part\\)?\\|verse\\)\\|Skeleton\\|T\\(ake\\|oStream\\)\\)?\\|u\\(cturedSelection\\|ve[HL]\\)\\)\\|ub\\|yle\\(Box\\|Definitions\\|Form\\|Print\\)\\)\\|u\\(b\\(resultants\\|s\\(criptBox\\|uperscriptBox\\)\\|tract\\(From\\)?\\)\\|m\\|perscriptBox\\|rface\\(Color\\|Graphics\\)\\)\\|witch\\|y\\(mbol\\(Name\\)?\\|ntax\\(Length\\|Q\\)\\)\\)\\|T\\(a\\(ble\\(Alignments\\|D\\(epth\\|irections\\)\\|Form\\|Headings\\|Spacing\\)?\\|g\\(Box\\|Set\\(Delayed\\)?\\|Unset\\)\\|ke\\|nh?\\)\\|e\\(X\\(Form\\|Save\\)\\|mporary\\|nsorRank\\|xt\\(Alignment\\|Justification\\|Style\\)?\\)\\|h\\(ickness\\|r\\(e\\(ad\\|eJSymbol\\)\\|o\\(ugh\\|w\\)\\)\\)\\|i\\(cks\\|m\\(e\\(Constrain\\(ed\\|t\\)\\|Used\\|Zone\\|s\\(By\\)?\\)\\|ing\\)\\)\\|o\\(Boxes\\|CharacterCode\\|Date\\|Expression\\|FileName\\|LowerCase\\|R\\(adicals\\|ules\\)\\|String\\|UpperCase\\|gether\\|kenWords\\|talWidth\\)\\|r\\(a\\(ce\\(Above\\|Backward\\|D\\(epth\\|ialog\\)\\|Forward\\|O\\(ff\\|n\\|riginal\\)\\|Print\\|Scan\\)?\\|ditionalForm\\|ns\\(formationFunctions\\|pose\\)\\)\\|eeForm\\|ig\\(Expand\\|Factor\\(List\\)?\\|Reduce\\|ToExp\\)\\|ueQ?\\)?\\)\\|U\\(n\\(der\\(overscriptBox\\|scriptBox\\)\\|e\\(qual\\|valuated\\)\\|i\\(nstall\\|on\\|que\\|tStep\\)\\|protect\\|s\\(ameQ\\|et\\)\\)\\|p\\(Set\\(Delayed\\)?\\|Values\\|date\\|perCaseQ\\)\\)\\|V\\(a\\(lueQ\\|riables\\)\\|e\\(ctorQ\\|rbatim\\)\\|i\\(ew\\(Center\\|Point\\|Vertical\\)\\|sible\\)\\)\\|W\\(eierstrass\\(HalfPeriods\\|Invariants\\|P\\(Prime\\)?\\|Sigma\\|Zeta\\)\\|hi\\(ch\\|le\\)\\|i\\(ndow\\(ClickSelect\\|Elements\\|F\\(loating\\|rame\\)\\|M\\(argins\\|ovable\\)\\|Size\\|T\\(itle\\|oolbars\\)\\)\\|th\\)\\|or\\(d\\(Se\\(arch\\|parators\\)\\)?\\|kingPrecision\\)\\|rite\\(String\\)?\\)\\|Xor\\|Z\\(Transform\\|eta\\)\\|[CDEINO]\\)\\>" 1 font-lock-keyword-face)
+;   '("\\<\\(Abort\\|B\\(egin\\(\\|Package\\)\\|lock\\|reak\\)\\|C\\(atch\\|heck\\|ontinue\\)\\|Do\\|End\\(\\|Package\\)\\|For\\|Goto\\|If\\|Label\\|M\\(essage\\|odule\\)\\|Print\\|Return\\|Switch\\|Throw\\|W\\(hi\\(ch\\|le\\)\\|ith\\)\\)\\>" 1 font-lock-keyword-face)
+   ;; a missing `;' in Mathematica code may cause magic effects. So 
+   ;; highlight it:
+;   '("\\(;\\)" 1 font-lock-keyword-face))
+;  "Subdued level highlighting for mathematica-m mode.")
+
+(defvar mathematica-m-font-lock-keywords-1
+  (list
+   '("\\(^[a-zA-Z]\\w*\\)\\([ \t]*=[ \t]*Compile\\|\\[\\([ \t]*\\]\\|.*\\(_\\|:\\)\\)\\)"
+     1 font-lock-function-name-face)
+;; and no keywords.
+   ))
+
+(defvar mathematica-m-font-lock-keywords-2
+  (append
+   mathematica-m-font-lock-keywords-1
+   '(
+     ("\\(\\(-\\|:\\)>\\|//[.@]?\\|/[.@;:]\\|@@\\|#\\(#\\|[0-9]*\\)\\|&\\)" 1 font-lock-keyword-face append)
+     ("([*]:[a-zA-Z-]*:[*])" 0 font-lock-keyword-face t) 
+;;; This pattern is just for internal use...
+;;;     ("([*]\\(:FILE-ID:\\).*:[*])" 1 font-lock-keyword-face t)
+     ("\\(!=\\|=\\(!=\\|==?\\)\\)" 1 font-lock-reference-face)))
+   "Gaudy level highlighting for mathematica-m mode.")
+
+(defvar mathematica-m-font-lock-keywords mathematica-m-font-lock-keywords-1
+  "Default expressions to highlight in mathematica-m mode.")
+
+
+
+;;;; - mathematica-m-mode
+(defun mathematica-m-mode ()
+  "Mathematica-Mode.
+Programming mode for writing Mathematica package files.
+Turning on mathematica-m-mode runs the hook `mathematica-m-mode-hook'.
+\\{mathematica-m-mode-map}"
+  (interactive)
+  ; kill all (non-permanent) buffer-local variables.
+  (kill-all-local-variables)
+  (use-local-map mathematica-m-mode-map)
+  (setq mode-name "mathematica-m")
+  (setq major-mode 'mathematica-m-mode)
+
+  (set-syntax-table mathematica-m-mode-syntax-table)
+
+  ; don't split the frame unless it is already split.
+  ; use C-x 2 or C-x 3 to split the frame.
+  (set (make-local-variable 'pop-up-windows) nil)
+
+  ; i don't understand the following six lines
+  (set (make-local-variable 'paragraph-start) (concat "$\\|" page-delimiter))
+  (set (make-local-variable 'paragraph-separate) paragraph-start)
+  (set (make-local-variable 'comment-start) "(* ")
+  (set (make-local-variable 'comment-end) " *)")
+  (set (make-local-variable 'comment-start-skip) "(\\*+ *")
+  (set (make-local-variable 'comment-column) 48)
+
+  (setq indent-tabs-mode nil) ; use space, not tab.
+  (setq tab-width 2)
+
+
+  ;; how to indent:
+  (make-local-variable 'indent-line-function)
+  (setq indent-line-function 'indent-relative-maybe)
+
+;  (make-local-variable 'indent-region-function)
+;  (setq indent-region-function 'mathematica-indent-region)
+
+  ;; dabbrev configuration:
+  ;; case matters in mathematica. tell dabbrev about this.
+  (set (make-local-variable 'dabbrev-case-fold-search) nil)
+  (set (make-local-variable 'dabbrev-case-replace)     nil)
+  ;; look in other mathematica-m-mode buffers for completions, too.
+  (set (make-local-variable 'dabbrev-friend-buffer-function)
+      (lambda (buffer)
+         (save-excursion
+           (set-buffer buffer)
+           (memq major-mode '(mathematica-m-mode)))))
+
+
+  ;; parse-sexp-ignore-comments should be set to nil. Otherwise matching
+  ;; paren highlighting does not work properly.
+  (set (make-local-variable 'parse-sexp-ignore-comments) nil)
+;  (set (make-local-variable 'indent-line-function) 'mathematica-m-indent-line)
+
+  (make-local-variable 'font-lock-defaults)
+  (setq font-lock-defaults
+       '((mathematica-m-font-lock-keywords
+          mathematica-m-font-lock-keywords-1
+          mathematica-m-font-lock-keywords-2)
+         nil nil ((?_ . "w")) beginning-of-defun
+         (font-lock-comment-start-regexp . "^([*]\\|[ \t]([*]")))
+
+  ;; if on Emacs, initialize imenu index creation function
+  (run-hooks 'mathematica-m-mode-hook)
+  ;(message "(run-hooks 'mathematica-m-mode-hook)")
+
+  (show-paren-mode)           ; show matching parentheses in color.
+  ; it seems, that it doesn't work for me: I have to call it interactively. 
+  (setq debug-flag 1)
+)
+
+; add 'mathematica-m to the global variable features.
+;(provide 'mathematica-m)
+
+
+
+
+
+;; Purpose:
+;;
+;; To send a buffer to another buffer running Mathematica.
+;;
+;; Installation:
+;;
+;; add this to .emacs:
+;;
+;;    (add-hook mathematica-comint-mode-hook 'turn-on-mathematica)
+;;
+;; Customisation:
+;;       The name of the mathematica interpreter is in variable
+;;          mathematica-comint-program-name
+;;       Arguments can be sent to the Mathematica interpreter when it is called
+;;       by setting the value of the variable
+;;          mathematica-comint-program-args
+;;
+;;       If the command does not seem to respond, see the
+;;          content of the `comint-prompt-regexp' variable
+;;          to check that it waits for the appropriate Mathematica prompt
+;;          the current value is appropriate for Mathematica 1.0 - 4.2
+;;
+;;    `mathematica-comint-hook' is invoked in the *mathematica* once it is started.
+;;    
+;;; All functions/variables start with
+;;; `(turn-(on/off)-)mathematica' or `mathematica-comint-'.
+
+(defgroup mathematica nil
+  "Major mode for interacting with an inferior Mathematica session."
+  :group 'mathematica
+  :prefix "mathematica-comint-")
+
+
+; makes the current buffer a mathematica mode buffer.
+; do i lose any comint defaults by this?
+(defun mathematica-comint-mode ()
+  "Major mode for interacting with an inferior Mathematica session.
+
+
+\\<mathematica-comint-mode-map>
+Commands:
+Return at end of buffer sends line as input.
+Return not at end copies rest of line to end and sends it.
+\\[mathematica-comint-find-error] jumps to the error line in the corresponding *.m file,
+\\[switch-to-mathematica-m] switches to  the corresponding *.m file,
+\\[dabbrev-expand] expands a word,
+\\[comint-interrupt-subjob] interrups Mathematica,
+\\[comint-quit-subjob] sends Mathematica the QUIT signal,
+\\[comint-kill-input] and \\[backward-kill-word] are kill commands,
+imitating normal Unix input editing.
+\\[comint-interrupt-subjob] interrupts the comint or its current
+subjob if any.
+\\[comint-stop-subjob] stops, likewise.
+ \\[comint-quit-subjob] sends quit signal."
+  (interactive)
+  (comint-mode)
+  (setq major-mode 'mathematica-comint-mode)
+  (setq mode-name "Mathematica")
+
+;;   (if mathematica-comint-mode-map
+;;       nil
+;;     (setq mathematica-comint-mode-map (copy-keymap comint-mode-map))
+;;     )
+  (setq mathematica-comint-mode-map (copy-keymap comint-mode-map))
+  (define-key mathematica-comint-mode-map [f2] 'mathematica-comint-find-error)
+  (define-key mathematica-comint-mode-map [C-tab] 'switch-to-mathematica-m)
+  (define-key mathematica-comint-mode-map [pause] 'comint-interrupt-subjob)
+  (define-key mathematica-comint-mode-map [C-pause] 'comint-quit-subjob)
+  (define-key mathematica-comint-mode-map [tab] 'dabbrev-expand)
+  (use-local-map mathematica-comint-mode-map)
+
+  ; don't split the frame unless it is already split.
+  ; use C-x 2 or C-x 3 to split the frame.
+  (set (make-local-variable 'pop-up-windows) nil)
+
+  ;; case matters in mathematica. tell dabbrev about this.
+  (set (make-local-variable 'dabbrev-case-fold-search) nil)
+  (set (make-local-variable 'dabbrev-case-replace)     nil)
+  ;; look in the associated mathematica-m-mode buffer for completions, too.
+  (set (make-local-variable 'dabbrev-friend-buffer-function)
+      (lambda (buffer) (eq buffer mathematica-comint-last-buffer)))
+
+  ; experimental: reuse mathematica-m-mode syntax highlighting here.
+  (set-syntax-table mathematica-m-mode-syntax-table)
+  (set (make-local-variable 'paragraph-start) (concat "$\\|" page-delimiter))
+  (set (make-local-variable 'paragraph-separate) paragraph-start)
+  (set (make-local-variable 'comment-start) "(* ")
+  (set (make-local-variable 'comment-end) " *)")
+  (set (make-local-variable 'comment-start-skip) "(\\*+ *")
+  (set (make-local-variable 'comment-column) 48)
+  (make-local-variable 'font-lock-defaults)
+  (setq font-lock-defaults
+       '((mathematica-m-font-lock-keywords
+          mathematica-m-font-lock-keywords-1
+          mathematica-m-font-lock-keywords-2)
+         nil nil ((?_ . "w")) beginning-of-defun
+         (font-lock-comment-start-regexp . "^([*]\\|[ \t]([*]")))
+  ; /experimental: reuse mathematica-m-mode syntax highlighting here.
+
+
+  )
+
+;; Mathematica-interface
+
+(require 'comint)
+; not needed?:
+;(require 'shell)
+
+; I doubt: "...corresponding to current buffer.";
+;    it seems to have the same value in any buffer.
+;
+(defvar mathematica-comint-process nil
+  "The active Mathematica subprocess corresponding to current buffer.")
+
+(defvar mathematica-comint-process-buffer nil
+  "*Buffer used for communication with Mathematica subprocess for current buffer.")
+
+; not needed?
+(defvar mathematica-comint-last-loaded-file nil
+  "The last file loaded into the Mathematica process.")
+
+; !!! has to be configured by the user !!!
+(defcustom mathematica-comint-program-name "math"
+  "*The name of the command to start the Mathematica interpreter."
+  :type 'string
+  :group 'mathematica)
+
+(defcustom mathematica-comint-program-args '("")
+  "*A list of string args to send to the mathematica process."
+  :type '(repeat string)
+  :group 'mathematica)
+
+;(defvar mathematica-comint-load-end nil
+;  "Position of the end of the last load command.")
+
+;(defvar mathematica-comint-send-end nil
+;  "Position of the end of the last send command.")
+
+(defun mathematica-comint-load ()
+  ""
+  (interactive)
+  
+  ; save the current buffer.
+  ; load its contents into mathematica.
+  (save-excursion (mathematica-comint-execute-get))  
+
+  ; (set-buffer mathematica-comint-process-buffer) + making it visible:
+  (pop-to-buffer mathematica-comint-process-buffer)
+
+  ; (mathematica-comint-wait-for-output)
+)
+
+; bad: moves the point.
+(defun mathematica-comint-wait-for-output ()
+  "Wait until output arrives and go to the last input."
+  (while (progn        
+           (sleep-for 0 200) ; 200 milliseconds
+           (message "waiting for the prompt.")         
+          (goto-char comint-last-input-end)
+          (not (re-search-forward comint-prompt-regexp nil t)))
+    (accept-process-output mathematica-comint-process)))
+
+;(defun comint-kill-subjob ()
+
+; may be called when mathematica is already running.
+; may be called even several times in a row; this does not matter.
+(defun mathematica-comint-start-process ()
+  "Start a Mathematica process and invokes `mathematica-comint-hook' if not nil.
+Prompts for a list of args if called with an argument."
+  (interactive "P")
+  (message "Starting `mathematica-comint-process' %s" mathematica-comint-program-name)
+  (setq mathematica-comint-process-buffer
+  ; "mathematica" means: buffername becomes *mathematica*
+    (make-comint "mathematica" mathematica-comint-program-name))
+  (setq mathematica-comint-process
+        (get-buffer-process mathematica-comint-process-buffer))
+  ;; Select Mathematica buffer temporarily
+  ; was:(set-buffer mathematica-comint-process-buffer)
+  ; is:
+  ; (set-buffer mathematica-comint-process-buffer) + making it visible:
+  ; This function makes buffer-or-name the current buffer and switches to it in some window, 
+  ; preferably not the window previously selected. The "popped-to" window becomes the selected 
+  ; window within its frame. 
+  (pop-to-buffer mathematica-comint-process-buffer)
+  ; reason: to make (window-width), for Mathematicas PageWidth option, work.
+
+  ;; Set the keymap (and the modename):
+  (mathematica-comint-mode)
+;  (setq comint-prompt-regexp  "^\? \\|^[A-Z][_a-zA-Z0-9]*> ")
+  (setq comint-prompt-regexp  "^In\[[0-9]+\]:= ")
+    ;; comint's history syntax conflicts with Mathematica syntax, eg. !!
+;  (setq comint-input-autoexpand nil)
+  (run-hooks 'mathematica-comint-hook)
+  (message "mathematica-comint-start-process terminated.")
+;  (message "")
+  )
+
+; (save-excursion (mathematica-comint-execute-get))
+; Get[...]; main[]; 
+(defun mathematica-comint-execute-get ();(load-command cd)
+  "Save the current buffer and load its file into the Mathematica process."
+  (let (file)
+    ;?
+    ;(hack-local-variables);; In case they've changed
+    (save-buffer)
+    (setq file (buffer-file-name))
+
+    ; remember this in order to jump back to it, eg after an error.
+    ; (we cannot read off the filename from the error message, due to //Short in the message)
+    (setq mathematica-comint-last-file (buffer-file-name))
+    (setq mathematica-comint-last-buffer (current-buffer))
+
+    ; make sure the process is there.
+    ; why not simply call mathematica-comint-start-process in any case?
+    (mathematica-comint-start-process)
+
+;;     (if (and mathematica-comint-process-buffer
+;;              (eq (process-status mathematica-comint-process) 'run))
+;;       ;; Ensure the Mathematica buffer is selected.
+;;     (set-buffer mathematica-comint-process-buffer)
+;;         ;; Start Mathematica process.
+;;         (mathematica-comint-start-process)) 
+
+    ;; why?:
+    ;; Wait until output arrives and go to the last input.
+;    (mathematica-comint-wait-for-output)
+
+; Here's a workaround for the problem with // Short:
+;SetOptions[$Output, PageWidth-> Infinity];Block[{Short=Identity},Get["c:/Documents and Settings/burki/My Documents/systems/Mathematica/BurkisMathematicaToolsAdditions_Backup1.m"]];SetOptions[$Output, PageWidth-> 78];
+
+    (mathematica-comint-send 
+     (format "SetOptions[$Output, PageWidth-> Infinity]; Block[{Short=Identity},Get[\"%s\"]]; SetOptions[$Output, PageWidth-> %d];" (mathematica-comint-quote-filename file) (- (window-width) 1)))
+; the necessity for -1 was found by experimentation.
+; trouble: it takes the window-width of the *.m buffer, not of the *mathematica* comint buffer.
+
+;; if the user wants to execute main[] indeed, then he can add such a call to his source file.
+;    (mathematica-comint-send "main[];")
+    
+    
+    ;; Wait until output arrives and go to the last input.
+;    (mathematica-comint-wait-for-output)
+  )
+)
+
+
+(defun mathematica-comint-send (&rest string)
+  "Send `mathematica-comint-process' the arguments (one or more strings).
+A newline is sent after the strings and they are inserted into the
+current buffer after the last output."
+;  (mathematica-comint-wait-for-output)
+  (accept-process-output mathematica-comint-process 0 100)
+  (goto-char (point-max))              
+  (apply 'insert string)
+  (comint-send-input)
+  (goto-char (point-max))
+)
+
+
+
+; (marker-insertion-type comint-last-input-end)
+; to do, not implemented yet.
+; to do: find the name of elisp's string-quoting function.
+(defun mathematica-comint-quote-filename (filename)
+  "quote special characters in filenames."
+  filename)
+
+;(mathematica-comint-quote-filename "")
+;(mathematica-comint-quote-filename "My Documents\\mathematica.hs")
+
+
+; (mathematica-comint-show-errors)
+(defun mathematica-comint-find-error ()
+  "If there is an error, set the cursor at the 
+error line, otherwise show the Mathematica buffer."
+  (interactive)
+  (set-buffer mathematica-comint-process-buffer)
+  (goto-char comint-last-input-start)
+  (if (re-search-forward
+       ; eg: Syntax::sntx: Syntax error in or before "SetAttributes[BatchResult, HoldAllComplete[; ". 
+       ; eg: (line 1 of "c:/examples/test.m")
+       "^\\(.*\\)(line \\([0-9]+\\) of \"\\(.*\\)\")" nil t)
+      (let ( ; Unfortunately, Mathematica applies //Short to the filename.
+             ; so efile is often nonsense like
+             ; "c:/Documents and Settin<<42>>rki/mathematica.el"
+            (efile (buffer-substring (match-beginning 3)         
+                                    (match-end 3)))
+            (eline (string-to-int (buffer-substring (match-beginning 2)
+                                    (match-end 2))))
+           (emesg (buffer-substring (match-beginning 1)         
+                                    (match-end 1)))
+           )
+
+        ; is this a kind of clean-up?
+        ;(pop-to-buffer  mathematica-comint-process-buffer) 
+        (goto-char (point-max))
+        ;(recenter)
+
+       (message "%s, line %d: %s" (file-name-nondirectory efile) eline emesg)
+       ;(message "%s" emesg)
+
+        ; jump to the error.
+
+        ; this is a reasonable guess, but not necessary the right file:
+       (set-buffer mathematica-comint-last-buffer)
+       (pop-to-buffer mathematica-comint-last-buffer)
+        (goto-line eline)
+
+        ; maybe that would be better in case of several files.
+        ; difficulty: to resolve efile in the same way as Matheamtica does. 
+        ; we should call Mathematica for doing the resolving.
+;         (if (file-exists-p efile)
+;             (progn (find-file-other-window efile)
+;                    (if eline (goto-line eline))
+;                    (recenter)))
+
+
+        ) ; let
+
+; else 
+    (progn
+     ;(pop-to-buffer  mathematica-comint-process-buffer) ; show *mathematica* buffer
+     (goto-char (point-max))
+;     (message "There were no errors.")
+     ; even if there were no errors, we switch back to the source code.
+     (pop-to-buffer mathematica-comint-last-buffer)
+     ;(recenter 2)                        ; show only the end...
+    )
+))
+
+;; ; (mathematica-comint-show-mathematica-buffer)
+;; (defun mathematica-comint-show-mathematica-buffer ()
+;;   "Goes to the Mathematica buffer."
+;;   (interactive)
+;;   (if (or (not mathematica-comint-process-buffer)
+;;           (not (buffer-live-p mathematica-comint-process-buffer)))
+;;       (mathematica-comint-start-process))
+;;   (pop-to-buffer  mathematica-comint-process-buffer)
+;;   )
+