📄 matlab.el
字号:
(setq b2 (match-beginning 0) e2 (match-end 0)) ;; make sure something exists... (if (not b3) (setq b3 b2 e3 e2))) (error "Eh?")) ;; Ok, build up some match data. (set-match-data (list b1 e2 ;the real deal. b1 e1 ;if (0) b2 e2 ;end b3 e3 ;else (if applicable.) b1 e3)) ;body commented out. t) (error nil)))))(defcustom matlab-keyword-list '("global" "persistent" "for" "while" "if" "elseif" "else" "endfunction" "return" "break" "continue" "switch" "case" "otherwise" "try" "catch" "tic" "toc") "List of keywords for MATLAB used in highlighting.Customizing this variable is only useful if `regexp-opt' is available." :group 'matlab :type '(repeat (string :tag "Keyword: ")))(defcustom matlab-handle-graphics-list '("figure" "axes" "axis" "line" "surface" "patch" "text" "light" "image" "set" "get" "uicontrol" "uimenu" "uitoolbar" "uitoggletool" "uipushtool" "uicontext" "uicontextmenu" "setfont" "setcolor") "List of handle graphics functions used in highlighting.Customizing this variable is only useful if `regexp-opt' is available." :group 'matlab :type '(repeat (string :tag "HG Keyword: ")))(defcustom matlab-debug-list '("dbstop" "dbclear" "dbcont" "dbdown" "dbmex" "dbstack" "dbstatus" "dbstep" "dbtype" "dbup" "dbquit") "List of debug commands used in highlighting.Customizing this variable is only useful if `regexp-opt' is available." :group 'matlab :type '(repeat (string :tag "Debug Keyword: ")));; font-lock keywords(defvar matlab-font-lock-keywords (list ;; String quote chars are also used as transpose, but only if directly ;; after characters, numbers, underscores, or closing delimiters. '(matlab-font-lock-string-match-normal 2 font-lock-string-face) ;; A string with no termination is not currently highlighted. ;; This will show that the string needs some attention. '(matlab-font-lock-string-match-unterminated 2 matlab-unterminated-string-face) ;; Comments must occur after the string, that way we can check to see ;; if the comment start char has occurred inside our string. (EL) '(matlab-font-lock-comment-match 1 font-lock-comment-face) ;; Various pragmas should be in different colors. ;; I think pragmas are always lower case? '("%#\\([a-z]+\\)" (1 'bold prepend)) ;; General keywords (list (if (fboundp 'regexp-opt) (concat "\\<\\(" (regexp-opt matlab-keyword-list) "\\)\\>") ;; Original hard-coded value for pre Emacs 20.1 "\\<\\(break\\|ca\\(se\\|tch\\)\\|e\\(lse\\(\\|if\\)\\|ndfunction\\)\\\|for\\|global\\|if\\|otherwise\\|return\\|switch\\|try\\|while\\|tic\\|toc\\)\\>") '(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)) ;; How about unreachable code? MUsT BE AFTER KEYWORDS in order to ;; get double-highlighting. '(matlab-find-unreachable-code (1 'underline prepend) ;if part (2 'underline prepend) ;end part (3 'underline prepend) ;else part (if applicable) (4 font-lock-comment-face prepend) ;commented out part. ) ;; 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 (if (fboundp 'regexp-opt) (concat "\\<\\(" (regexp-opt matlab-handle-graphics-list) "\\)\\>") ;; The original regular expression for pre Emacs 20.1 "\\<\\(ax\\(es\\|is\\)\\|figure\\|get\\|image\\|li\\(ght\\|ne\\)\\|\patch\\|s\\(et\\(\\|color\\|font\\)\\|urface\\)\\|text\\|\ui\\(cont\\(ext\\(\\|menu\\)\\|rol\\)\\|menu\\|\\\(toggle\\|push\\)tool\\|toolbar\\)\\)\\>") '(0 font-lock-type-face)) ) "Expressions to highlight in MATLAB mode.")(defvar matlab-gaudy-font-lock-keywords (append matlab-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 (list (concat "^\\s-*\\(function\\)\\>[ \t\n.]*" "\\(\\[[^]]*\\]\\|\\sw+\\)[ \t\n.]*" "=[ \t\n.]*\\(\\sw+\\)[ \t\n.]*" "\\(([^)]*)\\)?\\s-*\\([,;\n%]\\|$\\)") '(1 font-lock-keyword-face append) '(2 font-lock-variable-name-face append) '(3 font-lock-function-name-face append)) ;; defining a function, a function name, and an optional (possibly ;; empty) list of input variables (list (concat "^\\s-*\\(function\\)[ \t\n.]+" "\\(\\sw+\\)[ \t\n.]*" "\\(([^)]*)\\)?\\s-*\\([,;\n%]\\|$\\)") '(1 font-lock-keyword-face append) '(2 font-lock-function-name-face append)) ;; Anchor on the function keyword, highlight params (list (concat "^\\s-*function\\>[ \t\n.]*" "\\(\\(\\[[^]]*\\]\\|\\sw+\\)[ \t\n.]*=[ \t\n.]*\\)?" "\\sw+\\s-*(") '("\\s-*\\(\\sw+\\)\\s-*[,)]" nil nil (1 font-lock-variable-name-face))) ;; I like variables for FOR loops '("\\<\\(for\\)\\s-+\\(\\sw+\\)\\s-*=\\s-*\\\(\\([^\n,;%(]+\\|([^\n%)]+)\\)+\\)" (1 font-lock-keyword-face) (2 font-lock-variable-name-face append) (3 font-lock-reference-face append)) ;; Items after a switch statements are cool '("\\<\\(case\\|switch\\)\\s-+\\({[^}\n]+}\\|[^,%\n]+\\)" (1 font-lock-keyword-face) (2 font-lock-reference-face)) ;; How about a few matlab constants such as pi, infinity, and sqrt(-1)? ;; The ^>> is in case I use this in an interactive mode someday '("\\<\\(eps\\|pi\\|inf\\|Inf\\|NaN\\|nan\\|ans\\|i\\|j\\|^>>\\)\\>" 1 font-lock-reference-face) '("\\<[0-9]\\.?\\(i\\|j\\)\\>" 1 font-lock-reference-face) ;; Define these as variables since this is about as close ;; as matlab gets to variables (list (concat "\\<" matlab-indent-past-arg1-functions "\\s-*") '("(\\s-*\\(\\w+\\)\\s-*\\(,\\|)\\)" nil nil (1 font-lock-variable-name-face))) )) "Expressions to highlight in MATLAB mode.")(defvar matlab-really-gaudy-font-lock-keywords (append matlab-gaudy-font-lock-keywords (list ;; Since it's a math language, how bout dem symbols? '("\\([<>~]=?\\|\\.[/*^']\\|==\\|\\<xor\\>\\|[-!^&|*+\\/~:]\\)" 1 font-lock-type-face) ;; How about references in the HELP text. (list (concat "^" matlab-comment-line-s "\\s-*" "\\(\\([A-Z]+\\s-*=\\s-+\\|\\[[^]]+]\\s-*=\\s-+\\|\\)" "\\([A-Z][0-9A-Z]+\\)\\(([^)\n]+)\\| \\)\\)") '(1 font-lock-reference-face prepend)) (list (concat "^" matlab-comment-line-s "\\s-*" "See also\\s-+") '("\\([A-Z][A-Z0-9]+\\)\\([,.]\\| and\\|$\\) *" nil nil (1 font-lock-reference-face prepend))) (list (concat "^" matlab-comment-line-s "\\s-*" "\\(\\$" "Revision" "[^\n$]+\\$\\)") '(1 font-lock-reference-face prepend)) ;; continuation ellipsis. '("[^.]\\(\\.\\.\\.+\\)\\([^\n]*\\)" (1 'underline) (2 font-lock-comment-face)) ;; How about debugging statements? ;;'("\\<\\(db\\sw+\\)\\>" 1 'bold) (list (if (fboundp 'regexp-opt) (concat "\\<\\(" (regexp-opt matlab-debug-list) "\\)\\>") ;; pre-regexp-opt days. "\\<\\(db\\(c\\(lear\\|ont\\)\\|down\\|mex\\|quit\\|\st\\(a\\(ck\\|tus\\)\\|ep\\|op\\)\\|type\\|up\\)\\)\\>") '(0 'bold))) (if matlab-handle-simulink ;; Simulink functions, but only if the user wants it. (list (list (concat "\\<\\(\\([sg]et_param\\|sim\\([gs]et\\)?\\|" "\\(mld\\|ss\\)[A-Z]\\w+\\)\\|" "\\(new\\|open\\|close\\|save\\|find\\)_system\\|" "\\(add\\|delete\\|replace\\)_\\(block\\|line\\)\\|" "simulink\\|bd\\(root\\|close\\)" "\\)\\>") 1 matlab-simulink-keyword-face)) nil)) "Expressions to highlight in MATLAB mode.")(defvar matlab-shell-font-lock-keywords (list ;; How about Errors? '("^\\(Error in\\|Syntax error in\\)\\s-+==>\\s-+\\(.+\\)$" (1 font-lock-comment-face) (2 font-lock-string-face)) ;; and line numbers '("^\\(On line [0-9]+\\)" 1 font-lock-comment-face) ;; User beep things '("\\(\\?\\?\\?[^\n]+\\)" 1 font-lock-comment-face) ;; Useful user commands, but not useful programming constructs '("\\<\\(demo\\|whatsnew\\|info\\|subscribe\\|help\\|doc\\|lookfor\\|what\\\|whos?\\|cd\\|clear\\|load\\|save\\|helpdesk\\|helpwin\\)\\>" 1 font-lock-keyword-face) ;; Various notices '(" M A T L A B " 0 'underline) '("All Rights Reserved" 0 'italic) '("\\((c)\\s-+Copyright[^\n]+\\)" 1 font-lock-comment-face) '("\\(Version\\)\\s-+\\([^\n]+\\)" (1 font-lock-function-name-face) (2 font-lock-variable-name-face)) ) "Additional keywords used by MATLAB when reporting errors in interactive\mode.");; hilit19 patterns(defvar matlab-hilit19-patterns '( ("\\(^\\|[^%]\\)\\(%[ \t].*\\|%\\)$" 2 comment) ("\\(^\\|[;,]\\)[ \t]*\\(\function\\|global\\|for\\|while\\|if\\|elseif\\|else\\|end\\(function\\)?\\\|return\\|switch\\|case\\|otherwise\\|try\\|catch\\)\\b" 2 keyword)));; func-menu support for matlab(defvar fume-function-name-regexp-matlab "^\\s-*function\\>[ \t\n.]*\\(\\(\\[[^]]*\\]\\|\\sw+\\)[ \t\n.]*\=\[ \t\n.]*\\)?\\([a-zA-Z0-9_]+\\)" "Expression to get matlab function/procedure names.");; "The connection between a mode and the regexp that matches function(if (boundp 'fume-function-name-regexp-alist) (add-to-list 'fume-function-name-regexp-alist '(matlab-mode . fume-function-name-regexp-matlab)));;; Specialised routine to find the next MATLAB function or subroutine.(defun fume-find-next-matlab-function-name (buffer) "Searches for the next matlab function in BUFFER." (fume-find-next-sexp buffer))(if (boundp 'fume-function-name-regexp-alist) (add-to-list 'fume-find-function-name-method-alist '(matlab-mode . fume-find-next-matlab-function-name)));; Imenu support. Recycle the expression for fume since they are the;; same, and this reduced code duplication.(defvar matlab-imenu-generic-expression `((nil ,fume-function-name-regexp-matlab 3)) "Expressions which find function headings in MATLAB M files.");;; MATLAB mode entry point ==================================================;;;###autoload(defun matlab-mode () "MATLAB-mode is a major mode for editing MATLAB dot-m files.\\<matlab-mode-map>Convenient editing commands are: \\[matlab-comment-region] - Comment/Uncomment out a region of code. \\[matlab-fill-comment-line] - Fill the current comment line. \\[matlab-fill-region] - Fill code and comments in region. \\[matlab-fill-paragraph] - Refill the current command or comment. \\[matlab-complete-symbol] - Symbol completion of matlab symbols\based on the local syntax.Convenient navigation commands are: \\[matlab-beginning-of-command] - Move to the beginning of a command. \\[matlab-end-of-command] - Move to the end of a command. \\[matlab-beginning-of-defun] - Move to the beginning of a function. \\[matlab-end-of-defun] - Move do the end of a function. \\[matlab-forward-sexp] - Move forward over a syntactic block of code. \\[matlab-backward-sexp] - Move backwards over a syntactic block of code.Convenient template insertion commands: \\[tempo-template-matlab-function] - Insert a function definition. \\[tempo-template-matlab-if] - Insert an IF END block. \\[tempo-template-matlab-for] - Insert a FOR END block. \\[tempo-template-matlab-switch] - Insert a SWITCH END statement. \\[matlab-insert-next-case] - Insert the next CASE condition in a SWITCH. \\[matlab-insert-end-block] - Insert a matched END statement. With \optional ARG, reindent. \\[matlab-stringify-region] - Convert plaintext in region to a string \with correctly quoted chars.Variables: `matlab-indent-level' Level to indent blocks. `matlab-cont-level' Level to indent continuation lines. `matlab-cont-requires-ellipsis' Does your MATLAB support implied elipsis. `matlab-case-level' Level to unindent case statements. `matlab-indent-past-arg1-functions' Regexp of functions to indent past the first argument on continuation lines. `matlab-maximum-indents' List of maximum indents during lineups. `matlab-comment-column' Goal column for on-line comments. `fill-column' Column used in auto-fill. `matlab-indent-function' If non-nil, indents body of MATLAB functions. `matlab-return-function' Customize RET handling with this function `matlab-auto-fill' Non-nil, do auto-fill at startup `matlab-fill-code' Non-nil, auto-fill code. `matlab-fill-strings' Non-nil, auto-fill strings. `matlab-verify-on-save-flag' Non-nil, enable code checks on save `matlab-highlight-block-match-flag' Enable matching block begin/end keywords `matlab-vers-on-startup' If t, show version on start-up. `matlab-handle-simulink' If t, enable simulink keyword highlighting.All Key Bindings:\\{matlab-mode-map}" (interactive) (kill-all-local-variables) (use-local-map matlab-mode-map) (setq major-mode 'matlab-mode) (setq mode-name "MATLAB") (if (boundp 'whitespace-modes) (add-to-list 'whitespace-modes 'matlab-mode)) (setq local-abbrev-table matlab-mode-abbrev-table) (set-syntax-table matlab-mode-syntax-table) (setq indent-tabs-mode nil) (make-local-variable 'indent-line-function) (setq indent-line-function 'matlab-indent-line) (make-local-variable 'paragraph-start) (setq paragraph-start (concat "^$\\|" page-delimiter)) (make-local-variable 'paragraph-separate) (setq paragraph-separate paragraph-start) (make-local-variable 'paragraph-ignore-fill-prefix) (setq paragraph-ignore-fill-prefix t) (make-local-variable 'comment-start-skip) (setq comment-start-skip "%\\s-+") (make-local-variable 'comment-start) (setq comment-start "%") (make-local-variable 'comment-column) (setq comment-column matlab-comment-column) (make-local-variable 'comment-indent-function) (setq comment-indent-function 'matlab-comment-indent) (make-local-variable 'add-log-current-defun-function) (setq add-log-current-defun-function 'matlab-current-defun) (make-local-variable 'fill-column) (setq fill-column default-fill-column) (make-local-variable 'auto-fill-function) (if matlab-auto-fill (setq auto-fill-function 'matlab-auto-fill)) ;; Emacs 20 supports this variable. This lets users turn auto-fill ;; on and off and still get the right fill function. (make-local-variable 'normal-auto-fill-function)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -