how to make maxima-mode start imaxima



Tamas Papp <tkpapp at gmail.com> writes:

> On Fri, 30 Mar 2012 16:15:37 +0000, Leo Butler wrote:
>
>> Tamas Papp <tkpapp at gmail.com> writes:
>> 
>>> Hi,
>>>
>>> I am trying to figure out how to make maxima-mode start imaxima when
>>> something is sent to maxima but there is no maxima buffer yet.  I found
>>> this in the archives:
>>>
>>> http://article.gmane.org/gmane.comp.mathematics.maxima.general/32916
>>>
>>> but could not get it working (it breaks the interaction with the maxima
>>> buffer).  Are there any other possibilities?
>> 
>> Advising maxima-send-region seems the most sensible way to do this, for
>> the reasons explained in that message.
>> 
>> Could you explain what you mean by 'it breaks the interaction with the
>> maxima buffer'? In fact, could you back up and explain what you have
>> done to produce what results, please.
>
> Sorry, I should have done that originally.
>

No worries. Try this:

(defadvice maxima-send-region (before maxima-start-imaxima first)
  "Ensures that imaxima is running and the correct flag is set."
  (setq imaxima-use-maxima-mode-flag t)
  (unless (get-buffer maxima-buffer-name)
    (with-temp-buffer (imaxima))))
(ad-activate 'maxima-send-region)

> I can reproduce the bug like this: I open a Maxima source file, type the
> equations
>
> eq1: 1+a=2;
> eq2: a+b=c;
>
> then start pressing C-c C-c on each.  I get
>
> (%i1) block(load(("/usr/share/emacs-snapshot/site-lisp/maxima/imaxima.lisp")), linenum:0)$
> Maxima 5.2;
>
> (%i1) incorrect syntax: 5.2000000000000002 is not an infix operator
> MaximaSpace5.2;
>          ^
> (%i2) .0 http://m;
> incorrect syntax: HTTP is not an infix operator
> .0Spacehttp:
>       ^
>
> in the imaxima buffer.  Otherwise, it is an imaxima buffer that works
> correctly when typed into directly.

I can't reproduce this exactly. When I use the advice without wrapping
the call to imaxima in a with-temp-buffer macro, I get an 'args out of
range' error--presumably because emacs is in the *maxima* buffer when
the call to maxima-send-region is called. By wrapping the call to
imaxima in a with-temp-buffer macro, I ensure that maxima-send-region is
called in the source buffer.

I am not sure if this will fix all your problems, though. To me, it
looks like comint mode is messing up input and output.

>
> I have the following maxima-related configuration:
>
> (autoload 'maxima-mode "maxima" "Maxima mode" t)
> (autoload 'maxima "maxima" "Maxima interaction" t)
> (setq auto-mode-alist (cons '("\\.max" . maxima-mode) auto-mode-alist))
> (autoload 'imaxima "imaxima" "Frontend for maxima with Image support" t)
> (autoload 'imath-mode "imath" "Imath mode for math formula input" t)
> (setq imaxima-use-maxima-mode-flag t
>       imaxima-fnt-size "LARGE"
>       imaxima-latex-preamble "\\usepackage{concrete}\\usepackage{euler}")
>
> (defadvice maxima-send-region (before maxima-start-imaxima first)
>   "Ensures that imaxima is running and the correct flag is set."
>   (setq imaxima-use-maxima-mode-flag t)
>   (imaxima))
>
> (ad-activate 'maxima-send-region)
>
> (defun customize-maxima-mode ()
>   (interactive)
>   (setq imaxima-use-maxima-mode-flag t)
>   (local-set-key (kbd "C-c C-i") 'maxima-complete))
>
> (add-hook 'maxima-mode-hook 'customize-maxima-mode)
>
> (defun customize-imaxima ()
>   (interactive)
>   (local-set-key (kbd "TAB") 'maxima-complete))
>
> (add-hook 'imaxima-startup-hook 'customize-imaxima)
>
> Versions:
>
> $ dpkg -l 'maxima*'
> Desired=Unknown/Install/Remove/Purge/Hold
> | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
> |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
> ||/ Name                              Version                           Description
> +++-=================================-=================================-==================================================================================
> ii  maxima                            5.26.0-3                          Computer algebra system -- base system
> ii  maxima-doc                        5.26.0-3                          Computer algebra system -- documentation
> ii  maxima-emacs                      5.26.0-3                          Computer algebra system -- emacs interface
> ii  maxima-share                      5.26.0-3                          Computer algebra system -- extra code
> ii  maxima-src                        5.26.0-3                          Computer algebra system -- source code
> $ dpkg -l 'emacs-snapshot*'
> Desired=Unknown/Install/Remove/Purge/Hold
> | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
> |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
> ||/ Name                              Version                           Description
> +++-=================================-=================================-==================================================================================
> ii  emacs-snapshot                    2:20120326-1                      The GNU Emacs editor (development snapshot)
> ii  emacs-snapshot-bin-common         2:20120326-1                      The GNU Emacs editor's shared, architecture dependent files
> ii  emacs-snapshot-common             2:20120326-1                      The GNU Emacs editor's common infrastructure
> ii  emacs-snapshot-el                 2:20120326-1                      GNU Emacs LISP (.el) files
>
> Best,
>
> Tamas
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>

-- 
Leo Butler                <l_butler at users.sourceforge.net>
SDF Public Access UNIX System -   http://sdf.lonestar.org