Add current date when I save a file as a comment

Hi all,
I would like to know if there is a way to add a comment line with the current date when I save a file (inside the file).
For example lets say I have a function called abc.m. After I do some changes and save the file I would like to automatically add sth like (probably on the second line after the name of the function):
function abc() %Last edited 3/1/2015 <-(current date)
Similarly, is there a way to track the changes in my code (sth similar to the track changes of word)?
Thank you in advance, Elric

댓글 수: 3

Chad Greene
Chad Greene 2015년 1월 3일
편집: Chad Greene 2015년 1월 3일
I think you could create a function called savetime(filename) that reads the text of any input filename, then use regexp to find instances of some string like Lastupdate:. At the index of last occurrence of LastUpdate: in filename, insert datestr(now) and then insert a new LastUpdate:, then re-save the .m file with the inserted information.
So for example, savetime('abc.m') would read this function:
function abc()
% abc is a great function.
%
% Update Log:
% LastUpdate: 02-Jan-2015 16:22:04
% LastUpdate:
and then save it as
function abc()
% abc is a great function.
%
% Update Log:
% LastUpdate: 02-Jan-2015 16:22:04
% LastUpdate: 03-Jan-2015 12:15:02
% LastUpdate:
Similarly, you could print the whole contents of the previous version somewhere, perhaps at the end of abc.m or in a change log file of its own.
Elric
Elric 2015년 1월 6일
Hi Chad,
Thanks for you reply. Although what you suggest will work is not very convenient when you work on a very large project with lots of functions and files.
Just hope that this will be included in the future if not already.
7 years later, I also want to do exactly this. Did you find any way?

댓글을 달려면 로그인하십시오.

 채택된 답변

dpb
dpb 2015년 1월 3일

1 개 추천

Within Matlab on it's own automagically, not that I'm aware of. You can use external version control systems w/ Matlab that have the facility.
I've never looked into what abilities there are to customize the builtin editor; for coding "in anger" I use an external editor instead. A search of the help didn't find much useful documentation.

댓글 수: 2

Elric
Elric 2015년 1월 6일
Hi dpb,
Any suggestions for the external editor that you mentiond?
Best,
Elric
dpb
dpb 2015년 1월 7일
I'm still using the old Brief editor which actually must run in a real DOS window so I can't recommend it to anybody else...I've customized it so much over the years and have gotten so used to it I just don't want to change, particularly since I've now retired from coding "in anger" so no longer have to worry about compatibility with clients' newer systems. So, I can't really be of any direct help there, sorry.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

질문:

2015년 1월 3일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by