I did that too, yet it’s still not working –
Syntax Highlighting for Maxima executable folds and plugin sessions
That works for me. I don’t have another codes related to maxima in my init file besides
(define (in-prog-maxima?)
(and (in-maxima?) (in-prog?)))
(tm-define (notify-cursor-moved status)
(:require prog-highlight-brackets?)
(:mode in-prog-maxima?)
(select-brackets-after-movement "([{" ")]}" "\\"))
I had a keyboard short cut for inserting a maxima session in my init
file which I commented out. I also unticked Framed input fields
in Preferences for tag
. But I’m afraid your code still doesn’t work for me. Could it be that this is a system specific issue?
I’m running Maxima 5.45.1 using Lisp SBCL 2.2.5 compiled by MacPorts on macOS 13.6/15.7. in TeXmacs 2.1.2 as of 2022/05/05 with some minor modifications made to the maxima plugin in texmacs-maxima.lisp
that should have no effect on the behavior of input fields.
Session format style has nothing to do with maxima runtime. I guess there’s something wrong in your texmacs-maxima.lisp
.
After placing the definition of in-prog-maxima?
in init file, you can insert a maxima session, and press M-x
(prefix M
is meta key, perhaps Cmd
for apple’s laptop). Then you can see an input box near the bottom of TeXmacs window (if no effect, try other keys as meta key). Now type (in-prog-maxima?)
, if the definition is respected and you are truly in a legitimate maxima session a t
will be returned. Note: you need to confirm your cursor lies in a maxima session before you press M-x
.
BTW, legitimate scheme file should have extension name .scm
.
To make sure that I use the maxima plugin that ships with TeXmacs 2.1.2 and a clean texmacs-maxima.lisp
, I removed all files from .TeXmacs/plugin/maxima
– and there was still no bracket matching.
I did so, however neither M-x
nor A-x
nor C-x
opened an input box at the place you mentioned.
This is all a bit frustrating. But anyway thanks for your help and efforts.
Cheers,
Tilda
That is “Evaluate Scheme expression” under Debug->Execute in the menu. First you have to activate the Debugging tool, which you do through the Tools menu.
With @pireddag’s help I managed to run "Evaluate Scheme expression"
on (in-prog-maxima?)
to get the following result:
(unbound-variable #f "Unbound variable: ~S" (in-prog-maxima?) #f)
The great scheme expert that I am, I’m not quite sure how to read this.
-
(in-prog-maxima?) #f)
obviously means that the definition in theinit
-file is not respected and I’m not truly in a legitimate maxima session. -
Why? and how can I make it accepted?
-
What is a legitimate maxima session? – I’ve been able to run Maxima and do calculations and programming even though I’ve been in an “illegitimate” session all these years.
-
What does
(unbound-variable #f
and"Unbound variable: ~S"
signify?
I do not know how to interpret the details of those error messages, nevertheless it is possible that the functions you think are defined are not. One possible cause of this (admitting that it is happening ) is that your init file has some error before the point where you define those functions.
As a workaround for testing, you can open a Scheme session inside TeXmacs and evaluate the functions there. I did it and I obtained bracket matching. If that happens for you too, then one should debug the whole of the init file (it is not as bad as it seems).
After I’ve put the definition of those functions at the very beginning my my-texmacs-init.scm
I also get bracket/brace matching. Hurray, hurray, hurray!
So, it seems there’s some kind of nasty code in my init
-file. You suggested debugging the entire file. How exactly do you do this? Is there a scheme debugger?
I pasted the entire init
-file into a scheme session, evaluated it – and nothing happened .
IMHO you have to evaluate function after function in a Scheme session. I do not know anything about Guile’s debugger (I used a few times Mit Scheme’s debugger—in an elementary way) but
- You want to debug Guile 1.8 and so you would have to install it separately from the Guile that is in the repositories of your Ubuntu
- You need TeXmacs Scheme functions
Maybe there is a way to debug with a debugger, but I don’t know it.
That sounds like hard, grinding work . . .
I’m on macOS. MacPorts offer guile v1.8.8 (https://ports.macports.org/port/guile18/). Is this the version implemented in TeXmacs? I could not figure out if a debugger is included in this port. Maybe @mgubi or @darcy would know.
How many functions do you have? You don’t have to figure out if the output of each function in your init file is correct, but only that they can each be defined; at least for one of them the definition results in an error, and we want to figure out for which one.
For some reason the Scheme session evaluates only the first command given. If there are multiple you can put them in a (begin ...)
block.
Simply run texmacs
from a terminal (if dir of which is system search path), then texmacs will tell you when it meet errors during execution of your init file.
If nothing gets printed in your terminal after running /Applications/TeXmacs.app
, you can find the true path of texmacs under /Applications/TeXmacs.app
, which should look like:
$ ls /usr/share/TeXmacs/
COPYING examples INSTALL LICENSE packages progs styles TEX_FONTS
doc fonts langs misc plugins README SVNREV texts
I don’t quite remember the directory structure of the mac version, but they should be similar. Under above path you can ultimately find somewhere a binary called texmacs
(it can also live in somewhere like /usr/local/bin
, find it anyway). Then run:
TEXMACS_PATH=/path/to/true/texmacs/path /path/to/texmacs/binary
Now stdio should behave like a normal terminal program.
Thanks for the information @sharkc. Running the following in a terminal (bash-shell)
TEXMACS_PATH=/Applications/TeXmacs.app/Contents/MacOS/TeXmacs /Applications/TeXmacs.app/Contents/MacOS/TeXmacs
resulted in this error message and a little later TeXmacs crashed:
TeXmacs] std-warning, Could not find TeXmacs icon file: /Applications/TeXmacs.app/Contents/MacOS/TeXmacs/misc/images/texmacs-512.png
TeXmacs]
TeXmacs] Installation problem: please send a bug report.
TeXmacs] The initialization file init-texmacs.scm could not be found.
TeXmacs] Please check the values of the environment variables
TeXmacs] TEXMACS_PATH and GUILE_LOAD_PATH. init-texmacs.scm should
TeXmacs] be readable and in the directory $TEXMACS_PATH/progs
TeXmacs] or in the directory $GUILE_LOAD_PATH
TeXmacs]
Throwing guile could not be found
-------------------------------------------------
Error message:
guile could not be found
So I ran
$ /Applications/TeXmacs.app/Contents/MacOS/TeXmacs
getting this screen output:
/Users/tilda/.TeXmacs/progs/my-init-texmacs.scm:336:1: In expression (assign “darkgreen” (macro “body” #)):
/Users/tilda/.TeXmacs/progs/my-init-texmacs.scm:336:1: Unbound variable: assign
TeXmacs] With linked TrueType support
/Users/tilda/.TeXmacs/progs/my-init-texmacs.scm:12:8: In expression (in-maxima?):
/Users/tilda/.TeXmacs/progs/my-init-texmacs.scm:12:8: Unbound variable: in-maxima?
/Users/tilda/.TeXmacs/progs/my-init-texmacs.scm:12:8: In expression (in-maxima?):
/Users/tilda/.TeXmacs/progs/my-init-texmacs.scm:12:8: Unbound variable: in-maxima?
If I interpret these results correctly, there are only two lines in the init
-file that are critical:
-
line 336,
(assign "darkgreen" (macro "body" (with "color" "dark green" (arg "body"))))
which is code by Vincent Douce (from: http://lists.texmacs.org/wws/arc/texmacs-users/2021-10/msg00044.html. btw, on this thread Vincent and Giovanni also posted some extremely useful keyboard shortcuts for math mode which, @pireddag, should be posted in a wiki in Notes on TeXmacs [https://texmacs.github.io/notes/docs/main.html] ) -
line 12,
(and (in-maxima?) (in-prog?)))
which is the code you posted on this blog.
This raises some questions.
-
After moving the definition of the brace/bracket-matching functions at the top of the
init
-file it is working. Why then this “error” message? -
Why does TeXmacs read-in/interpret code from line 336 before code from line 12?
This is the Scheme representation of a TeXmacs macro. This kind of thing should go into a preamble or a style file. Perhaps Vincent didn’t notice because this was at the end of the init file.
Ok
Besides VD wrote a document which might be a starting point for a post, which I have kept on my hard drive without making a post out of it for a long time
in-maxima?
is dynamically (I guess) defined by some hidden process, for plugin sessions. I tested another demo session and similar function is also defined. When you load your init file, (in-maxima?)
is used as a unbound variable in a function instead of actually being run. Then texmacs throw a warning when everything is done (after:
TeXmacs] With linked TrueType support
). If you don’t want to see the warning, just replace (in-maxima?)
with (== (get-env "prog-language") "maxima")
.
I had another look at this, but something fishy going on in the current git master.
I noticed that octave
highlighting has been broken by a recent commit. The problem seems to be that (format? "octave")
returns false.
So, I added
(define-format octave
(:name "Octave"))
to my-init-texmacs.scm
. This made (format? "octave")
return true. However, now all other highlighting in the document fails.
Oddly enough after removing the define-format
from my-init-texmacs.scm
highlighting for several languages that used to work remains broken.
I’ve gotten a type of “Maxima highlighting” to work by editing the TeXmacs source, but not yet from my-init-texmacs.scm
, as I don’t understand well how define-format
works.
The below works for me, although note that the keywords are simply copied from Octave, so they won’t give a meaningful Maxima highlighting.
patch
diff --git a/TeXmacs/packages/environment/env-program.ts b/TeXmacs/packages/environment/env-program.ts
index c71e97c36..c802d8471 100644
--- a/TeXmacs/packages/environment/env-program.ts
+++ b/TeXmacs/packages/environment/env-program.ts
@@ -174,6 +174,10 @@
<assign|python|<macro|<name|Python>>>
<assign|julia|<macro|<name|Julia>>>
+
+ <assign|maxima|<macro|<name|Maxima>>>
+
+ <assign|octave|<macro|<name|Octave>>>
<assign|scala|<macro|<name|Scala>>>
@@ -209,6 +213,8 @@
<assign|octave-lang|<macro|body|<with|mode|prog|prog-language|octave|font-family|rm|<arg|body>>>>
+ <assign|maxima-lang|<macro|body|<with|mode|prog|prog-language|maxima|font-family|rm|<arg|body>>>>
+
<\active*>
<\src-comment>
Blocks of code for standard languages
@@ -298,6 +304,12 @@
<julia|<arg|body>>
</pseudo-code>
</macro>>
+
+ <assign|maxima-code|<\macro|body>
+ <\pseudo-code>
+ <maxima-lang|<arg|body>>
+ </pseudo-code>
+ </macro>>
<assign|scala-code|<\macro|body>
<\pseudo-code>
@@ -384,4 +396,4 @@
<associate|preamble|true>
<associate|sfactor|5>
</collection>
-</initial>
\ No newline at end of file
+</initial>
diff --git a/TeXmacs/progs/kernel/texmacs/tm-modes.scm b/TeXmacs/progs/kernel/texmacs/tm-modes.scm
index 2a42fe5b3..0c986f4da 100644
--- a/TeXmacs/progs/kernel/texmacs/tm-modes.scm
+++ b/TeXmacs/progs/kernel/texmacs/tm-modes.scm
@@ -160,6 +160,8 @@
(in-prog-dot% #t in-prog% in-dot%)
(in-octave% (== (get-env "prog-language") "octave"))
(in-prog-octave% #t in-prog% in-octave%)
+ (in-maxima% (== (get-env "prog-language") "maxima"))
+ (in-prog-maxima% #t in-prog% in-maxima%)
(in-java% (== (get-env "prog-language") "java"))
(in-prog-java% #t in-prog% in-java%)
(in-javascript% (== (get-env "prog-language") "javascript"))
diff --git a/TeXmacs/progs/text/text-drd.scm b/TeXmacs/progs/text/text-drd.scm
index 405791643..632639a11 100644
--- a/TeXmacs/progs/text/text-drd.scm
+++ b/TeXmacs/progs/text/text-drd.scm
@@ -214,11 +214,11 @@
(define-group inline-code-tag
verbatim scm cpp mmx r fortran octave
- python julia java javascript json scala scilab shell)
+ python julia maxima java javascript json scala scilab shell)
(define-group block-code-tag
verbatim-code scm-code cpp-code dot-code mmx-code r-code fortran-code
- octave-code python-code julia-code java-code javascript-code json-code scala-code
+ octave-code python-code julia-code maxima-code java-code javascript-code json-code scala-code
scilab-code shell-code)
;; ornaments
diff --git a/plugins/code/progs/init-code.scm b/plugins/code/progs/init-code.scm
index f60add728..89d24a49c 100644
--- a/plugins/code/progs/init-code.scm
+++ b/plugins/code/progs/init-code.scm
@@ -1,3 +1,17 @@
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Maxima source files
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(define-format maxima
+ (:name "Maxima Source Code"))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Octave source files
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(define-format octave
+ (:name "Octave Source Code")
+ (:suffix "m"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; C++ source files
diff --git a/plugins/maxima/progs/maxima-lang.scm b/plugins/maxima/progs/maxima-lang.scm
new file mode 100644
index 000000000..8f7628c0b
--- /dev/null
+++ b/plugins/maxima/progs/maxima-lang.scm
@@ -0,0 +1,62 @@
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;
+;; MODULE : maxima-lang.scm
+;; DESCRIPTION : the maxima Language
+;; COPYRIGHT : (C) 2020 Darcy Shen
+;;
+;; This software falls under the GNU general public license version 3 or later.
+;; It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
+;; in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
+;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(texmacs-module (maxima-lang)
+ (:use (prog default-lang)))
+
+(tm-define (parser-feature lan key)
+ (:require (and (== lan "maxima") (== key "keyword")))
+ `(,(string->symbol key)
+ (constant
+ "false" "true")
+ (declare_type "function" "endfunction" "class")
+ (declare_module "pkg")
+ (keyword_conditional
+ "break" "continue" "do" "else" "for" "endfor" "if" "endif"
+ "while" "endwhile" "switch" "case")
+ (keyword_control
+ "catch" "try")))
+
+(tm-define (parser-feature lan key)
+ (:require (and (== lan "maxima") (== key "operator")))
+ `(,(string->symbol key)
+ (operator "," ";" ":" "=")
+ (operator_special "@")
+ (operator_field ".")
+ (operator_openclose "{" "[" "(" ")" "]" "}")))
+
+(define (maxima-number-suffix)
+ `(suffix
+ (imaginary "j" "J")))
+
+(tm-define (parser-feature lan key)
+ (:require (and (== lan "maxima") (== key "number")))
+ `(,(string->symbol key)
+ (bool_features
+ "prefix_0x" "prefix_0b"
+ "sci_notation")
+ (separator "_")
+ ,(maxima-number-suffix)))
+
+(tm-define (parser-feature lan key)
+ (:require (and (== lan "maxima") (== key "string")))
+ `(,(string->symbol key)
+ (bool_features
+ "hex_with_8_bits" "hex_with_16_bits"
+ "hex_with_32_bits" "octal_upto_3_digits")
+ (escape_sequences "\\" "\"" "'" "a" "b" "f" "n" "r" "t" "v")))
+
+(tm-define (parser-feature lan key)
+ (:require (and (== lan "maxima") (== key "comment")))
+ `(,(string->symbol key)
+ (inline "#" "%")))