Separate font-lock keywords that are only for M files, and those that
work fine for files and the shell. matlab.el: (matlab*-font-lock-keywords): Use defconst. (matlab-font-lock-keywords): Rename to: (matlab-basic-font-lock-keywords): New and remove lines to: (matlab-file-basic-font-lock-keywords): New. (matlab-gaudy-font-lock-keywords): Rename to: (matlab-file-gaudy-font-lock-keywords): New and only use keywords for -file- and both. (matlab-mode): Use new named keywords. matlab-shell.el: (matlab*-font-lock-keywords): Use defconst. Use only keywords from matlab.el meant for both files and shell. (matlab-shell-object-output-font-lock-keywords): New
This commit is contained in:
parent
6dbdf778f9
commit
3fd09f43f5
2 changed files with 94 additions and 50 deletions
|
@ -204,10 +204,9 @@ If multiple prompts are seen together, only call this once.")
|
|||
;;; Font Lock
|
||||
;;
|
||||
;; Extra font lock keywords for the MATLAB shell.
|
||||
(defvar matlab-shell-font-lock-keywords
|
||||
(defconst matlab-shell-font-lock-keywords
|
||||
(list
|
||||
;; Startup notices
|
||||
;; Various notices
|
||||
'(" M A T L A B " 0 'underline)
|
||||
'("All Rights Reserved" 0 'italic)
|
||||
'("\\(\\(?:(c)\\)?\\s-+Copyright[^\n]+\\)" 1 font-lock-comment-face)
|
||||
|
@ -233,18 +232,41 @@ If multiple prompts are seen together, only call this once.")
|
|||
"Additional keywords used by MATLAB when reporting errors in interactive\
|
||||
mode.")
|
||||
|
||||
(defvar matlab-shell-font-lock-keywords-1
|
||||
(append matlab-font-lock-keywords matlab-shell-font-lock-keywords)
|
||||
"Keyword symbol used for font-lock mode.")
|
||||
(defconst matlab-shell-font-lock-keywords-1
|
||||
(append matlab-basic-font-lock-keywords
|
||||
matlab-shell-font-lock-keywords)
|
||||
"Keyword symbol used for basic font-lock for MATLAB shell.")
|
||||
|
||||
(defvar matlab-shell-font-lock-keywords-2
|
||||
(append matlab-shell-font-lock-keywords-1 matlab-gaudy-font-lock-keywords)
|
||||
"Keyword symbol used for gaudy font-lock symbols.")
|
||||
(defconst matlab-shell-object-output-font-lock-keywords
|
||||
(list
|
||||
;; disp of objects usually looks like this:
|
||||
'("^\\s-*\\(\\w+\\) with properties:" (1 font-lock-type-face))
|
||||
;; object output - highlight property names after 'with properties:' indicator
|
||||
;; NOTE: Normally a block like this would require us to use `font-lock-multiline' feature
|
||||
;; but since this is shell output, and not a thing you edit, we can skip it and rely
|
||||
;; on matlab-shell dumping the text as a unit.
|
||||
'("^\\s-*\\(\\w+ with properties:\\)\n\\s-*\n"
|
||||
("^\\s-*\\(\\w+\\):[^\n]+$" ;; match the property before the :
|
||||
;; Extend search region across lines.
|
||||
(save-excursion (re-search-forward "\n\\s-*\n" nil t)
|
||||
(beginning-of-line)
|
||||
(point))
|
||||
nil
|
||||
(1 font-lock-variable-name-face)))
|
||||
'("[[{]\\([0-9]+\\(?:x[0-9]+\\)+ \\w+\\)[]}]" (1 font-lock-comment-face))
|
||||
)
|
||||
"Highlight various extra outputs that are typical for MATLAB.")
|
||||
|
||||
(defvar matlab-shell-font-lock-keywords-3
|
||||
(defconst matlab-shell-font-lock-keywords-2
|
||||
(append matlab-shell-font-lock-keywords-1
|
||||
matlab-function-font-lock-keywords
|
||||
matlab-shell-object-output-font-lock-keywords)
|
||||
"Keyword symbol used for gaudy font-lock for MATLAB shell.")
|
||||
|
||||
(defconst matlab-shell-font-lock-keywords-3
|
||||
(append matlab-shell-font-lock-keywords-2
|
||||
matlab-really-gaudy-font-lock-keywords)
|
||||
"Keyword symbol used for really gaudy font-lock symbols.")
|
||||
"Keyword symbol used for really gaudy font-lock for MATLAB shell.")
|
||||
|
||||
;;; ROOT
|
||||
;;
|
||||
|
|
88
matlab.el
88
matlab.el
|
@ -1126,8 +1126,17 @@ Uses `regex-opt' if available. Otherwise creates a 'dumb' expression."
|
|||
(mapconcat (lambda (s) s) keywordlist "\\|"))
|
||||
"\\)\\>"))
|
||||
|
||||
;; font-lock keywords
|
||||
(defvar matlab-font-lock-keywords
|
||||
;;; Font Lock keyword handling
|
||||
;;
|
||||
;; Many parts of the keyword handling are shared with matlab-shell.
|
||||
;; The matlab based variables here are divided up between generic keywords
|
||||
;; and keywords only for M files. This means the M shell won't highlight
|
||||
;; some syntaxes like classdef stuff even though someone might paste them in.
|
||||
;;
|
||||
;; matlab-*-keywords -- MATLAB Files or Shell
|
||||
;; matlab-file-*-keywords -- MATLAB Files only
|
||||
|
||||
(defconst matlab-basic-font-lock-keywords
|
||||
(list
|
||||
;; charvec and string quote chars are also used as transpose, but only if directly
|
||||
;; after characters, numbers, underscores, or closing delimiters.
|
||||
|
@ -1141,15 +1150,36 @@ Uses `regex-opt' if available. Otherwise creates a 'dumb' expression."
|
|||
;; General keywords
|
||||
(list (matlab-font-lock-regexp-opt matlab-keyword-list)
|
||||
'(0 font-lock-keyword-face))
|
||||
;; The end keyword is only a keyword when not used as an array
|
||||
;; dereferencing part.
|
||||
'("\\(^\\|[;,]\\)[ \t]*\\(end\\)\\b"
|
||||
2 (if (matlab-valid-end-construct-p) font-lock-keyword-face nil))
|
||||
;; The global keyword defines some variables. Mark them.
|
||||
'("^\\s-*global\\s-+"
|
||||
("\\(\\w+\\)\\(\\s-*=[^,; \t\n]+\\|[, \t;]+\\|$\\)"
|
||||
nil nil (1 font-lock-variable-name-face)))
|
||||
;; Handle graphics stuff
|
||||
(list
|
||||
(matlab-font-lock-regexp-opt matlab-handle-graphics-list)
|
||||
'(0 font-lock-type-face))
|
||||
(list
|
||||
;; How about a few matlab constants such as pi, infinity, and sqrt(-1)?
|
||||
(matlab-font-lock-regexp-opt matlab-constants-keyword-list)
|
||||
1 font-lock-constant-face)
|
||||
;; Imaginary number support
|
||||
'("\\<[0-9]\\.?\\(i\\|j\\)\\>" 1 font-lock-reference-face)
|
||||
)
|
||||
"Basic Expressions to highlight in MATLAB mode or shell.")
|
||||
|
||||
(defconst matlab-file-basic-font-lock-keywords
|
||||
(append
|
||||
matlab-basic-font-lock-keywords
|
||||
(list
|
||||
;; Keywords that should be the first word on a line
|
||||
(list (concat "^\\s-*\\("
|
||||
(matlab-font-lock-regexp-opt matlab-keyword-first-on-line-list)
|
||||
"\\)")
|
||||
'(1 font-lock-keyword-face))
|
||||
;; The end keyword is only a keyword when not used as an array
|
||||
;; dereferencing part.
|
||||
'("\\(^\\|[;,]\\)[ \t]*\\(end\\)\\b"
|
||||
2 (if (matlab-valid-end-construct-p) font-lock-keyword-face nil))
|
||||
;; How about unreachable code? MUST BE AFTER KEYWORDS in order to
|
||||
;; get double-highlighting.
|
||||
'(matlab-find-unreachable-code
|
||||
|
@ -1172,28 +1202,13 @@ Uses `regex-opt' if available. Otherwise creates a 'dumb' expression."
|
|||
;; Highlight nested function/end keywords
|
||||
'(matlab-font-lock-nested-function-keyword-match
|
||||
(0 matlab-nested-function-keyword-face prepend))
|
||||
;; The global keyword defines some variables. Mark them.
|
||||
'("^\\s-*global\\s-+"
|
||||
("\\(\\w+\\)\\(\\s-*=[^,; \t\n]+\\|[, \t;]+\\|$\\)"
|
||||
nil nil (1 font-lock-variable-name-face)))
|
||||
;; Handle graphics stuff
|
||||
(list
|
||||
(matlab-font-lock-regexp-opt matlab-handle-graphics-list)
|
||||
'(0 font-lock-type-face))
|
||||
(list
|
||||
;; How about a few matlab constants such as pi, infinity, and sqrt(-1)?
|
||||
(matlab-font-lock-regexp-opt matlab-constants-keyword-list)
|
||||
1 font-lock-constant-face)
|
||||
;; Imaginary number support
|
||||
'("\\<[0-9]\\.?\\(i\\|j\\)\\>" 1 font-lock-reference-face)
|
||||
)
|
||||
"Expressions to highlight in MATLAB mode.")
|
||||
|
||||
))
|
||||
"Basic Expressions to highlight in MATLAB Files.")
|
||||
|
||||
(defconst matlab-function-arguments
|
||||
"\\(([^)]*)\\)?\\s-*\\([,;\n%]\\|$\\)")
|
||||
|
||||
(defvar matlab-function-font-lock-keywords
|
||||
(defconst matlab-function-font-lock-keywords
|
||||
(list
|
||||
;; defining a function, a (possibly empty) list of assigned variables,
|
||||
;; function name, and an optional (possibly empty) list of input variables
|
||||
|
@ -1239,7 +1254,7 @@ Uses `regex-opt' if available. Otherwise creates a 'dumb' expression."
|
|||
"\\s-*\\(?2:(\\([^)]+\\))\\|\\)"
|
||||
"Regular expression for matching an attributes block.")
|
||||
|
||||
(defvar matlab-class-font-lock-keywords
|
||||
(defconst matlab-file-class-font-lock-keywords
|
||||
(list
|
||||
;; Classdefs keyword and the class name
|
||||
(list (concat "^\\s-*\\(classdef\\)"
|
||||
|
@ -1273,17 +1288,17 @@ Uses `regex-opt' if available. Otherwise creates a 'dumb' expression."
|
|||
)
|
||||
"List of font-lock keywords used when an MATLAB file contains a class.")
|
||||
|
||||
(defvar matlab-gaudy-font-lock-keywords
|
||||
(defconst matlab-file-gaudy-font-lock-keywords
|
||||
(append
|
||||
matlab-font-lock-keywords
|
||||
matlab-basic-font-lock-keywords
|
||||
matlab-file-basic-font-lock-keywords
|
||||
matlab-function-font-lock-keywords
|
||||
matlab-class-font-lock-keywords
|
||||
matlab-file-class-font-lock-keywords
|
||||
)
|
||||
"Expressions to highlight in MATLAB mode.")
|
||||
|
||||
(defvar matlab-really-gaudy-font-lock-keywords
|
||||
(defconst matlab-really-gaudy-font-lock-keywords
|
||||
(append
|
||||
matlab-gaudy-font-lock-keywords
|
||||
(list
|
||||
;; Since it's a math language, how bout dem symbols?
|
||||
'("\\([<>~]=?\\|\\.[/*^']\\|==\\|\\<xor\\>\\|[-!^&|*+\\/~:]\\)"
|
||||
|
@ -1316,6 +1331,13 @@ Uses `regex-opt' if available. Otherwise creates a 'dumb' expression."
|
|||
))
|
||||
"Expressions to highlight in MATLAB mode.")
|
||||
|
||||
(defconst matlab-file-really-gaudy-font-lock-keywords
|
||||
(append
|
||||
matlab-file-gaudy-font-lock-keywords
|
||||
matlab-really-gaudy-font-lock-keywords
|
||||
)
|
||||
"Expressions to highlight in MATLAB mode.")
|
||||
|
||||
;; Imenu support.
|
||||
(defvar matlab-imenu-generic-expression
|
||||
'((nil "^\\s-*function\\>[ \t\n.]*\\(\\(\\[[^]]*\\]\\|\\sw+\\)[ \t\n.]*\
|
||||
|
@ -1497,9 +1519,9 @@ All Key Bindings:
|
|||
;; give each file it's own parameter history
|
||||
(make-local-variable 'matlab-shell-save-and-go-history)
|
||||
(make-local-variable 'font-lock-defaults)
|
||||
(setq font-lock-defaults '((matlab-font-lock-keywords
|
||||
matlab-gaudy-font-lock-keywords
|
||||
matlab-really-gaudy-font-lock-keywords
|
||||
(setq font-lock-defaults '((matlab-file-font-lock-keywords
|
||||
matlab-file-gaudy-font-lock-keywords
|
||||
matlab-file-really-gaudy-font-lock-keywords
|
||||
)
|
||||
t ; do not do string/comment highlighting
|
||||
nil ; keywords are case sensitive.
|
||||
|
|
Loading…
Reference in a new issue