├── LICENSE ├── README.md ├── grammars ├── m.cson └── octave.cson ├── highlighting-test.m ├── package.json ├── settings └── language-matlab-octave.cson └── snippets └── language-matlab-octave.cson /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 David S. Price 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Atom.io Package for MATLAB and Octave Language Support 2 | 3 | ## Version 1.0.0+ Major Update 4 | **Breaking change:** as of v1 release August 2019, migrated MATLAB grammar source from TextMate to official MATLAB support mathworks/MATLAB-Language-grammar. This fixed many reported issues and improved MATLAB highlighting to match official [github/linguist](https://github.com/github/linguist) used on Github.com. 5 | 6 | Octave grammar source remains unchanged. 7 | 8 | ### Octave language support (v0.2.0+) 9 | Octave grammar is converted from TextMate Bundle and remains unchanged from v0 to v1. Last update was v0.2. See: 10 | https://github.com/textmate/matlab.tmbundle 11 | 12 | ### MATLAB language Support (v1.0.0+) 13 | The syntax highlighting comes from the MathWorks TextMate grammar: 14 | https://github.com/mathworks/MATLAB-Language-grammar 15 | 16 | #### Commit Hash: MATLAB-Language-grammar used for current grammar version 17 | https://github.com/mathworks/MATLAB-Language-grammar/tree/40d9a0cd3b628f80cdcf948bbe1747a527ed5dd5 18 | 19 | #### Screenshot Example: preview of included file `highlighting-test.m`_ 20 | ![language-matlab-octave-highlighting](https://user-images.githubusercontent.com/43882944/61577281-29e12680-aab3-11e9-900d-527a0afa8e37.png) 21 | 22 | 23 | ## Process for Updating MATLAB Grammar 24 | ### Converting the MathWorks TextMate Grammar 25 | 1. Clone, convert, and update the grammar: 26 | ```bash 27 | git clone git@github.com:mathworks/MATLAB-Language-grammar.git 28 | apm init --package language-matlab-temp --convert MATLAB-Language-grammar/Matlab.tmbundle/ 29 | cp language-matlab-temp/grammars/matlab.cson language-matlab-octave/grammars/m.cson 30 | ``` 31 | 32 | 1. Apply an Atom-specific patch to the file `language-matlab-octave/grammars/m.cson`: 33 | * Change `name: "meta.class.matlab"` to `name: ""`. This prevents atom from improperly coloring all class contents. 34 | 35 | 1. Re-add function highlighting into updated `language-matlab-octave/grammars/m.cson`: 36 | * MATLAB-Language-grammar does not highlight MATLAB functions exactly like the TextMate grammar. If you view the diff of the newly generated `language-matlab-octave/grammars/m.cson`, you'll see the functions to add back. 37 | * For convenience, these are included as reference in `language-matlab-octave/grammars/functions-reference.cson`. Use this file to update `patterns:` and `repository:` sections of the new `m.cson`. 38 | 39 | ### Testing/Verifying Grammar Changes 40 | See the MATLAB file `highlighting-test.m` for MATLAB code snippets to test syntax highlighting changes. Supposing you've updated `grammars/m.cson` you can test your changes by doing the following: 41 | ```bash 42 | cd your-repo-clone 43 | apm remove language-matlab-octave 44 | apm link . 45 | atom . 46 | ``` 47 | Open `highlighting-test.m` and ensure that the syntax highlighting is as desired. If you fix something specific, consider adding a code snippet to that file locking down your change for future testing. 48 | -------------------------------------------------------------------------------- /grammars/octave.cson: -------------------------------------------------------------------------------- 1 | fileTypes: [ 2 | "m" 3 | ] 4 | name: "Octave" 5 | patterns: [ 6 | { 7 | begin: ''' 8 | (?x) 9 | (?=function\\b) # borrowed from ruby bundle 10 | (?<=^|\\s)(function)\\s+ # the function keyword 11 | (?>\\[(.*)\\])?\\t# match various different combination of output arguments 12 | ((?>[a-zA-Z_]\\w*))? 13 | (?>\\s*=\\s*)? 14 | ((?>[a-zA-Z_]\\w*(?>[?!]|=(?!>))? )) # the function name 15 | (?=[ \\t]*[^\\s%|#]) # make sure arguments and not a comment follow 16 | \\s*(\\() # the opening parenthesis for arguments 17 | ''' 18 | beginCaptures: 19 | "1": 20 | name: "storage.type.octave" 21 | "2": 22 | name: "variable.parameter.output.function.octave" 23 | "3": 24 | name: "variable.parameter.output.function.octave" 25 | "4": 26 | name: "entity.name.function.octave" 27 | contentName: "variable.parameter.input.function.octave" 28 | end: "\\)" 29 | endCaptures: 30 | "0": 31 | name: "punctuation.definition.parameters.octave" 32 | name: "meta.function.with-arguments.octave" 33 | } 34 | { 35 | captures: 36 | "1": 37 | name: "storage.type.octave" 38 | "2": 39 | name: "variable.parameter.output.function.octave" 40 | "3": 41 | name: "variable.parameter.output.function.octave" 42 | "4": 43 | name: "entity.name.function.octave" 44 | match: ''' 45 | (?x) 46 | (?=function\\b) # borrowed from ruby bundle 47 | (?<=^|\\s)(function)\\s+ # the function keyword 48 | (?>\\[(.*)\\])? # match various different combination of output arguments 49 | ((?>[a-zA-Z_]\\w*))? 50 | (?>\\s*=\\s*)? 51 | ((?>[a-zA-Z_]\\w*(?>[?!]|=(?!>))? )) # the function name 52 | ''' 53 | name: "meta.function.without-arguments.octave" 54 | } 55 | { 56 | include: "#constants_override" 57 | } 58 | { 59 | include: "#brackets" 60 | } 61 | { 62 | include: "#curlybrackets" 63 | } 64 | { 65 | include: "#parens" 66 | } 67 | { 68 | include: "#string" 69 | } 70 | { 71 | include: "#string_double" 72 | } 73 | { 74 | include: "#transpose" 75 | } 76 | { 77 | include: "#double_quote" 78 | } 79 | { 80 | include: "#operators" 81 | } 82 | { 83 | include: "#all_octave_keywords" 84 | } 85 | { 86 | include: "#all_octave_comments" 87 | } 88 | { 89 | include: "#number" 90 | } 91 | { 92 | include: "#variable" 93 | } 94 | { 95 | include: "#variable_invalid" 96 | } 97 | { 98 | include: "#not_equal_invalid" 99 | } 100 | { 101 | include: "#variable_assignment" 102 | } 103 | ] 104 | repository: 105 | all_octave_comments: 106 | patterns: [ 107 | { 108 | begin: "(^[ \\t]+)?(?=%%)" 109 | beginCaptures: 110 | "1": 111 | name: "punctuation.whitespace.comment.leading.octave" 112 | end: "(?!\\G)" 113 | patterns: [ 114 | { 115 | begin: "%%" 116 | beginCaptures: 117 | "0": 118 | name: "punctuation.definition.comment.octave" 119 | end: "\\n" 120 | name: "comment.line.double-percentage.octave" 121 | } 122 | ] 123 | } 124 | { 125 | begin: "%\\{" 126 | captures: 127 | "1": 128 | name: "punctuation.definition.comment.octave" 129 | end: "%\\}" 130 | name: "comment.block.percentage.octave" 131 | } 132 | { 133 | begin: "(^[ \\t]+)?(?=%)" 134 | beginCaptures: 135 | "1": 136 | name: "punctuation.whitespace.comment.leading.octave" 137 | end: "(?!\\G)" 138 | patterns: [ 139 | { 140 | begin: "%" 141 | beginCaptures: 142 | "0": 143 | name: "punctuation.definition.comment.octave" 144 | end: "\\n" 145 | name: "comment.line.percentage.octave" 146 | } 147 | ] 148 | } 149 | { 150 | begin: "(^[ \\t]+)?(?=#)" 151 | beginCaptures: 152 | "1": 153 | name: "punctuation.whitespace.comment.leading.octave" 154 | end: "(?!\\G)" 155 | patterns: [ 156 | { 157 | begin: "#" 158 | beginCaptures: 159 | "0": 160 | name: "punctuation.definition.comment.octave" 161 | end: "\\n" 162 | name: "comment.line.number-sign.octave" 163 | } 164 | ] 165 | } 166 | ] 167 | all_octave_keywords: 168 | patterns: [ 169 | { 170 | include: "#octave_keyword_control" 171 | } 172 | { 173 | include: "#octave_constant_language" 174 | } 175 | { 176 | include: "#octave_storage_control" 177 | } 178 | { 179 | include: "#octave_support_function" 180 | } 181 | { 182 | include: "#octave_support_external" 183 | } 184 | ] 185 | allofem: 186 | patterns: [ 187 | { 188 | include: "#parens" 189 | } 190 | { 191 | include: "#curlybrackets" 192 | } 193 | { 194 | include: "#end_in_parens" 195 | } 196 | { 197 | include: "#brackets" 198 | } 199 | { 200 | include: "#string" 201 | } 202 | { 203 | include: "#string_double" 204 | } 205 | { 206 | include: "#transpose" 207 | } 208 | { 209 | include: "#all_octave_keywords" 210 | } 211 | { 212 | include: "#all_octave_comments" 213 | } 214 | { 215 | include: "#variable" 216 | } 217 | { 218 | include: "#variable_invalid" 219 | } 220 | { 221 | include: "#number" 222 | } 223 | { 224 | include: "#operators" 225 | } 226 | ] 227 | brackets: 228 | begin: "\\[" 229 | beginCaptures: 230 | "0": 231 | name: "meta.brackets.octave" 232 | contentName: "meta.brackets.octave" 233 | end: "\\]" 234 | endCaptures: 235 | "0": 236 | name: "meta.brackets.octave" 237 | patterns: [ 238 | { 239 | include: "#allofem" 240 | } 241 | ] 242 | constants_override: 243 | comment: "The user is trying to override MATLAB constants and functions." 244 | match: "(^|\\;)\\s*(i|j|inf|Inf|nan|NaN|eps|end)\\s*=[^=]" 245 | name: "meta.inappropriate.octave" 246 | curlybrackets: 247 | begin: "\\{" 248 | beginCaptures: 249 | "0": 250 | name: "meta.brackets.curly.octave" 251 | contentName: "meta.brackets.curly.octave" 252 | end: "\\}" 253 | endCaptures: 254 | "0": 255 | name: "meta.brackets.curly.octave" 256 | patterns: [ 257 | { 258 | include: "#allofem" 259 | } 260 | { 261 | include: "#end_in_parens" 262 | } 263 | ] 264 | end_in_parens: 265 | comment: "end as operator symbol" 266 | match: "\\bend\\b" 267 | name: "keyword.operator.symbols.octave" 268 | escaped_quote: 269 | patterns: [ 270 | { 271 | match: "''" 272 | name: "constant.character.escape.octave" 273 | } 274 | ] 275 | not_equal_invalid: 276 | comment: "Not equal is written ~= not !=." 277 | match: "\\s*!=\\s*" 278 | name: "invalid.illegal.invalid-inequality.octave" 279 | number: 280 | comment: "Valid numbers: 1, .1, 1.1, .1e1, 1.1e1, 1e1, 1i, 1j, 1e2j" 281 | match: "(?<=[\\s\\-\\+\\*\\/\\\\=:\\[\\(\\{,]|^)\\d*\\.?\\d+([eE][+-]?\\d)?([0-9&&[^\\.]])*(i|j)?\\b" 282 | name: "constant.numeric.octave" 283 | octave_constant_language: 284 | comment: "MATLAB constants" 285 | match: "\\b(argv|e|eps|false|F_DUPFD|F_GETFD|F_GETFL|filesep|F_SETFD|F_SETFL|i|I|inf|Inf|j|J|NA|nan|NaN|O_APPEND|O_ASYNC|O_CREAT|OCTAVE_HOME|OCTAVE_VERSION|O_EXCL|O_NONBLOCK|O_RDONLY|O_RDWR|O_SYNC|O_TRUNC|O_WRONLY|pi|program_invocation_name|program_name|P_tmpdir|realmax|realmin|SEEK_CUR|SEEK_END|SEEK_SET|SIG|stderr|stdin|stdout|true|ans|automatic_replot|beep_on_error|completion_append_char|crash_dumps_octave_core|current_script_file_name|debug_on_error|debug_on_interrupt|debug_on_warning|debug_symtab_lookups|DEFAULT_EXEC_PATH|DEFAULT_LOADPATH|default_save_format|echo_executing_commands|EDITOR|EXEC_PATH|FFTW_WISDOM_PROGRAM|fixed_point_format|gnuplot_binary|gnuplot_command_axes|gnuplot_command_end|gnuplot_command_plot|gnuplot_command_replot|gnuplot_command_splot|gnuplot_command_title|gnuplot_command_using|gnuplot_command_with|gnuplot_has_frames|history_file|history_size|ignore_function_time_stamp|IMAGEPATH|INFO_FILE|INFO_PROGRAM|__kluge_procbuf_delay__|LOADPATH|MAKEINFO_PROGRAM|max_recursion_depth|octave_core_file_format|octave_core_file_limit|octave_core_file_name|output_max_field_width|output_precision|page_output_immediately|PAGER|page_screen_output|print_answer_id_name|print_empty_dimensions|print_rhs_assign_val|PS1|PS2|PS4|save_header_format_string|save_precision|saving_history|sighup_dumps_octave_core|sigterm_dumps_octave_core|silent_functions|split_long_rows|string_fill_char|struct_levels_to_print|suppress_verbose_help_message|variables_can_hide_functions|warn_assign_as_truth_value|warn_divide_by_zero|warn_empty_list_elements|warn_fortran_indexing|warn_function_name_clash|warn_future_time_stamp|warn_imag_to_real|warn_matlab_incompatible|warn_missing_semicolon|warn_neg_dim_as_zero|warn_num_to_str|warn_precedence_change|warn_reload_forces_clear|warn_resize_on_range_error|warn_separator_insert|warn_single_quote_string|warn_str_to_num|warn_undefined_return_values|warn_variable_switch_label|whos_line_format)\\b" 286 | name: "constant.language.octave" 287 | octave_keyword_control: 288 | comment: "Control keywords" 289 | match: "(?=|>|<=|<|=|&|&&|:|\\||\\|\\||\\+|-|\\*|\\.\\*|/|\\./|\\\\|\\.\\\\|\\^|\\.\\^|!)\\s*" 306 | name: "keyword.operator.symbols.octave" 307 | parens: 308 | begin: "\\(" 309 | beginCaptures: 310 | "0": 311 | name: "meta.parens.octave" 312 | contentName: "meta.parens.octave" 313 | end: "\\)" 314 | endCaptures: 315 | "0": 316 | name: "meta.parens.octave" 317 | patterns: [ 318 | { 319 | include: "#allofem" 320 | } 321 | { 322 | include: "#end_in_parens" 323 | } 324 | ] 325 | special_characters: 326 | comment: "Operator symbols" 327 | match: "((\\%([\\+\\-0]?\\d{0,3}(\\.\\d{1,3})?)(c|d|e|E|f|g|G|s|((b|t)?(o|u|x|X))))|\\%\\%|\\\\(b|f|n|r|t|\\\\))" 328 | name: "constant.character.escape.octave" 329 | string: 330 | begin: "((?<=(\\[|\\(|\\{|=|\\s|,|;))|^)'" 331 | beginCaptures: 332 | "0": 333 | name: "punctuation.definition.string.begin.octave" 334 | end: "'(?=(\\]|\\)|\\}|=|~|<|>|&|\\||-|\\+|\\*|\\.|\\^|\\||\\s|;|,))" 335 | endCaptures: 336 | "0": 337 | name: "punctuation.definition.string.end.octave" 338 | name: "string.quoted.single.octave" 339 | patterns: [ 340 | { 341 | include: "#escaped_quote" 342 | } 343 | { 344 | include: "#unescaped_quote" 345 | } 346 | { 347 | include: "#special_characters" 348 | } 349 | ] 350 | string_double: 351 | begin: "((?<=(\\[|\\(|\\{|=|\\s|;|:|,))|^)\"" 352 | beginCaptures: 353 | "0": 354 | name: "punctuation.definition.string.begin.octave" 355 | end: "\"(?=(\\]|\\)|\\}|=|~|<|>|&|\\||-|\\+|\\*|\\.|\\^|\\||\\s|;|:|,))" 356 | endCaptures: 357 | "0": 358 | name: "punctuation.definition.string.end.octave" 359 | name: "string.quoted.double.octave" 360 | patterns: [ 361 | { 362 | include: "#escaped_quote" 363 | } 364 | { 365 | include: "#unescaped_quote" 366 | } 367 | { 368 | include: "#special_characters" 369 | } 370 | ] 371 | transpose: 372 | match: "((\\w+)|(?<=\\])|(?<=\\)))\\.?'" 373 | name: "keyword.operator.transpose.octave" 374 | unescaped_quote: 375 | patterns: [ 376 | { 377 | match: "'(?=.)" 378 | name: "invalid.illegal.unescaped-quote.octave" 379 | } 380 | ] 381 | variable: 382 | comment: "Valid variable." 383 | match: "\\b[a-zA-Z]\\w*\\b" 384 | name: "variable.other.valid.octave" 385 | variable_assignment: 386 | comment: "Incomplete variable assignment." 387 | match: "=\\s*\\.{0,2}\\s*;?\\s*$\\n?" 388 | name: "invalid.illegal.incomplete-variable-assignment.octave" 389 | variable_invalid: 390 | comment: "No variables or function names can start with a number or an underscore." 391 | match: "\\b(_\\w|\\d+[_a-df-zA-DF-Z])\\w*\\b" 392 | name: "invalid.illegal.invalid-variable-name.octave" 393 | scopeName: "source.octave" 394 | -------------------------------------------------------------------------------- /highlighting-test.m: -------------------------------------------------------------------------------- 1 | % 1. Double-quoted strings: https://github.com/JamesRitchie/language-matlab/issues/32 2 | s1 = "a double-quoted string"; 3 | c1 = 'a character array'; 4 | 5 | % 2. %% comment issue: https://github.com/JamesRitchie/language-matlab/issues/28 6 | %% 7 | y = abs(rand(3)); % make sure this isn't a comment line 8 | 9 | % 3. Everything showing up as meta.variable.other.valid.matlab: https://github.com/JamesRitchie/language-matlab/issues/23 10 | someVariable = A\b; 11 | 12 | % 4. Highlighting in monokai-dark: https://github.com/JamesRitchie/language-matlab/issues/15 13 | % This isn't valid syntax inside of a script but it still will highlight for testing 14 | classdef aclass 15 | properties 16 | prop1 17 | prop2 18 | end 19 | methods 20 | function y = someMethod(x) 21 | y = sort(repmat(x,2,3)); 22 | end 23 | end 24 | end 25 | 26 | % 5. fprintf with double quotes: https://github.com/JamesRitchie/language-matlab/issues/10 27 | fprintf(" %d" , decimal) 28 | 29 | % 6. Comment blocks: https://github.com/thedavidprice/language-matlab-octave/issues/14 30 | %{ 31 | disp('Commented block') 32 | %} 33 | 34 | %{/ 35 | disp('Active block') 36 | %} 37 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "language-matlab-octave", 3 | "version": "1.2.0", 4 | "description": "MATLAB grammar support from official Mathworks bundle (used on Github.com). Octave support converted from TextMate.", 5 | "keywords": [ 6 | "MATLAB", 7 | "Octave" 8 | ], 9 | "repository": "https://github.com/thedavidprice/language-matlab-octave", 10 | "license": "MIT", 11 | "engines": { 12 | "atom": ">=1.0.0 <2.0.0" 13 | }, 14 | "dependencies": {} 15 | } 16 | -------------------------------------------------------------------------------- /settings/language-matlab-octave.cson: -------------------------------------------------------------------------------- 1 | ".source.matlab": 2 | editor: 3 | commentStart: "% " 4 | increaseIndentPattern: ''' 5 | (?x)^\\s* 6 | \\b( 7 | function 8 | |if|else|elseif 9 | |switch|case|otherwise 10 | |for|parfor|while 11 | |try|catch 12 | |unwind_protect 13 | |properties|methods 14 | |enumeration|events|arguments 15 | )\\b 16 | ''' 17 | decreaseIndentPattern: "^\\s*\\b(end\\w*|catch|else|elseif|case|otherwise)\\b" 18 | foldEndPattern: "^\\s*(end|return)\\b.*$" 19 | ".source.octave": 20 | editor: 21 | commentStart: "% " 22 | increaseIndentPattern: "^\\s*(catch|else|elseif|for|parfor|function|if|switch|while|try).*" 23 | decreaseIndentPattern: "^\\s*(catch|else|elseif|end|endfunction|endif|endswitch|endwhile|endfor|endparfor|endtry)\\b" 24 | foldEndPattern: "^\\s*(end|return|endfunction|endif|endswitch|endwhile|endfor|endparfor|endtry)\\b.*$" 25 | -------------------------------------------------------------------------------- /snippets/language-matlab-octave.cson: -------------------------------------------------------------------------------- 1 | ".source.matlab": 2 | "Octave function": 3 | prefix: "octfun" 4 | body: ''' 5 | ## Copyright (C) ${TM_YEAR} $TM_FULLNAME 6 | ## 7 | ## This program is free software; you can redistribute it and/or modify 8 | ## it under the terms of the GNU General Public License as published by 9 | ## the Free Software Foundation; either version 2 of the License, or 10 | ## (at your option) any later version. 11 | ## 12 | ## This program is distributed in the hope that it will be useful, 13 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | ## GNU General Public License for more details. 16 | ## 17 | ## You should have received a copy of the GNU General Public License 18 | ## along with this program; If not, see . 19 | 20 | ## -*- texinfo -*- 21 | ## @deftypefn {Function File} {${1:Outputs} = } ${2:Function Name} (${3:Input Arguments) 22 | ## ${4:Short Description} 23 | ## 24 | ## ${5:Long Description} 25 | ## 26 | ## @seealso{${6:functions}} 27 | ## @end deftypefn 28 | 29 | ## Author: $TM_FULLNAME 30 | 31 | $0 32 | 33 | endfunction 34 | ''' 35 | "switch … case … end": 36 | prefix: "switch" 37 | body: ''' 38 | switch ${1:var} 39 | case ${2:'${3:string}'} 40 | $0 41 | `if [[ $TM_USE_OCTAVE -ne '0' ]] 42 | then echo "endswitch" 43 | else 44 | echo "end" 45 | fi` 46 | ''' 47 | "switch … case … otherwise … end": 48 | prefix: "switcho" 49 | body: ''' 50 | switch ${1:var} 51 | case ${2:'${3:string}'} 52 | $4 53 | otherwise 54 | $0 55 | `if [[ $TM_USE_OCTAVE -ne '0' ]] 56 | then echo "endswitch" 57 | else 58 | echo "end" 59 | fi` 60 | ''' 61 | "try … catch … end": 62 | prefix: "try" 63 | body: ''' 64 | try 65 | $1 66 | catch 67 | $0 68 | `if [[ $TM_USE_OCTAVE -ne '0' ]] 69 | then echo "end_try_catch" 70 | else 71 | echo "end" 72 | fi` 73 | ''' 74 | "unwind_protect … cleanup … end": 75 | prefix: "unwind" 76 | body: ''' 77 | unwind_protect 78 | $1 79 | unwnd_protect_cleanup 80 | $0 81 | end_unwind_protect 82 | ''' 83 | ".source.matlab, .source.octave": 84 | "^": 85 | prefix: "^" 86 | body: "^($1) $2" 87 | case: 88 | prefix: "case" 89 | body: ''' 90 | case ${2:'${3:string}'} 91 | $0 92 | ''' 93 | "disp sprintf": 94 | prefix: "dsp" 95 | body: "disp(sprintf('${1:%s}\\\\n'${1/([^%]|%%)*(%.)?.*/(?2:, :\\))/}$2${1/([^%]|%%)*(%.)?.*/(?2:\\))/});" 96 | disp: 97 | prefix: "disp" 98 | body: "disp('${1:Text}');" 99 | dlmwrite: 100 | prefix: "dlmwrite" 101 | body: ''' 102 | dlmwrite('${1:filename}.dat', [${2:variables}], ${3:'${4:delimiter}', '${5:\\t}'}); 103 | $0 104 | ''' 105 | else: 106 | prefix: "else" 107 | body: ''' 108 | else 109 | ${1:body} 110 | ''' 111 | elseif: 112 | prefix: "elseif" 113 | body: ''' 114 | elseif ${1:condition} 115 | $0 116 | ''' 117 | error: 118 | prefix: "error" 119 | body: "error('${1:Description}');" 120 | exp: 121 | prefix: "e" 122 | body: "exp($1) $2" 123 | "for … end cell strings": 124 | prefix: "fors" 125 | body: ''' 126 | for ${1:s} = transpose(${2:strings}(:)); $1 = $1{1}; 127 | $0 128 | `if [[ $TM_USE_OCTAVE -ne '0' ]] 129 | then echo "endfor" 130 | else 131 | echo "end" 132 | fi`; clear $1; 133 | ''' 134 | "for … end": 135 | prefix: "for" 136 | body: ''' 137 | for ${1:ii}=${2:1}${3::${4:n}} 138 | $0 139 | `if [[ $TM_USE_OCTAVE -ne '0' ]] 140 | then echo "endfor" 141 | else 142 | echo "end" 143 | fi` 144 | ''' 145 | fprintf: 146 | prefix: "fpr" 147 | body: "fprintf(${1:fid}, '${2:%s}\\\\n'${2/([^%]|%%)*(%.)?.*/(?2:, :\\);)/}$3${2/([^%]|%%)*(%.)?.*/(?2:\\);)/}" 148 | function: 149 | prefix: "function" 150 | body: ''' 151 | function ${1:out} = ${2:?${TM_FILENAME/\\.m//:f}}(${3:in}) 152 | % ${2/.*/\\U$0/} ${4:Description} 153 | % ${1/.*/\\U$0/} = ${2/.*/\\U$0/}(${6:${3/.*/\\U$0/}}) 154 | % 155 | % ${5:Long description} 156 | 157 | $0 158 | 159 | `if [[ $TM_CLOSE_FUNCTIONS -ne '0' ]] 160 | then 161 | if [[ $TM_USE_OCTAVE -ne '0' ]] 162 | then echo "endfunction" 163 | else 164 | echo "end ${TM_COMMENT_START}function" 165 | fi 166 | fi` 167 | 168 | ''' 169 | get: 170 | prefix: "get" 171 | body: "get(${1:gca},'${2:PropertyName}');" 172 | griddata: 173 | prefix: "griddata" 174 | body: "griddata(${1:xx}, ${2:yy}, ${3:zz}, ${4:xi}, ${5:yi}); " 175 | "if … else …end": 176 | prefix: "ife" 177 | body: ''' 178 | if ${1:condition} 179 | $2 180 | else 181 | $3 182 | `if [[ $TM_USE_OCTAVE -ne '0' ]] 183 | then echo "endif" 184 | else 185 | echo "end" 186 | fi` 187 | ''' 188 | "if … elseif … end": 189 | prefix: "ifeif" 190 | body: ''' 191 | if ${1:condition} 192 | ${2:body} 193 | elseif ${3:condition} 194 | ${4:body} 195 | else 196 | ${5:body} 197 | end 198 | 199 | ''' 200 | "if … end": 201 | prefix: "if" 202 | body: ''' 203 | if ${1:condition} 204 | $0 205 | `if [[ $TM_USE_OCTAVE -ne '0' ]] 206 | then echo "endif" 207 | else 208 | echo "end" 209 | fi` 210 | ''' 211 | line: 212 | prefix: "line" 213 | body: ''' 214 | line(${1:xvector},${2:yvector}${3:,'Color','${4:b}','LineWidth',${5:1},'LineStyle','${6:-}'}) 215 | 216 | ''' 217 | nargchk: 218 | prefix: "nargchk" 219 | body: ''' 220 | error(nargchk(${1:min}, ${2:max}, ${3:nargin}, `if [[ $TM_USE_OCTAVE -eq '0' ]]; then 221 | echo -n "'struct'" 222 | fi` )); 223 | 224 | ''' 225 | set: 226 | prefix: "set" 227 | body: "set(${1:get(${2:gca},'${3:PropertyName}')},'${4:PropertyName}',${5:PropertyValue});" 228 | "small function": 229 | prefix: "f" 230 | body: ''' 231 | function ${1:out} = ${2:f}(${3:in}) 232 | $0 233 | `if [[ $TM_CLOSE_FUNCTIONS -ne '0' ]] 234 | then 235 | if [[ $TM_USE_OCTAVE -ne '0' ]] 236 | then echo "endfunction" 237 | else 238 | echo "end" 239 | fi 240 | fi` 241 | ''' 242 | sprintf: 243 | prefix: "spr" 244 | body: "sprintf('${1:%s}\\\\n'${1/([^%]|%%)*(%.)?.*/(?2:, :\\);)/}$2${1/([^%]|%%)*(%.)?.*/(?2:\\);)/}" 245 | title: 246 | prefix: "zla" 247 | body: "set(get(gca,'Title'),'String',${1:'${2}'});" 248 | unix: 249 | prefix: "uni" 250 | body: "[${1:s},${2:w}] = unix('${3:Unix commands}');" 251 | warning: 252 | prefix: "war" 253 | body: "warning(['${1:Description}']);" 254 | while: 255 | prefix: "whi" 256 | body: ''' 257 | while ${1:condition} 258 | ${2:body} 259 | end 260 | 261 | ''' 262 | xlabel: 263 | prefix: "xla" 264 | body: "set(get(gca,'XLabel'),'String',${1:'${2}'});" 265 | xtick: 266 | prefix: "xti" 267 | body: "set(gca,'XTick',${1:[${2}]});" 268 | ylabel: 269 | prefix: "yla" 270 | body: "set(get(gca,'YLabel'),'String',${1:'${2}'});" 271 | ytick: 272 | prefix: "yti" 273 | body: "set(gca,'YTick',${1:[${2}]});" 274 | zlabel: 275 | prefix: "zla" 276 | body: "set(get(gca,'ZLabel'),'String',${1:'${2}'});" 277 | --------------------------------------------------------------------------------