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., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
26 ;; Please send suggestions and bug reports to <belanger@truman.edu>
27 ;; The latest version of this package should be available at
28 ;; ftp://vh213601.truman.edu/pub/Maxima
32 ;;; This file is used for font-lock for maxima.el
34 ;; The keywords are divided into the following groups, following the
36 ;; Functions (font-lock-builtin-face or font-lock-keyword-face)
37 ;; Variables (font-lock-keyword-face)
38 ;; Constants (font-lock-constant-face)
39 ;; Keywords (font-lock-keyword-face)
40 ;; Declarations (font-lock-keyword-face)
41 ;; Operators (font-lock-keyword-face)
42 ;; Property (font-lock-keyword-face)
43 ;; Macros (font-lock-keyword-face)
44 ;; Special operators (font-lock-keyword-face)
45 ;; Special symbols (font-lock-keyword-face)
51 (provide 'maxima-font-lock
)
55 ;; (defvar maxima-variable-face 'maxima-variable-face
56 ;; "The face to use for the variables.")
58 ;; (defvar maxima-function-face 'maxima-function-face
59 ;; "The face to use for the functions.")
61 ;; (defvar maxima-constant-face 'maxima-constant-face
62 ;; "The face to use for the constants.")
64 ;; (defvar maxima-keyword-face 'maxima-keyword-face
65 ;; "The face to use for the keywords.")
67 ;; (defvar maxima-operator-face 'maxima-operator-face
68 ;; "The face to use for the operators.")
70 ;; (defvar maxima-property-face 'maxima-property-face
71 ;; "The face to use for the properties.")
73 ;; (defvar maxima-macro-face 'maxima-macro-face
74 ;; "The face to use for the macros.")
76 ;; (defvar maxima-specop-face 'maxima-specop-face
77 ;; "The face to use for the special operators.")
79 ;; (defvar maxima-declaration-face 'maxima-declaration-face
80 ;; "The face to use for the macros.")
82 ;; (defvar maxima-specsymb-face 'maxima-specsymb-face
83 ;; "The face to use for the special symbols.")
94 (defvar maxima-match-variables-1
96 (eval-when-compile (regexp-opt maxima-vars-1
))
98 "regexp to match the maxima variables.")
100 (defvar maxima-vars-2
105 "change_filedefaults"
106 "current_let_rule_package"
107 "default_let_rule_package"
108 "display_format_internal"
115 "integration_constant_counter"
120 "matrix_element_mult"
121 "matrix_element_transpose"
126 "solve_inconsistent_error"
127 "sublis_apply_lambda"
129 "taylor_order_coefficients"
130 "taylor_truncate_polynomials"
133 "tr_bound_function_applyp"
134 "tr_file_tty_messagesp"
135 "tr_float_can_branch_complex"
136 "tr_function_call_default"
138 "tr_optimize_max_loop"
141 "tr_true_name_of_file_being_translated"
142 "tr_warn_bad_function_calls"
147 "tr_warn_undefined_variable"
151 (defvar maxima-match-variables-2
153 (eval-when-compile (regexp-opt maxima-vars-2
))
155 "regexp to match the maxima variables.")
157 (defvar maxima-vars-3
278 (defvar maxima-match-variables-3
280 (eval-when-compile (regexp-opt maxima-vars-3
))
282 "regexp to match the maxima variables.")
284 (defvar maxima-vars-4
383 (defvar maxima-match-variables-4
385 (eval-when-compile (regexp-opt maxima-vars-4
))
387 "regexp to match the maxima variables.")
399 (defvar maxima-match-functions-1
401 (eval-when-compile (regexp-opt maxima-fns-1
))
403 "regexp to match the maxima functions.")
581 (defvar maxima-match-functions-2
583 (eval-when-compile (regexp-opt maxima-fns-2
))
585 "regexp to match the maxima functions.")
619 "extract_linear_equations"
629 "fast_central_elements"
660 (defvar maxima-match-functions-3
662 (eval-when-compile (regexp-opt maxima-fns-3
))
664 "regexp to match the maxima functions.")
753 (defvar maxima-match-functions-4
755 (eval-when-compile (regexp-opt maxima-fns-4
))
757 "regexp to match the maxima functions.")
786 "monomial_dimensions"
889 (defvar maxima-match-functions-5
891 (eval-when-compile (regexp-opt maxima-fns-5
))
893 "regexp to match the maxima functions.")
937 "resolvante_alternee1"
938 "resolvante_bipartite"
939 "resolvante_diedrale"
942 "resolvante_produit_sym"
943 "resolvante_unitaire"
977 "set_up_dot_simplifications"
981 "similaritytransform"
1074 (defvar maxima-match-functions-6
1076 (eval-when-compile (regexp-opt maxima-fns-6
))
1078 "regexp to match the maxima functions.")
1080 (defvar maxima-const-1
1091 (defvar maxima-match-constants-1
1093 (eval-when-compile (regexp-opt maxima-const-1
))
1095 "regexp to match the maxima constants.")
1097 (defvar maxima-const-2
1106 (defvar maxima-match-constants-2
1108 (eval-when-compile (regexp-opt maxima-const-2
))
1110 "regexp to match the maxima constants.")
1112 (defvar maxima-match-constants-3
1113 "\\<\\([0-9]+\\)\\>"
1114 "regexp to match the maxima constants.")
1116 (defvar maxima-match-constants-4
1117 "\\<\\([0-9]+\.\\)?\\([0-9]+b[+-]?[0-9]\\)\\>"
1118 "regexp to match the maxima constants.")
1120 (defvar maxima-keywds
1124 (defvar maxima-match-keywords
1126 (eval-when-compile (regexp-opt maxima-keywds
))
1128 "regexp to match the maxima keywords.")
1130 (defvar maxima-match-operators
1153 "regexp to match the maxima operators.")
1155 (defvar maxima-props
1160 (defvar maxima-match-properties
1162 (eval-when-compile (regexp-opt maxima-props
))
1164 "regexp to match maxima properties.")
1166 (defvar maxima-macros
1172 (defvar maxima-match-macros
1174 (eval-when-compile (regexp-opt maxima-macros
))
1176 "regexp to match maxima macros.")
1178 (defvar maxima-specops
1193 (defvar maxima-match-specops
1195 (eval-when-compile (regexp-opt maxima-specops
))
1197 "regexp to match maxima special operators.")
1218 (defvar maxima-match-declarations
1220 (eval-when-compile (regexp-opt maxima-decs
))
1222 "regexp to match maxima declarations.")
1224 (defvar maxima-spsymbs-1
1236 (defvar maxima-match-specsymbs-1
1238 (eval-when-compile (regexp-opt maxima-spsymbs-1
))
1240 "regexp to match maxima special symbols.")
1242 (defvar maxima-match-specsymbs-2
1243 "\\(\\<\\?\\sw+\\>\\)"
1244 "regexp to match maxima special symbols.")
1246 ;;; now, create the faces.
1248 ;; (defface maxima-function-face
1249 ;; '((((type tty) (class color)) (:foreground "blue" :weight bold))
1250 ;; (((class color) (background light)) (:foreground "blue" :weight bold))
1251 ;; (((class color) (background dark)) (:foreground "lightskyblue" :weight bold))
1252 ;; (t (:inverse-video t :bold t)))
1253 ;; "font lock mode face used to highlight function names."
1256 ;; (defface maxima-constant-face
1257 ;; '((((type tty) (class color)) (:foreground "magenta"))
1258 ;; (((class grayscale) (background light))
1259 ;; (:foreground "lightgray" :bold t :underline t))
1260 ;; (((class grayscale) (background dark))
1261 ;; (:foreground "gray50" :bold t :underline t))
1262 ;; (((class color) (background light)) (:foreground "cadetblue" :weight bold))
1263 ;; (((class color) (background dark)) (:foreground "aquamarine" :weight bold))
1264 ;; (t (:bold t :underline t)))
1265 ;; "font lock mode face used to highlight constants and labels."
1268 ;; (defface maxima-keyword-face
1269 ;; '((((type tty) (class color)) (:foreground "cyan" :weight bold))
1270 ;; (((class grayscale) (background light)) (:foreground "lightgray" :bold t))
1271 ;; (((class grayscale) (background dark)) (:foreground "dimgray" :bold t))
1272 ;; (((class color) (background light)) (:foreground "purple" :weight bold))
1273 ;; (((class color) (background dark)) (:foreground "cyan" :weight bold))
1275 ;; "font lock mode face used to highlight keywords."
1278 ;; (defface maxima-operator-face
1279 ;; '((((type tty) (class color)) (:foreground "blue" :weight light))
1280 ;; (((class grayscale) (background light)) (:foreground "lightgray" :bold t))
1281 ;; (((class grayscale) (background dark)) (:foreground "dimgray" :bold t))
1282 ;; (((class color) (background light)) (:foreground "orchid" :weight bold))
1283 ;; (((class color) (background dark)) (:foreground "lightsteelblue" :weight bold))
1285 ;; "font lock mode face used to highlight builtins."
1288 ;; (defface maxima-property-face
1289 ;; '((((type tty) (class color)) (:foreground "green"))
1290 ;; (((class grayscale) (background light)) (:foreground "gray90" :bold t))
1291 ;; (((class grayscale) (background dark)) (:foreground "dimgray" :bold t))
1292 ;; (((class color) (background light)) (:foreground "forestgreen" :weight bold))
1293 ;; (((class color) (background dark)) (:foreground "palegreen" :weight bold))
1294 ;; (t (:bold t :underline t)))
1295 ;; "font lock mode face used to highlight type and classes."
1298 ;; (defface maxima-macro-face
1299 ;; '((((class color) (background dark)) (:foreground "steelblue1"))
1300 ;; (((class color) (background light)) (:foreground "blue3"))
1301 ;; (t (:underline t)))
1302 ;; "font lock mode face used to highlight preprocessor conditionals."
1305 ;; (defface maxima-specop-face
1306 ;; '((((type tty) (class color)) (:foreground "cyan" :weight bold))
1307 ;; (((class grayscale) (background light)) (:foreground "lightgray" :bold t))
1308 ;; (((class grayscale) (background dark)) (:foreground "dimgray" :bold t))
1309 ;; (((class color) (background light)) (:foreground "purple" :weight bold))
1310 ;; (((class color) (background dark)) (:foreground "cyan" :weight bold))
1312 ;; "font lock mode face used to highlight keywords."
1315 ;; (defface maxima-declaration-face
1316 ;; '((((type tty) (class color)) (:foreground "cyan" :weight bold))
1317 ;; (((class grayscale) (background light)) (:foreground "lightgray" :bold t))
1318 ;; (((class grayscale) (background dark)) (:foreground "dimgray" :bold t))
1319 ;; (((class color) (background light)) (:foreground "purple" :weight bold))
1320 ;; (((class color) (background dark)) (:foreground "cyan" :weight bold))
1322 ;; "font lock mode face used to highlight keywords."
1325 ;; (defface maxima-specsymb-face
1326 ;; '((((type tty) (class color)) (:foreground "red"))
1327 ;; (((class color) (background light)) (:foreground "red" :bold t))
1328 ;; (((class color) (background dark)) (:foreground "pink" :bold t))
1329 ;; (t (:inverse-video t :bold t)))
1330 ;; "font lock mode face used to highlight warnings."
1333 ;; (defface maxima-variable-face
1334 ;; '((((type tty) (class color)) (:foreground "yellow" :weight light))
1335 ;; (((class grayscale) (background light))
1336 ;; (:foreground "gray90" :bold t :italic t))
1337 ;; (((class grayscale) (background dark))
1338 ;; (:foreground "dimgray" :bold t :italic t))
1339 ;; (((class color) (background light)) (:foreground "darkgoldenrod" :italic t))
1340 ;; (((class color) (background dark)) (:foreground "lightgoldenrod" :italic t))
1341 ;; (t (:bold t :italic t)))
1342 ;; "font lock mode face used to highlight variable names."
1345 ;;; now, the keywords
1346 (unless (facep 'font-lock-builtin-face
)
1347 (copy-face 'font-lock-keyword-face
'font-lock-builtin-face
))
1349 (unless (facep 'font-lock-constant-face
)
1350 (copy-face 'font-lock-keyword-face
'font-lock-constant-face
))
1352 (defvar maxima-font-lock-keywords-1
1354 (,maxima-match-declarations . font-lock-keyword-face
))
1355 "Subdued level highlighting for Maxima mode.")
1357 (defvar maxima-font-lock-keywords-2
1358 (append maxima-font-lock-keywords-1
1360 (,maxima-match-operators . font-lock-keyword-face
)
1361 (,maxima-match-variables-1 . font-lock-keyword-face
)
1362 (,maxima-match-variables-2 . font-lock-keyword-face
)
1363 (,maxima-match-variables-3 . font-lock-keyword-face
)
1364 (,maxima-match-variables-4 . font-lock-keyword-face
)
1365 (,maxima-match-functions-1 . font-lock-builtin-face
)
1366 (,maxima-match-functions-2 . font-lock-builtin-face
)
1367 (,maxima-match-functions-3 . font-lock-builtin-face
)
1368 (,maxima-match-functions-4 . font-lock-builtin-face
)
1369 (,maxima-match-functions-5 . font-lock-builtin-face
)
1370 (,maxima-match-functions-6 . font-lock-builtin-face
)
1371 (,maxima-match-constants-1 . font-lock-constant-face
)
1372 (,maxima-match-constants-2 . font-lock-constant-face
)
1373 (,maxima-match-constants-3 . font-lock-constant-face
)
1374 (,maxima-match-constants-4 . font-lock-constant-face
)
1375 (,maxima-match-keywords . font-lock-keyword-face
)
1376 (,maxima-match-properties . font-lock-keyword-face
)
1377 (,maxima-match-macros . font-lock-keyword-face
)
1378 (,maxima-match-specops . font-lock-keyword-face
)
1379 (,maxima-match-specsymbs-1 . font-lock-keyword-face
)
1380 (,maxima-match-specsymbs-2 . font-lock-keyword-face
)))
1381 "Medium level highlighting for Maxima mode.")
1383 (defvar maxima-font-lock-keywords-3
1384 (let* ((spc "[[:space:]]*")
1385 (lspc (concat "^" spc
))
1386 (name "[%_[:alnum:]]+")
1387 (fname (concat "\\(" name
"\\)"))
1388 (arg (concat spc name spc
))
1389 (marg (concat "\\(?:\\(?:" arg
"," spc
"\\)+" arg
"\\)"))
1390 (optarg (concat spc
"\\[" spc name spc
"\\]" spc
))
1391 (1-arg (concat spc name spc
))
1392 (1-arg-optarg (concat spc name spc
"," spc
"\\[" spc name spc
"\\]" spc
))
1393 (marg-optarg (concat marg spc
"," spc optarg
))
1395 (fopen (concat spc
"(" spc
))
1396 (fclose (concat spc
")" spc
))
1398 (fbegin (concat lspc fname fopen
))
1399 (fend (concat fclose defn
))
1401 ;; functions: f(...) :=
1402 (fn (concat fbegin
"\\(" zarg alt optarg alt
1-arg alt marg alt optarg alt
1-arg-optarg alt marg-optarg
"\\)" fend
))
1403 ;; pure hash functions: f[...] :=
1404 (afopen (concat spc
"\\[" spc
))
1405 (afclose (concat spc
"\\]" spc
))
1406 (afbegin (concat lspc fname afopen
))
1407 (afend (concat afclose defn
))
1408 (afn (concat afbegin
"\\(" zarg alt
1-arg alt marg
"\\)" afend
))
1409 ;; hash/ordinary functions: f[...](...) :=
1410 (hfopen (concat spc
"\\[" spc
))
1411 (hfclose (concat spc
"\\]" spc
))
1412 (hfbegin (concat lspc fname hfopen
))
1413 (hfend (concat hfclose defn
))
1414 (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
)))
1415 (append maxima-font-lock-keywords-2
1417 (list fn
'(1 font-lock-function-name-face
))
1418 (list afn
'(1 font-lock-function-name-face
))
1419 (list hfn
'(1 font-lock-function-name-face
))
1420 (list fn
'(2 font-lock-variable-name-face
))
1421 (list afn
'(2 font-lock-variable-name-face
))
1422 (list hfn
'(2 font-lock-variable-name-face
))
1423 (list hfn
'(3 font-lock-variable-name-face
)))))
1424 "Gaudy level highlighting for Maxima mode.")
1426 (defvar maxima-font-lock-keywords maxima-font-lock-keywords-3
1427 "Default expressions to highlight in Maxima mode.")
1429 (defun maxima-font-setup ()
1430 (make-local-variable 'font-lock-defaults
)
1431 (setq font-lock-defaults
1432 '((maxima-font-lock-keywords maxima-font-lock-keywords-1
1433 maxima-font-lock-keywords-2 maxima-font-lock-keywords-3
)
1436 (add-hook 'maxima-mode-hook
'maxima-font-setup
)
1438 ;;; A function to fontify the preamble in a Maxima process buffer
1439 (defvar maxima-preamble-fontlock t
)
1441 (defun maxima-match-preamble (limit)
1442 "Used to fontify the preamble."
1443 (if maxima-preamble-fontlock
1445 (setq maxima-preamble-fontlock nil
)
1446 (let ((beg (point-min))
1448 (if (search-forward "(%i1)" limit
)
1451 (setq end
(maxima-line-end-position))
1452 (store-match-data (list beg end
))
1456 (defvar inferior-maxima-font-lock-keywords-1
1457 (append maxima-font-lock-keywords-1
1458 '((maxima-match-preamble (0 font-lock-string-face t t
)))))
1460 (defvar inferior-maxima-font-lock-keywords-2
1461 (append maxima-font-lock-keywords-2
1462 '((maxima-match-preamble (0 font-lock-string-face t t
)))))
1464 (defvar inferior-maxima-font-lock-keywords-3
1465 (append maxima-font-lock-keywords-3
1466 '((maxima-match-preamble (0 font-lock-string-face t t
)))))
1468 (defvar inferior-maxima-font-lock-keywords inferior-maxima-font-lock-keywords-3
1469 "Default expressions to highlight in Maxima mode.")
1471 (defun inferior-maxima-font-setup ()
1472 (make-local-variable 'font-lock-defaults
)
1473 (setq font-lock-defaults
1474 '((inferior-maxima-font-lock-keywords inferior-maxima-font-lock-keywords-1
1475 inferior-maxima-font-lock-keywords-2 inferior-maxima-font-lock-keywords-3
)
1478 ;;; now for the symbols
1480 (defvar maxima-symbols
1482 (lambda (x) (list x
))
1503 ;;; end of maxima-font-lock.el