Home Download Buy Blog Forum Support

Automatically add file header plugin

Automatically add file header plugin

Postby fjctlzy on Mon Nov 26, 2012 3:56 am

hi, all

this is my first time writing sublime text2 plugin, and don't know any rules writing it, please feel free to give me any suggestion.

the plugin ZyFileheader(https://github.com/fjctlzy/ZyFileheader) is a plugin of Sublime Text2 which helps to add file header like

{
#!/usr/bin/env python
# -*- coding:utf-8 -*-
#*********************************************************#
# @@ScriptName: a.py
# @@Author: Your name here<Your email here>
# @@Create Date: 2012-11-25 22:24:14
# @@Modify Date: 2012-11-25 22:24:34
# @@Function:
#*********************************************************#
}
to your new created file, and you could define the header for yourself.
The scriptName will change if your save as file(CTRL+SHIFT+S) in sublimetext.
The modify date will change each time your press CTRL+S
A new line will be append to the end of file if not exists

I hope you like it.
fjctlzy
 
Posts: 12
Joined: Mon Feb 06, 2012 8:16 am

Re: Automatically add file header plugin

Postby Eduan on Thu Nov 29, 2012 11:54 pm

Seems like a great idea! I no longer use Sublime Text, but it's a great idea nonetheless, very useful for Grease Monkey scripts. :)

- Eduan
Check out my blog and website: EduanTech.com (currently undergoing some facial and organs makeover...)
Also check out my profiles: GitHub - Greduan | BitBucket - Greduan
Eduan
 
Posts: 140
Joined: Sun Oct 14, 2012 4:05 pm

Re: Automatically add file header plugin

Postby highend on Sun Dec 02, 2012 10:50 pm

May I ask for a few feature requests?

1.) It would be nice if we could define different file_header_format templates.
Maybe with some type of scope so that they can be automatically applied to a file with a specific extension.

E.g.:
Code: Select all
"file_header_format.xys": "/**********************************************************#\n# @@ScriptName: \n# @@Author: @@author <@@email>\n# @@Create Date:\n# @@Modify Date: \n# @@Function:\n#**********************************************************/",


.xys files are script files for XYplorer (a Windows file manager) and comment blocks are created inside
Code: Select all
/* ... */
regions.

So a normal ctrl+1 would insert that template if I'm working inside a .xys file...

2.) Can you "reorganize" your settings that should be placed inside the Preferences.sublime-settings file?
Something like this:

Code: Select all
{
   "zyfileheader":
   {
       "ignore_files": ["zy_file_header.py", "default.sublime-settings", "Preferences.sublime-settings"],
       "file_header_format": "#*********************************************************#\n# @@ScriptName: \n# @@Author: @@author<@@email>\n# @@Create Date:\n# @@Modify Date: \n# @@Function:\n#*********************************************************#",
       "python": "#!/usr/bin/env python\n# -*- coding:utf-8 -*-",
       "shell" : "#!/usr/bin/env bash",
       "author" : "Your name here",
       "email" : "Your email here"
    }
}

Otherwise all the different settings will be resorted (alphabetically) when the Preferences.sublime-settings file get's rewritten, which makes it hard to edit those settings afterwards.

3.) Can we get an option to not insert a template automatically when a new file is created (via ctrl+n)?

4.) It would be nice if we could redefine the time format for created and modified date (globally or for every template).
E.g. in Germany we use: DD.MM.YYYY HH:MM:SS

Regards,
Highend
highend
 
Posts: 94
Joined: Fri Jan 20, 2012 2:47 pm

Re: Automatically add file header plugin

Postby fjctlzy on Tue Dec 04, 2012 4:59 am

Thanks for you reply, and I will implement 2),3) and 4) first as they are easier, and 1) will be implemented later, as it's a bit harder...


highend wrote:May I ask for a few feature requests?

1.) It would be nice if we could define different file_header_format templates.
Maybe with some type of scope so that they can be automatically applied to a file with a specific extension.

E.g.:
Code: Select all
"file_header_format.xys": "/**********************************************************#\n# @@ScriptName: \n# @@Author: @@author <@@email>\n# @@Create Date:\n# @@Modify Date: \n# @@Function:\n#**********************************************************/",


.xys files are script files for XYplorer (a Windows file manager) and comment blocks are created inside
Code: Select all
/* ... */
regions.

So a normal ctrl+1 would insert that template if I'm working inside a .xys file...

2.) Can you "reorganize" your settings that should be placed inside the Preferences.sublime-settings file?
Something like this:

Code: Select all
{
   "zyfileheader":
   {
       "ignore_files": ["zy_file_header.py", "default.sublime-settings", "Preferences.sublime-settings"],
       "file_header_format": "#*********************************************************#\n# @@ScriptName: \n# @@Author: @@author<@@email>\n# @@Create Date:\n# @@Modify Date: \n# @@Function:\n#*********************************************************#",
       "python": "#!/usr/bin/env python\n# -*- coding:utf-8 -*-",
       "shell" : "#!/usr/bin/env bash",
       "author" : "Your name here",
       "email" : "Your email here"
    }
}

Otherwise all the different settings will be resorted (alphabetically) when the Preferences.sublime-settings file get's rewritten, which makes it hard to edit those settings afterwards.

3.) Can we get an option to not insert a template automatically when a new file is created (via ctrl+n)?

4.) It would be nice if we could redefine the time format for created and modified date (globally or for every template).
E.g. in Germany we use: DD.MM.YYYY HH:MM:SS

Regards,
Highend
fjctlzy
 
Posts: 12
Joined: Mon Feb 06, 2012 8:16 am

Re: Automatically add file header plugin

Postby fjctlzy on Tue Dec 04, 2012 7:28 am

hi, 2), 3), and 4) features are added, you could see the feature list now.

Features
Modify Date will change each time you save(CTRL+S) the file
ScriptName will change each time you save as(CTRL+SHIFT+S) the file
CTRL + 1 could add defined header to your current file which has no header
Custom time format, using Python datetime format, please refer to
CTRL + 1 will use file ctime as @@Create Date for existed file
You could set add_on_created to false so that when file is created, the header won't be added automatically
fjctlzy
 
Posts: 12
Joined: Mon Feb 06, 2012 8:16 am

Re: Automatically add file header plugin

Postby highend on Tue Dec 04, 2012 7:58 am

hi, 2), 3), and 4) features are added, you could see the feature list now.


Thanks a lot, all changes are working fine so far :) Hope we can see the scope addition anytime in the new future.
Regards,
Highend
highend
 
Posts: 94
Joined: Fri Jan 20, 2012 2:47 pm

Re: Automatically add file header plugin

Postby fjctlzy on Tue Dec 04, 2012 8:07 am

Multiple header formats is supported now, please check out and have a try...But add_on_created should be set to false, let me know if you have any issues.


"zy_file_header" : {
"add_on_created": true,
"file_header_format": "#*********************************************************#\n# @@ScriptName: \n# @@Author: @@author<@@email>\n# @@Create Date:\n# @@Modify Date: \n# @@Function:\n#*********************************************************#",
"file_header_format.php": "/*********************************************************#\n# @@ScriptName: \n# @@Author: @@author<@@email>\n# @@Create Date:\n# @@Modify Date: \n# @@Function:\n#*********************************************************/",
"file_header_format.c": "/*********************************************************#\n# @@ScriptName: \n# @@Author: @@author<@@email>\n# @@Create Date:\n# @@Modify Date: \n# @@Function:\n#*********************************************************/",
"python": "#!/usr/bin/env python\n# -*- coding:utf-8 -*-",
"shell": "#!/usr/bin/env bash",
"author": "your name here",
"email": "your email here",
"time_format": "%Y-%m-%d %H:%M:%S",
"ignore_files":
[
".*.sublime.*",
"README",
".*.sublime-settings",
"zy_file_header.py"
]
}
fjctlzy
 
Posts: 12
Joined: Mon Feb 06, 2012 8:16 am

Re: Automatically add file header plugin

Postby highend on Tue Dec 04, 2012 10:16 am

Thanks for the fast implementation.

I have one small issue.

Atm I have defined only one template:
Code: Select all
"file_header_format.xys": "/* *********************************************************\n * @@ScriptName: \n * @@Author: @@author <@@email>\n * @@Create Date:\n * @@Modify Date: \n * @@Function:\n********************************************************* */\n\n",


When I insert it via alt+1 I get:

Code: Select all
/* *********************************************************
# @@ScriptName: .Test.xys
* @@Author: Highend <your email here>
* @@Create Date: 09.08.2012 15:56:27
# @@Modify Date: 04.12.2012 11:00:53
* @@Function:
********************************************************* */



So for two lines not the defined "*" characters are inserted but "#".
highend
 
Posts: 94
Joined: Fri Jan 20, 2012 2:47 pm

Re: Automatically add file header plugin

Postby fjctlzy on Wed Dec 05, 2012 2:35 am

should be fixed now.
fjctlzy
 
Posts: 12
Joined: Mon Feb 06, 2012 8:16 am

Re: Automatically add file header plugin

Postby highend on Wed Dec 05, 2012 11:16 am

Confirmed, fixed. Ty!
highend
 
Posts: 94
Joined: Fri Jan 20, 2012 2:47 pm

Next

Return to Plugin Development

Who is online

Users browsing this forum: Majestic-12 [Bot] and 8 guests