Sublime Forum

Matlab octfun snippet

#1

Hi all, one common inconvenience I encounter when working with Matlab .m files is one of the autocompletion snippets. Matlab has a couple of quirks - newlines can serve as the end of a statement, and a space can be used to delimit string arguments i.e. “hold(‘on’);” does the same thing as “hold on\n”. Where this is problematic is that it’s a common pattern to write code like

figure
plot(...)
hold on
plot(...)

But the keyword ‘on’ triggers the snippet ‘octfun’ and then pressing enter to end the statement activates it. This snippet is a particularly odd one that consists mostly of comments! So what you end up getting is

figure
plot(...)
hold ## Copyright (C)  
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; If not, see <http://www.gnu.org/licenses/>.

## -*- texinfo -*-
## @deftypefn {Function File} {Outputs = } Function Name (Input Arguments)
## Short Description
##
## Long Description
##
## @seealso{functions
## @end deftypefn

## Author:  



endfunction

Is there really a usage case for this snippet? It’s especially strange because “#” isn’t even the comment character for Matlab/Octave. Perhaps it could be removed? As far as I can tell, it comes preloaded with Sublime (on my Mac, it’s contained within “Sublime Text.app” rather than in Application Support"). Alternatively, is there a way to disable this snippet via a config?

Thanks!

0 Likes

#2

Compare https://github.com/sublimehq/Packages/tree/master/Matlab/Snippets

You could send a pull request to change the snippets.

0 Likes

#3

Just to borrow a comment I made on another similar post about default snippet names:

To alter this, I would recommend getting the addon PackageResourceViewer. This gives you the ability to go into any currently loaded package through the quick bar, open a resource, and then edit it. When you do this (say for instance, you wanted to make it such that you needed to type constant instead of con) you are able to save this and it will override the default behavior for this snippet.

Hope that helps.

0 Likes