A small set of tools for deleting specific comments in MATLAB/Octave code.
- git - required for function
striprepo
Download repository and add src directory to MATLAB's path:
addpath path/to/Matlab-Comment-Stripper
Use striprepo(deletionMark, pathToGitRepo, showProgress)
to delete specified comments from all m-files within git repository at pathToGitRepo (either relative to current or absolute path). Empty pathToGitRepo defaults to current working directory. Argument showProgress different than 0 will print current number of processed files.
striprepo(deletionMark)
is equivalent to striprepo(deletionMark, '', 0)
.
To delete all comments, use empty string explicitly: striprepo('')
Note: if you don't use '%' sign at the beginning of deletionMark, only block comments will be affected.
Assume that this is one of many files in your repository.
% a comment
foo = 'bar'; %?! this one is marked
%{
block comment
%{
%?!
marked and nested block
%}
%}
a = 1 + 2; % one plus two
Use striprepo('%?!')
cut out unwanted comments.
>> [files, errors] = striprepo('%?!')
% a comment
foo = 'bar';
%{
block comment
%}
a = 1 + 2; % one plus two
Use striprepo('')
to get rid of all the comments:
>> [files, errors] = striprepo('')
There is not a single comment in any of your files now.
foo = 'bar';
a = 1 + 2;
Use stripfile(deletionMark, inputFile)
to delete specified comments from a file.
Use stripfile(deletionMark, inputFile, outputFile)
to write result to another file.
Let's say your working directory is /home/project/src
and you also have /home/project/copy
directory. You can make a copy of a file and drop some comments.
The file at /home/project/src
:
% hello
foo = 'bar'; %@ temp comment
>> [status, errorMsg] = stripfile('%@', 'file.m', '../copy/filecopy.m')
The file at /home/project/copy
:
% hello
foo = 'bar';
See function descriptions for more info.
Peter John Acklam - main regular expression is based on the one used in % MATLAB Comment Stripping Toolbox