Skip to content

Commit

Permalink
fix: 修复多次重复注释问题,现可多次快速插入注释模块,已有注释不会覆盖
Browse files Browse the repository at this point in the history
  • Loading branch information
cuixing158 committed Mar 16, 2022
1 parent 1eb4b49 commit 40ab209
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 39 deletions.
Binary file modified header.mlappinstall
Binary file not shown.
2 changes: 1 addition & 1 deletion readme.md
Expand Up @@ -7,7 +7,7 @@ First double-click directly on "header.mlappinstall" and then right-click on "Ad

## How to use
1. Open the script m file you want to comment;<br>
1. use the shortcut "alt" + "1" to insert comments for the function or class or type "header" in the command window.<br>
1. use the shortcut "alt" + "1" or click on the "header" icon in the Quick Access toolbar or type "header" in the command window.<br>

## How to modify the template to suit your needs?
Type this on the command line:`edit header.m`,then modify it.<br>
Expand Down
84 changes: 46 additions & 38 deletions src/header.m
Expand Up @@ -89,51 +89,59 @@ function header(authorName,emailAddress,CopyrightOrganization)
preIdx = 1;
for i = 1:numIdxs
currentIdxs = idxSigs{i};
% startIdx = currentIdxs(1);
% startIdx = currentIdxs(1);
endIdx = currentIdxs(end);
preLines = allOriLines(preIdx:endIdx);

% process strings in cell array
patN = ["function","classdef","..."," "];
temp = string(replace(signatures{i},patN,""));
currentSig = temp.strip().join();

% create header template to be inserted
% modify this string to change header template
headerTemplate={sprintf([
'%% Brief: One line description of what the function or class performs\n',...
'%% Details:\n',...
'%% None\n',...
'%% \n',...
'%% Syntax: \n',...
'%% %s\n',... % 1
'%% \n',...
'%% Inputs:\n',...
'%% input1 - [m,n] size,[double] type,Description\n',...
'%% input2 - [m,n] size,[double] type,Description\n',...
'%% input3 - [m,n] size,[double] type,Description\n',...
'%% \n',...
'%% Outputs:\n',...
'%% output1 - [m,n] size,[double] type,Description\n',...
'%% \n',...
'%% Example: \n',...
'%% None\n',...
'%% \n',...
'%% See also: None\n',...
'\n',...
'%% Author: %s\n',... % 2
'%% Email: %s\n',... % 3
'%% Created: %s\n',... % 4
'%% Version history revision notes:\n' ...
'%% None\n',...
'%% Implementation In Matlab R%s\n',... % 5
'%% Copyright © %s %s.All Rights Reserved.\n',...% 6,7
'%%'], currentSig,authorName,emailAddress,string(date),...
version('-release'),string(year(date)),CopyrightOrganization)};% the current date is automatically added
if endIdx+1>length(allOriLines) % last line define "function"
allOriLines = [allOriLines;" "];
end
nearSignatureLine = allOriLines(endIdx+1);
if startsWith(strip(nearSignatureLine),"%")
headerTemplate = [];
else
% process strings in cell array
patN = ["function","classdef","..."," "];
temp = string(replace(signatures{i},patN,""));
currentSig = temp.strip().join();

% create header template to be inserted
% modify this string to change header template
headerTemplate={sprintf([
'%% Brief: One line description of what the function or class performs\n',...
'%% Details:\n',...
'%% None\n',...
'%% \n',...
'%% Syntax: \n',...
'%% %s\n',... % 1
'%% \n',...
'%% Inputs:\n',...
'%% input1 - [m,n] size,[double] type,Description\n',...
'%% input2 - [m,n] size,[double] type,Description\n',...
'%% input3 - [m,n] size,[double] type,Description\n',...
'%% \n',...
'%% Outputs:\n',...
'%% output1 - [m,n] size,[double] type,Description\n',...
'%% \n',...
'%% Example: \n',...
'%% None\n',...
'%% \n',...
'%% See also: None\n',...
'\n',...
'%% Author: %s\n',... % 2
'%% Email: %s\n',... % 3
'%% Created: %s\n',... % 4
'%% Version history revision notes:\n' ...
'%% None\n',...
'%% Implementation In Matlab R%s\n',... % 5
'%% Copyright © %s %s.All Rights Reserved.\n',...% 6,7
'%%'], currentSig,authorName,emailAddress,string(date),...
version('-release'),string(year(date)),CopyrightOrganization)};% the current date is automatically added
end
% insert header template as the second cell in the array of text lines
allDstLines=[allDstLines;preLines;headerTemplate];
preIdx = endIdx+1;

end
if length(allOriLines)>endIdx
allDstLines=[allDstLines;allOriLines(endIdx+1:end)];
Expand Down

0 comments on commit 40ab209

Please sign in to comment.