Linux for Designers

a blog by Eckhard M. Jäger

gEdit Template plugin

, , , ,

For SweeTS i needed the possibilty to create a document based on a template file (the normal "New from template" function). gEdit didn't ship with that and so i tried to create it. I was lucky to find a start in the familiar plugin by Rob Miller which i modified. This plugin is completely localized in german and english.

How it works:
* Copy the files of the Template plugin into ~/.gnome2/gedit/plugins
* create a folder "templates" in ~/.gnome2/gedit
* copy your templates files into it (example default.html)
* Start gEdit and enable the plugin "New File From a Template" in the preferences
* After a restart the plugin appears in the File menu
* Assign the typical shortcut "Shift+Ctrl+N" to it
* the new created files will get the mimetype of the template files

Download:
http://files.myopera.com/area42/files/gedit_template_plugin.zip

gEdit plugins i wrote too:
http://my.opera.com/area42/blog/gedit-language-reference-plugin
http://my.opera.com/area42/blog/gedit-browser-preview-plugin
A lot of other gEdit plugins can be found here.

Second Life WindLight First Look ViewerGimp 2.4.2

Comments

Unregistered user Wednesday, November 28, 2007 4:02:42 AM

engel writes: Great template! I've just released a basic template set for this: http://hansengel.wordpress.com/2007/11/27/gedit-template-plugin-basic-templates/ It includes most templates that web developers would need.

Eckhard M. Jägerarea42 Wednesday, November 28, 2007 7:47:42 AM

Hello Engel,

very cool, i will check it out!

Unregistered user Wednesday, November 28, 2007 1:37:10 PM

engel writes: I have a suggestion for this plugin.... Why not make support for "variables", like the current user logged in? Then, we could reference the variables from our templates through brackets (ex. "{user}"). The plugin would process the template, and replace the variables with their values.

Eckhard M. Jägerarea42 Wednesday, November 28, 2007 6:10:45 PM

a possibel way, i will think about that.

Unregistered user Saturday, July 26, 2008 7:49:16 AM

TompaD writes: Hi! I have a problem with one of your plugins - template-plugin. The dialogwindow will not close after I have choosed a template. Its an template I made myself(actionscript)....when I choose another the window close....strange. Regards TompaD

Eckhard M. Jägerarea42 Saturday, July 26, 2008 10:20:20 AM

@TompaD
Can i download it and take a look? Or drop me a line: bart neeeneenee de

Unregistered user Friday, August 1, 2008 9:12:21 AM

TompaD writes: I made a new one with mxml-extension, but the same there, no closing of window after clicking OK. It looks like this: <?xml version="1.0"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> <mx:Script> <![CDATA[ ]]> </mx:Script> </mx:Application> regards Tompad

Eckhard M. Jägerarea42 Friday, August 1, 2008 10:36:10 AM

Here no problem at all. What's the filename of it? Did it contains spaces? Try to use "_" for spaces.

Unregistered user Saturday, August 2, 2008 7:37:18 AM

Tompad writes: How strange! The filenames is Flex.mxml and Actionscript3.as - I tried with different files... So no spaces...Is it because I run it on Xubuntu?? ...but when none of the templates should work......the "original" templates loads as they should.....this is a mysterium for me.....

Unregistered user Saturday, August 2, 2008 8:31:12 AM

TompaD writes: Hi again! I tried to make other template - TXT.txt, DOC.doc and PHP5.php - and guess what! Only PHP5.php did work as the "original" templates. Is there a list in the plugin with which files is accepted?

Unregistered user Saturday, August 2, 2008 8:40:17 AM

TompaD writes: Hi again! :-) What is the latest version of plugin? I got 1.02. Regards TompaD

Eckhard M. Jägerarea42 Saturday, August 2, 2008 9:04:21 AM

1.02 is up-to-date. What kind OS and desktop you use? Which version of gEdit?

Unregistered user Saturday, August 2, 2008 9:31:05 AM

TompaD writes: Lets see - I have Xubuntu 8.04 with Xfce 4 Desktop Environment version 4.4.2 (Xfce 4.4), gEdit is 2.22.3

Alexsalexs Tuesday, October 21, 2008 5:10:26 PM

Danke für das Plugin, eine Vorlage zu öffnen fehlte mir von PSPad sehr. (sidux mit xfce-Desktop)
Jetzt muss ich nur noch schauen dass ich den Color-Picker (nicht das ganze Paket) zum laufen bekomme.

Grüsse Alexs

Eckhard M. Jägerarea42 Tuesday, October 21, 2008 8:38:27 PM

@Alexs

Hier gibt es noch mehr Plugins für gEdit:
http://live.gnome.org/Gedit/Plugins#third_party

Und unbedingt die Snippet-Sammlung für das Externe Werkzeuge-Plugin ansehen:
http://live.gnome.org/Gedit/ExternalToolsPluginSnippets

Unregistered user Saturday, May 2, 2009 10:03:47 AM

Felix writes: I think this is somewhat broken in gEdit 2.26.1 (Ubuntu 9.04). The part that's broken seems to be the language detection of the template. I just deleted that whole part and it worked. But thanks, great plugin :)

Eckhard M. Jägerarea42 Wednesday, May 6, 2009 9:22:43 PM

Hi Felix,

you are right, i got a brand new Dell Studio 17 and will install Jaunty on it, then i will fix this problem.

Unregistered user Thursday, May 7, 2009 6:36:35 AM

konsumer writes: I made a version that uses ~/Templates (to share with nautilus) and uses some variables: $$DATETIME$$ $$YEAR$$ $$USER_EMAIL$$ $$USER_NAME$$ $$USER_NICKNAME$$ It grabs this data from the gnome "About Me" dialog. You can see how to add them by searching for "add some useful presets" in template.py I also included templates for Druapl6 module, and some others I find useful. http://david.konsumer.googlepages.com/gedit_template_plugin.zip

Eckhard M. Jägerarea42 Thursday, May 7, 2009 7:33:54 PM

Hi konsumer,

this sound great. Did it working on Ubuntu 9.04?

Alexsalexs Monday, May 11, 2009 4:19:32 PM

Irgendwie klappt das Plugin nicht mehr. worried
Wenn ich eine HTML-Vorlage mit gedit 2.26.1 öffnen will (sidux), steht folgendes in der Konsole:
Traceback (most recent call last):
  File "/home/alex/.gnome2/gedit/plugins/template.py", line 145, in on_open_from_template_activate
    language = gedit.language_manager_get_language_from_mime_type(language_manager, mimes[0])			
AttributeError: 'module' object has no attribute 'language_manager_get_language_from_mime_type'

Grüße Alexs

Eckhard M. Jägerarea42 Monday, May 11, 2009 8:43:45 PM

Hello Alex,

yes i know there is a problem with the gEdit Template plugin. I switched now to Ubuntu 9.04 that ships with Gnome 2.26 and will fix this problem soon.

Thanks for your reply.

Unregistered user Monday, May 11, 2009 10:43:42 PM

konsumer writes: area42: yes, I am using jaunty. alex: I didn't touch the language stuff (I don't think.) By the error message, it looks like you are using an older version (I notice there is old language stuff commented out at line 145) Try a new version, try switching around the commented stuff in that area. Maybe comment all the language stuff. what happens?

th3pr0ph3t Tuesday, May 19, 2009 8:03:43 PM

Hey I modified this plugin with some of the fixes you guys did (if only I read all the comments *before*).

Anyway, I want to share it and the modifications I did include:
- the language thing where the template is not loaded because it tries to call a method that does not exist anymore.
- the plugin now ASKS now asks for the NEW DOCUMENT's name (starting in the currently open file's directory). It copies the file, then opens it.
- it does not fail (showing an empty document) when the template uses an encoding different than UTF-8 (I needed ISO-8859-1).
- the following expressions are resolved if found in the template text:
$USER $USERNAME, $LOGNAME
$HOME
...and all vars replaced by os.path.expandvars()
$DATE
$TIME
$DATETIME
$GEDIT_CURRENT_DOCUMENT_URI
$GEDIT_CURRENT_DOCUMENT_NAME
$GEDIT_CURRENT_DOCUMENT_PATH
$GEDIT_CURRENT_DOCUMENT_DIR

Well that's the way I like it, maybe somebody else does.
Here's the file, regards.

http://files.myopera.com/th3pr0ph3t/files/template.zip

Eckhard M. Jägerarea42 Wednesday, May 20, 2009 7:34:56 AM

I will check it out!!! Thanks.

Unregistered user Monday, July 6, 2009 7:15:58 PM

Anonymous writes: It's not working for me. When I go to 'New from template', I'll try and open my template. But it won't. It doesn't work using a double-click or just pressing open. I end up having to close the window, and just opening the file, and doing a 'Save-as'. This is on Ubuntu 9.04.

Unregistered user Monday, July 6, 2009 7:18:59 PM

Anonymous writes: Oh, th3pr0ph3t's fix seems to be working for me. It also ask for the new name of the file, which is something that would have been useful.

Unregistered user Wednesday, July 15, 2009 6:33:14 AM

Michael writes: I lost on how to assign a keyboard shortcut, could someone please post how they did it. Thanks.

Eckhard M. Jägerarea42 Wednesday, July 15, 2009 9:24:36 PM

You must enable them here:
http://blogs.gnome.org/thos/files/2007/05/Screenshot-Appearance%20Preferences-4.png
Well if dynamic shortcuts enabled on your gnome desktop than hover over the menu entry and press the keyys you like to use

Unregistered user Monday, August 10, 2009 12:12:25 PM

Anke writes: @th3pr0ph3t, your modified plugin works for me, thanks.

Unregistered user Thursday, September 10, 2009 4:20:03 PM

ddf writes: I have this same problem mentioned above: ---------- It's not working for me. When I go to 'New from template', I'll try and open my template. But it won't. It doesn't work using a double-click or just pressing open. I end up having to close the window, and just opening the file, and doing a 'Save-as'. This is on Ubuntu 9.04. ----------- It used to work fine. Not sure when it stopped working

Unregistered user Wednesday, November 18, 2009 8:52:00 PM

spidie writes: I'm currently getting a broken link on the zip file, is it still available?

Unregistered user Monday, January 4, 2010 3:39:49 PM

jqueralt writes: I found a little bug that it's easy to correct in template.py . In line 229 #buttons = (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN, gtk.RESPONSE_OK) appears a button with the label 'Open' when it really has to say 'Save' because its function is to save the file generated from the template. I put in my line 229: buttons = (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_SAVE, gtk.RESPONSE_OK) and it works! Hope it can help.

Unregistered user Tuesday, March 2, 2010 8:15:13 PM

JeongtaeRoh writes: It's a plugin I wanted, but it has a problem. http://pds16.egloos.com/pds/201003/03/11/GeditTemplatePluginError.png As you can see, I can't toggle the plugin. I'm running ubuntu 9.10. It looks weird. Can you tell me what's the problem?

Eckhard M. Jägerarea42 Wednesday, March 3, 2010 3:44:36 PM

Mhm, interesting, i'm running Karmic too and it works without a problem. It based may on the localisation.

Alexsalexs Wednesday, March 3, 2010 4:12:06 PM

I can confirm this problem, I can't enable the plugin.

When start gedit from console:
$ gedit
ImportError: No module named template
** (gedit:5810): WARNING **: Error loading plugin 'Neu von Vorlage 1.04'

gedit 2.28.3 / python 2.5.5 / sidux

th3pr0ph3t Sunday, March 7, 2010 3:33:16 AM

mhm... have you tried without the other plugins?

Unregistered user Monday, April 5, 2010 2:41:59 PM

Jason writes: Same here regarding not being able to enable the plugin when running Ubuntu 9.10. The plugin shows up in the preferences Plugin tab, but it is grayed out. All of my other plugins are working just fine. Help! I definitely want to use this sweet plugin. Jason

Unregistered user Wednesday, April 14, 2010 6:26:31 AM

Anonymous writes: Rename template.2.py to template.py.

Alexsalexs Wednesday, April 14, 2010 5:19:10 PM

Originally posted by anonymous:

Rename template.2.py to template.py.


Yeah, thanks cheers

Unregistered user Tuesday, April 26, 2011 6:36:21 PM

Newbean writes: Changing the name from template.2.py to template.py solved the problem.

Unregistered user Monday, June 27, 2011 6:51:42 AM

E3D3 writes: Thanks, It works great in Gedit 2.30.3

Unregistered user Saturday, July 23, 2011 5:39:32 AM

Germán writes: It is very useful but doesn't work with Gedit 3. Please could you update it??

Eckhard M. Jägerarea42 Saturday, July 23, 2011 3:01:53 PM

When switching to Ubuntu 12.04 and Gnome3 an update will be available.

Alexsalexs Monday, November 7, 2011 4:00:07 PM

Eckhard, have you been updating to gnome3?
I have gedit hold on gtk2. worried

Alexsalexs Saturday, December 3, 2011 8:11:44 PM

I found compatible Templates-plugin for gedit3 here.

Thank you for the gedit2 plugin, Eckhard. smile

Write a comment

New comments have been disabled for this post.