1 ;;; maxima-font-lock.el --- syntax highlighting for maxima.el
3 ;; Copyright: (C) 2001 Jay Belanger
5 ;; Author: Jay Belanger <belanger@truman.edu>
8 ;; $Date: 2010-11-21 21:42:45 $
9 ;; Keywords: maxima, font-lock
11 ;; This program is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2, or (at
14 ;; your option) any later version.
16 ;; This program is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;; General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 ;; Please send suggestions and bug reports to <belanger@truman.edu>
26 ;; The latest version of this package should be available at
27 ;; ftp://vh213601.truman.edu/pub/Maxima
31 ;;; This file is used for font-lock for maxima.el
33 ;; The keywords are divided into the following groups, following the
35 ;; Functions (font-lock-builtin-face or font-lock-keyword-face)
36 ;; Variables (font-lock-keyword-face)
37 ;; Constants (font-lock-constant-face)
38 ;; Keywords (font-lock-keyword-face)
39 ;; Declarations (font-lock-keyword-face)
40 ;; Operators (font-lock-keyword-face)
41 ;; Property (font-lock-keyword-face)
42 ;; Macros (font-lock-keyword-face)
43 ;; Special operators (font-lock-keyword-face)
44 ;; Special symbols (font-lock-keyword-face)
50 (provide 'maxima-font-lock
)
54 ;; (defvar maxima-variable-face 'maxima-variable-face
55 ;; "The face to use for the variables.")
57 ;; (defvar maxima-function-face 'maxima-function-face
58 ;; "The face to use for the functions.")
60 ;; (defvar maxima-constant-face 'maxima-constant-face
61 ;; "The face to use for the constants.")
63 ;; (defvar maxima-keyword-face 'maxima-keyword-face
64 ;; "The face to use for the keywords.")
66 ;; (defvar maxima-operator-face 'maxima-operator-face
67 ;; "The face to use for the operators.")
69 ;; (defvar maxima-property-face 'maxima-property-face
70 ;; "The face to use for the properties.")
72 ;; (defvar maxima-macro-face 'maxima-macro-face
73 ;; "The face to use for the macros.")
75 ;; (defvar maxima-specop-face 'maxima-specop-face
76 ;; "The face to use for the special operators.")
78 ;; (defvar maxima-declaration-face 'maxima-declaration-face
79 ;; "The face to use for the macros.")
81 ;; (defvar maxima-specsymb-face 'maxima-specsymb-face
82 ;; "The face to use for the special symbols.")
93 (defvar maxima-match-variables-1
95 (eval-when-compile (regexp-opt maxima-vars-1
))
97 "regexp to match the maxima variables.")
104 "change_filedefaults"
105 "current_let_rule_package"
106 "default_let_rule_package"
107 "display_format_internal"
114 "integration_constant_counter"
119 "matrix_element_mult"
120 "matrix_element_transpose"
125 "solve_inconsistent_error"
126 "sublis_apply_lambda"
128 "taylor_order_coefficients"
129 "taylor_truncate_polynomials"
132 "tr_bound_function_applyp"
133 "tr_file_tty_messagesp"
134 "tr_float_can_branch_complex"
135 "tr_function_call_default"
137 "tr_optimize_max_loop"
139 "tr_true_name_of_file_being_translated"
140 "tr_warn_bad_function_calls"
145 "tr_warn_undefined_variable"
149 (defvar maxima-match-variables-2
151 (eval-when-compile (regexp-opt maxima-vars-2
))
153 "regexp to match the maxima variables.")
155 (defvar maxima-vars-3
276 (defvar maxima-match-variables-3
278 (eval-when-compile (regexp-opt maxima-vars-3
))
280 "regexp to match the maxima variables.")
282 (defvar maxima-vars-4
379 (defvar maxima-match-variables-4
381 (eval-when-compile (regexp-opt maxima-vars-4
))
383 "regexp to match the maxima variables.")
395 (defvar maxima-match-functions-1
397 (eval-when-compile (regexp-opt maxima-fns-1
))
399 "regexp to match the maxima functions.")
572 (defvar maxima-match-functions-2
574 (eval-when-compile (regexp-opt maxima-fns-2
))
576 "regexp to match the maxima functions.")
610 "extract_linear_equations"
620 "fast_central_elements"
651 (defvar maxima-match-functions-3
653 (eval-when-compile (regexp-opt maxima-fns-3
))
655 "regexp to match the maxima functions.")
744 (defvar maxima-match-functions-4
746 (eval-when-compile (regexp-opt maxima-fns-4
))
748 "regexp to match the maxima functions.")
777 "monomial_dimensions"
880 (defvar maxima-match-functions-5
882 (eval-when-compile (regexp-opt maxima-fns-5
))
884 "regexp to match the maxima functions.")
928 "resolvante_alternee1"
929 "resolvante_bipartite"
930 "resolvante_diedrale"
933 "resolvante_produit_sym"
934 "resolvante_unitaire"
967 "set_up_dot_simplifications"
971 "similaritytransform"
1062 (defvar maxima-match-functions-6
1064 (eval-when-compile (regexp-opt maxima-fns-6
))
1066 "regexp to match the maxima functions.")
1068 (defvar maxima-const-1
1079 (defvar maxima-match-constants-1
1081 (eval-when-compile (regexp-opt maxima-const-1
))
1083 "regexp to match the maxima constants.")
1085 (defvar maxima-const-2
1094 (defvar maxima-match-constants-2
1096 (eval-when-compile (regexp-opt maxima-const-2
))
1098 "regexp to match the maxima constants.")
1100 (defvar maxima-match-constants-3
1101 "\\<\\([0-9]+\\)\\>"
1102 "regexp to match the maxima constants.")
1104 (defvar maxima-match-constants-4
1105 "\\<\\([0-9]+\.\\)?\\([0-9]+b[+-]?[0-9]\\)\\>"
1106 "regexp to match the maxima constants.")
1108 (defvar maxima-keywds
1112 (defvar maxima-match-keywords
1114 (eval-when-compile (regexp-opt maxima-keywds
))
1116 "regexp to match the maxima keywords.")
1118 (defvar maxima-match-operators
1141 "regexp to match the maxima operators.")
1143 (defvar maxima-props
1148 (defvar maxima-match-properties
1150 (eval-when-compile (regexp-opt maxima-props
))
1152 "regexp to match maxima properties.")
1154 (defvar maxima-macros
1160 (defvar maxima-match-macros
1162 (eval-when-compile (regexp-opt maxima-macros
))
1164 "regexp to match maxima macros.")
1166 (defvar maxima-specops
1181 (defvar maxima-match-specops
1183 (eval-when-compile (regexp-opt maxima-specops
))
1185 "regexp to match maxima special operators.")
1206 (defvar maxima-match-declarations
1208 (eval-when-compile (regexp-opt maxima-decs
))
1210 "regexp to match maxima declarations.")
1212 (defvar maxima-spsymbs-1
1224 (defvar maxima-match-specsymbs-1
1226 (eval-when-compile (regexp-opt maxima-spsymbs-1
))
1228 "regexp to match maxima special symbols.")
1230 (defvar maxima-match-specsymbs-2
1231 "\\(\\<\\?\\sw+\\>\\)"
1232 "regexp to match maxima special symbols.")
1234 ;;; now, create the faces.
1236 ;; (defface maxima-function-face
1237 ;; '((((type tty) (class color)) (:foreground "blue" :weight bold))
1238 ;; (((class color) (background light)) (:foreground "blue" :weight bold))
1239 ;; (((class color) (background dark)) (:foreground "lightskyblue" :weight bold))
1240 ;; (t (:inverse-video t :bold t)))
1241 ;; "font lock mode face used to highlight function names."
1244 ;; (defface maxima-constant-face
1245 ;; '((((type tty) (class color)) (:foreground "magenta"))
1246 ;; (((class grayscale) (background light))
1247 ;; (:foreground "lightgray" :bold t :underline t))
1248 ;; (((class grayscale) (background dark))
1249 ;; (:foreground "gray50" :bold t :underline t))
1250 ;; (((class color) (background light)) (:foreground "cadetblue" :weight bold))
1251 ;; (((class color) (background dark)) (:foreground "aquamarine" :weight bold))
1252 ;; (t (:bold t :underline t)))
1253 ;; "font lock mode face used to highlight constants and labels."
1256 ;; (defface maxima-keyword-face
1257 ;; '((((type tty) (class color)) (:foreground "cyan" :weight bold))
1258 ;; (((class grayscale) (background light)) (:foreground "lightgray" :bold t))
1259 ;; (((class grayscale) (background dark)) (:foreground "dimgray" :bold t))
1260 ;; (((class color) (background light)) (:foreground "purple" :weight bold))
1261 ;; (((class color) (background dark)) (:foreground "cyan" :weight bold))
1263 ;; "font lock mode face used to highlight keywords."
1266 ;; (defface maxima-operator-face
1267 ;; '((((type tty) (class color)) (:foreground "blue" :weight light))
1268 ;; (((class grayscale) (background light)) (:foreground "lightgray" :bold t))
1269 ;; (((class grayscale) (background dark)) (:foreground "dimgray" :bold t))
1270 ;; (((class color) (background light)) (:foreground "orchid" :weight bold))
1271 ;; (((class color) (background dark)) (:foreground "lightsteelblue" :weight bold))
1273 ;; "font lock mode face used to highlight builtins."
1276 ;; (defface maxima-property-face
1277 ;; '((((type tty) (class color)) (:foreground "green"))
1278 ;; (((class grayscale) (background light)) (:foreground "gray90" :bold t))
1279 ;; (((class grayscale) (background dark)) (:foreground "dimgray" :bold t))
1280 ;; (((class color) (background light)) (:foreground "forestgreen" :weight bold))
1281 ;; (((class color) (background dark)) (:foreground "palegreen" :weight bold))
1282 ;; (t (:bold t :underline t)))
1283 ;; "font lock mode face used to highlight type and classes."
1286 ;; (defface maxima-macro-face
1287 ;; '((((class color) (background dark)) (:foreground "steelblue1"))
1288 ;; (((class color) (background light)) (:foreground "blue3"))
1289 ;; (t (:underline t)))
1290 ;; "font lock mode face used to highlight preprocessor conditionals."
1293 ;; (defface maxima-specop-face
1294 ;; '((((type tty) (class color)) (:foreground "cyan" :weight bold))
1295 ;; (((class grayscale) (background light)) (:foreground "lightgray" :bold t))
1296 ;; (((class grayscale) (background dark)) (:foreground "dimgray" :bold t))
1297 ;; (((class color) (background light)) (:foreground "purple" :weight bold))
1298 ;; (((class color) (background dark)) (:foreground "cyan" :weight bold))
1300 ;; "font lock mode face used to highlight keywords."
1303 ;; (defface maxima-declaration-face
1304 ;; '((((type tty) (class color)) (:foreground "cyan" :weight bold))
1305 ;; (((class grayscale) (background light)) (:foreground "lightgray" :bold t))
1306 ;; (((class grayscale) (background dark)) (:foreground "dimgray" :bold t))
1307 ;; (((class color) (background light)) (:foreground "purple" :weight bold))
1308 ;; (((class color) (background dark)) (:foreground "cyan" :weight bold))
1310 ;; "font lock mode face used to highlight keywords."
1313 ;; (defface maxima-specsymb-face
1314 ;; '((((type tty) (class color)) (:foreground "red"))
1315 ;; (((class color) (background light)) (:foreground "red" :bold t))
1316 ;; (((class color) (background dark)) (:foreground "pink" :bold t))
1317 ;; (t (:inverse-video t :bold t)))
1318 ;; "font lock mode face used to highlight warnings."
1321 ;; (defface maxima-variable-face
1322 ;; '((((type tty) (class color)) (:foreground "yellow" :weight light))
1323 ;; (((class grayscale) (background light))
1324 ;; (:foreground "gray90" :bold t :italic t))
1325 ;; (((class grayscale) (background dark))
1326 ;; (:foreground "dimgray" :bold t :italic t))
1327 ;; (((class color) (background light)) (:foreground "darkgoldenrod" :italic t))
1328 ;; (((class color) (background dark)) (:foreground "lightgoldenrod" :italic t))
1329 ;; (t (:bold t :italic t)))
1330 ;; "font lock mode face used to highlight variable names."
1333 ;;; now, the keywords
1334 (unless (facep 'font-lock-builtin-face
)
1335 (copy-face 'font-lock-keyword-face
'font-lock-builtin-face
))
1337 (unless (facep 'font-lock-constant-face
)
1338 (copy-face 'font-lock-keyword-face
'font-lock-constant-face
))
1340 (defvar maxima-font-lock-keywords-1
1342 (,maxima-match-declarations . font-lock-keyword-face
))
1343 "Subdued level highlighting for Maxima mode.")
1345 (defvar maxima-font-lock-keywords-2
1346 (append maxima-font-lock-keywords-1
1348 (,maxima-match-operators . font-lock-keyword-face
)
1349 (,maxima-match-variables-1 . font-lock-keyword-face
)
1350 (,maxima-match-variables-2 . font-lock-keyword-face
)
1351 (,maxima-match-variables-3 . font-lock-keyword-face
)
1352 (,maxima-match-variables-4 . font-lock-keyword-face
)
1353 (,maxima-match-functions-1 . font-lock-builtin-face
)
1354 (,maxima-match-functions-2 . font-lock-builtin-face
)
1355 (,maxima-match-functions-3 . font-lock-builtin-face
)
1356 (,maxima-match-functions-4 . font-lock-builtin-face
)
1357 (,maxima-match-functions-5 . font-lock-builtin-face
)
1358 (,maxima-match-functions-6 . font-lock-builtin-face
)
1359 (,maxima-match-constants-1 . font-lock-constant-face
)
1360 (,maxima-match-constants-2 . font-lock-constant-face
)
1361 (,maxima-match-constants-3 . font-lock-constant-face
)
1362 (,maxima-match-constants-4 . font-lock-constant-face
)
1363 (,maxima-match-keywords . font-lock-keyword-face
)
1364 (,maxima-match-properties . font-lock-keyword-face
)
1365 (,maxima-match-macros . font-lock-keyword-face
)
1366 (,maxima-match-specops . font-lock-keyword-face
)
1367 (,maxima-match-specsymbs-1 . font-lock-keyword-face
)
1368 (,maxima-match-specsymbs-2 . font-lock-keyword-face
)))
1369 "Medium level highlighting for Maxima mode.")
1371 (defvar maxima-font-lock-keywords-3
1372 (let* ((spc "[[:space:]]*")
1373 (lspc (concat "^" spc
))
1374 (name "[%_[:alnum:]]+")
1375 (fname (concat "\\(" name
"\\)"))
1376 (arg (concat spc name spc
))
1377 (marg (concat "\\(?:\\(?:" arg
"," spc
"\\)+" arg
"\\)"))
1378 (optarg (concat spc
"\\[" spc name spc
"\\]" spc
))
1379 (1-arg (concat spc name spc
))
1380 (1-arg-optarg (concat spc name spc
"," spc
"\\[" spc name spc
"\\]" spc
))
1381 (marg-optarg (concat marg spc
"," spc optarg
))
1383 (fopen (concat spc
"(" spc
))
1384 (fclose (concat spc
")" spc
))
1386 (fbegin (concat lspc fname fopen
))
1387 (fend (concat fclose defn
))
1389 ;; functions: f(...) :=
1390 (fn (concat fbegin
"\\(" zarg alt optarg alt
1-arg alt marg alt optarg alt
1-arg-optarg alt marg-optarg
"\\)" fend
))
1391 ;; pure hash functions: f[...] :=
1392 (afopen (concat spc
"\\[" spc
))
1393 (afclose (concat spc
"\\]" spc
))
1394 (afbegin (concat lspc fname afopen
))
1395 (afend (concat afclose defn
))
1396 (afn (concat afbegin
"\\(" zarg alt
1-arg alt marg
"\\)" afend
))
1397 ;; hash/ordinary functions: f[...](...) :=
1398 (hfopen (concat spc
"\\[" spc
))
1399 (hfclose (concat spc
"\\]" spc
))
1400 (hfbegin (concat lspc fname hfopen
))
1401 (hfend (concat hfclose defn
))
1402 (hfn (concat hfbegin
"\\(" 1-arg alt marg
"\\)" hfclose fopen
"\\(" zarg alt
1-arg alt marg alt optarg alt
1-arg-optarg alt marg-optarg
"\\)" fend
)))
1403 (append maxima-font-lock-keywords-2
1405 (list fn
'(1 font-lock-function-name-face
))
1406 (list afn
'(1 font-lock-function-name-face
))
1407 (list hfn
'(1 font-lock-function-name-face
))
1408 (list fn
'(2 font-lock-variable-name-face
))
1409 (list afn
'(2 font-lock-variable-name-face
))
1410 (list hfn
'(2 font-lock-variable-name-face
))
1411 (list hfn
'(3 font-lock-variable-name-face
)))))
1412 "Gaudy level highlighting for Maxima mode.")
1414 (defvar maxima-font-lock-keywords maxima-font-lock-keywords-3
1415 "Default expressions to highlight in Maxima mode.")
1417 (defun maxima-font-setup ()
1418 (make-local-variable 'font-lock-defaults
)
1419 (setq font-lock-defaults
1420 '((maxima-font-lock-keywords maxima-font-lock-keywords-1
1421 maxima-font-lock-keywords-2 maxima-font-lock-keywords-3
)
1424 (add-hook 'maxima-mode-hook
'maxima-font-setup
)
1426 ;;; A function to fontify the preamble in a Maxima process buffer
1427 (defvar maxima-preamble-fontlock t
)
1429 (defun maxima-match-preamble (limit)
1430 "Used to fontify the preamble."
1431 (if maxima-preamble-fontlock
1433 (setq maxima-preamble-fontlock nil
)
1434 (let ((beg (point-min))
1436 (if (search-forward "(%i1)" limit
)
1439 (setq end
(maxima-line-end-position))
1440 (store-match-data (list beg end
))
1444 (defvar inferior-maxima-font-lock-keywords-1
1445 (append maxima-font-lock-keywords-1
1446 '((maxima-match-preamble (0 font-lock-string-face t t
)))))
1448 (defvar inferior-maxima-font-lock-keywords-2
1449 (append maxima-font-lock-keywords-2
1450 '((maxima-match-preamble (0 font-lock-string-face t t
)))))
1452 (defvar inferior-maxima-font-lock-keywords-3
1453 (append maxima-font-lock-keywords-3
1454 '((maxima-match-preamble (0 font-lock-string-face t t
)))))
1456 (defvar inferior-maxima-font-lock-keywords inferior-maxima-font-lock-keywords-3
1457 "Default expressions to highlight in Maxima mode.")
1459 (defun inferior-maxima-font-setup ()
1460 (make-local-variable 'font-lock-defaults
)
1461 (setq font-lock-defaults
1462 '((inferior-maxima-font-lock-keywords inferior-maxima-font-lock-keywords-1
1463 inferior-maxima-font-lock-keywords-2 inferior-maxima-font-lock-keywords-3
)
1466 ;;; now for the symbols
1468 (defvar maxima-symbols
1470 (lambda (x) (list x
))
1491 ;;; end of maxima-font-lock.el