<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>sp2hari@weblog... &#187; Gedit</title>
	<atom:link href="http://sp2hari.com/tag/gedit/feed/" rel="self" type="application/rss+xml" />
	<link>http://sp2hari.com</link>
	<description>I see, learn and rediscover... everyday!</description>
	<lastBuildDate>Thu, 24 Nov 2011 22:06:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Save Before Save &#8211; Gedit Plugin</title>
		<link>http://sp2hari.com/2009/07/07/save-before-save-gedit-plugin/</link>
		<comments>http://sp2hari.com/2009/07/07/save-before-save-gedit-plugin/#comments</comments>
		<pubDate>Tue, 07 Jul 2009 08:32:05 +0000</pubDate>
		<dc:creator>sp2hari</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Gedit]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://sp2hari.com/?p=237</guid>
		<description><![CDATA[A few days back, I got a mail from my friend, saying, Subject: Versioning in Windows Hi guys, Does any one know a software that can version files in windows? As simple as: There&#8217;s a certain folder of files I &#8230; <a href="http://sp2hari.com/2009/07/07/save-before-save-gedit-plugin/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>A few days back, I got a mail from my friend, saying, </p>
<p><em>Subject: Versioning in Windows<br />
Hi guys,</p>
<p>Does any one know a software that can version files in windows?<br />
As simple as: There&#8217;s a certain folder of files I want to be &#8220;version&#8221; tracked, I specify the list of folders.<br />
After this, every change I make is time-archived. So later, I can say, how did it look exactly at 3:47 am on Monday, and I get it back.</p>
<p>Any one has seen any s/w that can do this for me today?<br />
Perhaps something like this, but more frequent: http://www.apple.com/timecapsule/backup.html<br />
I remember having one like this within Google for Linux. I have a feeling they built this in the file system from scratch.</p>
<p>Thanks,<br />
</em></p>
<p>I  replied to him about some windows software I found after some googling and also found out that there is a file system in Linux which can perform this. But changing the file system of a current system sounded &#8220;dangerous&#8221; to me. I didn&#8217;t explore much into it. I use gedit for almost all development in my machine and started wondering how hard or easy can it be to create a gedit plugin which can do this. </p>
<p>That resulted in the following plugin. </p>
<p><strong>Installation instructions. </strong></p>
<p>1. Download the latest plugin file from <a href="http://sp2hari.com/work/saveb4save-1.0.0.zip">here</a>.<br />
2. Extract the files and copy the two files to ~/.gnome2/gedit/plugins<br />
3. Open gedit and enable the plugin.<br />
4. For the first time, configure the path where you need the backups to be stored. </p>
<p><strong>TODO</strong><br />
1. This is a 2 hour hack. Gedit plugin&#8217;s coding convention standards (if there is anything) is not followed.<br />
2. The time taken to save might increase if there are too many backup files. //TODO for next version.<br />
3. A neat GUI to show the diff and all the saved versions in the backup folder.<br />
4. An option to save diffs or the full text.<br />
5. Format of the filename can be provided as an option to the user.</p>
<p>Hope you like the plugin. Please fill in your feedback as comments to this post. </p>
]]></content:encoded>
			<wfw:commentRss>http://sp2hari.com/2009/07/07/save-before-save-gedit-plugin/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Gedit Plugin</title>
		<link>http://sp2hari.com/2007/11/08/gedit-plugin/</link>
		<comments>http://sp2hari.com/2007/11/08/gedit-plugin/#comments</comments>
		<pubDate>Thu, 08 Nov 2007 08:47:19 +0000</pubDate>
		<dc:creator>sp2hari</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Gedit]]></category>
		<category><![CDATA[GNU/Linux]]></category>

		<guid isPermaLink="false">http://sp2hari.com/2007/11/08/gedit-plugin/</guid>
		<description><![CDATA[In this article, we&#8217;ll see how to write plugins for Gedit. Since plugin development is easy in Python, I&#8217;m planning to explain this using Python. When the first caveman programmer chiseled the first program on the walls of the first &#8230; <a href="http://sp2hari.com/2007/11/08/gedit-plugin/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p align="justify">In this article, we&#8217;ll see how to write plugins for Gedit. Since plugin development is easy in Python, I&#8217;m planning to explain this using Python.</p>
<p align="justify">When the first caveman programmer chiseled the first program on the walls of the first cave computer, it was program to paint the string &#8220;Hello, world&#8221; in Antelope pictures. Roman programming textbooks began with the &#8220;Salut, Mundi&#8221; program. I don&#8217;t know what happens to people who break with this tradition, but I think it&#8217;s safer not to find out. So we&#8217;ll also deal only with HelloWorld in our first plugin.</p>
<p align="justify">This plugin is going to do two things. One is to add the string &#8220;HelloWorld &#8221; at the cursor position. The next is to convert all &#8220;Hello&#8221; in the program to &#8220;World&#8221;. A neat tutorial to write python plugins is can be found at <a href="http://live.gnome.org/Gedit/PythonPluginHowTo" target="_blank">live.gnome.org</a>.  Though you can skip that tutorial for now since I&#8217;ve explained most of the things one need to know to write this plugin. But i suggest you read that tutorial soon.</p>
<p align="justify">Some of the paths you need to know for writing a plugin.</p>
<table>
<tr>
<th>Path</th>
<th>Details</th>
</tr>
<tr class="row-a">
<td>/usr/lib/gedit-2/plugins/</td>
<td>System-wide plugins directory</td>
</tr>
<tr class="row-b">
<td>~/.gnome2/gedit/plugins/</td>
<td>User Plugins directory</td>
</tr>
<tr class="row-a">
<td>/usr/share/gedit-2/</td>
<td>Data needed for system-wide plugins.</td>
</tr>
<tr class="row-b">
<td>~/.gconf/apps/gedit-2/</td>
<td>Gedit configuration. <br/>Can be modified using gconf-editor.</td>
</tr>
<tr class="row-a">
<td>/usr/share/gtk-doc/html/gedit</td>
<td>gedit Reference Manual</td>
</tr>
</table>
<p>Every python plugin needs at least two files. Let us name our plugin as &#8220;frisco&#8221;. So we should have two files namely, frisco.gedit-plugin and frisco.py</p>
<p>Let&#8217;s start with the contents of frisco.gedit-plugin.<br />
<code>[Gedit Plugin]<br />
Loader=python<br />
Module=frisco<br />
IAge=2<br />
Name=HelloWord<br />
Description=A HelloWorld plugin for Gedit.<br />
Authors=Harishankaran K &lt;sp2hari@gmail.com&gt;<br />
Copyright=Copyright Â© sp2hari<br />
Website=http://www.sp2hari.com</code></p>
<p>The contents of this file is almost same for all the plugins. The module, name and description will change for different plugins. If your plugin has the python file frisco.py, then the modulde is frisco.</p>
<p>Note :: We don&#8217;t specify the extension in the module name.</p>
<p>The .gedit-plugin file is done now. Next let&#8217;s move on to frisco.py.</p>
<pre><code>#!/usr/bin/python

import gedit

class HelloWorldPlugin(gedit.Plugin):
    def __init__(self):
        print "Plugin loaded"

    def activate(self, window):
        print "Plugin activated"

    def deactivate(self, window):
        print "Plugin deactivated"

    def update_ui(self, window):
        pass
</code></pre>
<p align="justify">This file, frisco.py derives one class from the Gedit.plugin and defines activate, deactivate and update_ui.  activate() is called when the plugin is activated. Similarly deactivate() is called when the plugin is deactivated.  We will check how our plugin works now.</p>
<p align="justify">Run gedit from terminal and check whether your plugin is listed in the plugins list.</p>
<p align="justify">You can see that the details you provided in frisco.gedit-plugin can be viewed in the About Plugin and the Credits.</p>
<p align="justify">Now enable the plugin and look at shell prompt. You will see the print statements being execute when we activate and deactivate the plugin. :). Wow, our first plugin is ready to add more spice. :-)</p>
<p align="justify">Note:: If you get an error saying</p>
<p align="justify">WARNING **: Cannot load Python plugin &#8216;HelloWord&#8217; since file &#8216;frisco&#8217; cannot be read.</p>
<p>WARNING **: Error activating plugin &#8216;HelloWord&#8217;</p>
<p>Then the file frisco.py is not present in your plugins directory or the python file has an error. Fix the code and try again. You will get the output  as  shown below.</p>
<p align="center"><a href="http://sp2hari.com/wp-content/uploads/2007/11/frisco.png" title="Frisco Plugin"><img src="http://sp2hari.com/wp-content/uploads/2007/11/frisco.png" alt="Frisco Plugin" /></a></p>
<p align="left">&nbsp;</p>
<p align="left">The output for the above plugin in the shell when the plugin is activated and deactivated for a few times will be like</p>
<p><code><br />
hari@hari-laptop:~$ gedit<br />
Plugin loaded<br />
Plugin activated<br />
Plugin deactivated<br />
Plugin activated<br />
Plugin deactivated<br />
Plugin activated<br />
Plugin deactivated<br />
Plugin activated<br />
</code></p>
<p align="justify">Now we have to add functionality to this plugin. A good practice while coding plugin is the create a separate &#8216;Helper&#8217; Class which will control the window and do all useful actions. It&#8217;ll be called once in the main class.</p>
<p align="justify">So we will modify the  HelloWorldPlugin class as follows</p>
<pre><code>#!/usr/bin/python

import gedit

class HelloWorld(gedit.Plugin):
    def __init__(self):
        gedit.Plugin.__init__(self)
        self._instances = {}

    def activate(self, window):
        self._instances[window] = HelloWorldHelper(self, window)

    def deactivate(self, window):
        self._instances[window].deactivate()
        del self._instances[window]

    def update_ui(self, window):
        self._instances[window].update_ui()</code></pre>
<p>The code for the HelloWorldHelper class will be</p>
<pre><code>

class HelloWorldHelper:
    def __init__(self, plugin, window):
        print "Plugin created for", window
        self._window = window
        self._plugin = plugin

    def deactivate(self):
        print "Plugin stopped for", self._window
        self._window = None
        self._plugin = None

    def update_ui(self):
        # Called whenever the window has been updated (active tab
        # changed, etc.)
        print "Plugin update for", self._window

</code></pre>
<p>When you run gedit from terminal, now, it will print more details like the Gedit window object. A sample run for the above code is given below</p>
<p><code>hari@hari-laptop:~$ gedit<br />
Plugin created for &lt;gedit.Window object at 0x8521504 (GeditWindow at 0x816e000)&gt;<br />
Plugin update for &lt;gedit.Window object at 0x8521504 (GeditWindow at 0x816e000)&gt;<br />
Plugin update for &lt;gedit.Window object at 0x8521504 (GeditWindow at 0x816e000)&gt;<br />
Plugin stopped for &lt;gedit.Window object at 0x8521504 (GeditWindow at 0x816e000)&gt;<br />
Plugin created for &lt;gedit.Window object at 0x8521504 (GeditWindow at 0x816e000)&gt;<br />
Plugin stopped for &lt;gedit.Window object at 0x8521504 (GeditWindow at 0x816e000)&gt;<br />
Plugin created for &lt;gedit.Window object at 0x8521504 (GeditWindow at 0x816e000)&gt;<br />
Plugin stopped for &lt;gedit.Window object at 0x8521504 (GeditWindow at 0x816e000)&gt;<br />
Plugin created for &lt;gedit.Window object at 0x8521504 (GeditWindow at 0x816e000)&gt;</code></p>
<p>Hereafter there is no need to change the HelloWorldPlugin class. So we&#8217;ll work only on the HelloWorldHelper class. We will define a ui_str which will enable us to add a menuitem in the Tools menu.</p>
<p>We will define the ui_str as follows</p>
<pre><code>import gtk 

ui_str = """&lt;ui&gt;
  &lt;menubar name="MenuBar"&gt;
    &lt;menu name="ToolsMenu" action="Tools"&gt;
      &lt;placeholder name="ToolsOps_2"&gt;
        &lt;menuitem name="Insert HelloWorld" action="InsertHelloWorld"/&gt;
        &lt;menuitem name="Change Hello to World" action="ChangeHellotoWorld"/&gt;
      &lt;/placeholder&gt;
    &lt;/menu&gt;
  &lt;/menubar&gt;
&lt;/ui&gt;
"""</code></pre>
<p align="justify">The activate, deactivate and update ui functions for the HelloWorldHelper Class are modified as follows</p>
<pre><code>    def __init__(self, plugin, window):
        self._window = window
        self._plugin = plugin

        # Insert menu items
        self._insert_menu()

    def deactivate(self):
        self._window = None
        self._plugin = None

        self._remove_menu()
    def update_ui(self):
        # Called whenever the window has been updated (active tab
        # changed, etc.)
        self._action_group.set_sensitive(self._window.get_active_document() != None)
</code></pre>
<p align="justify">Now we need to write the method insert_menu which will register the callbacks for the actions like inserting hello world and changing hello to world.<br />
The insert_menu function is defined as followed. If you know gtk or pygtk then it&#8217;ll be easy for you to understand that code. I&#8217;ll advise you to read the basics of pygtk if you plan to write your own plugin.</p>
<pre><code>    def _insert_menu(self):
        # Get the GtkUIManager
        manager = self._window.get_ui_manager()

        # Create a new action group
        self._action_group = gtk.ActionGroup("ExamplePyPluginActions")
        self._action_group.add_actions([("InsertHelloWorld", None, _("Insert HelloWorld"),
                                         None, _("Insert HelloWorld"),
                                         self._inserthelloworld)])
        self._action_group.add_actions([("ChangeHellotoWorld", None, _("Change Hello to World"),
                                         None, _("Change Hello to World"),
                                         self._hellotoworld)])

        # Insert the action group
        manager.insert_action_group(self._action_group, -1)

        # Merge the UI
        self._ui_id = manager.add_ui_from_string(ui_str)

    def _remove_menu(self):
        # Get the GtkUIManager
        manager = self._window.get_ui_manager()

        # Remove the ui
        manager.remove_ui(self._ui_id)

        # Remove the action group
        manager.remove_action_group(self._action_group)

        # Make sure the manager updates
        manager.ensure_update()
</code></pre>
<p align="justify">Now we are all set the two final functions which will do the required actions. These are defined in the helper class as follows</p>
<pre><code>    def _hellotoworld(self, action):
        doc = self._window.get_active_document();
        if not doc:
            return
        doc.replace_all("Hello", "World", 0);

    def _inserthelloworld(self, action):
        doc = self._window.get_active_document();
        if not doc:
            print "Noe";
            return;
        doc.insert_at_cursor("HelloWorld")</code></pre>
<p align="justify">Well, that&#8217;s all. Your first plugin is up and running now :-) :-)</p>
<p align="justify">The python files used in this example can be downloaded <a href="http://sp2hari.com/wp-content/uploads/2007/11/friscotar.bz2" title="Frisco Plugin TarBall">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://sp2hari.com/2007/11/08/gedit-plugin/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Gedit</title>
		<link>http://sp2hari.com/2007/11/06/gedit/</link>
		<comments>http://sp2hari.com/2007/11/06/gedit/#comments</comments>
		<pubDate>Tue, 06 Nov 2007 08:24:24 +0000</pubDate>
		<dc:creator>sp2hari</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Gedit]]></category>
		<category><![CDATA[GNU/Linux]]></category>

		<guid isPermaLink="false">http://sp2hari.com/2007/11/06/gedit/</guid>
		<description><![CDATA[Every GNU/Linux user must be knowing about Gedit. This tiny text editor which comes with gnome is much more powerful than we all think. A few customizations and adding a few plugins will convert this simple text editor into a &#8230; <a href="http://sp2hari.com/2007/11/06/gedit/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p align="justify">Every GNU/Linux user must be knowing about Gedit. This tiny text editor which comes with gnome is much more powerful than we all think. A few customizations and adding a few plugins will convert this simple text editor into a complete IDE for any programming language. In this article, i have mentioned about the configurations i have made in my box and the plugins which you might find useful.</p>
<p align="justify">Any text editor has to be customized according to the need of the end user. The customizations for a C or C++ coder and a PHP or Python coder are totally different. So let me write here according to various needs. Check out in which category you fit in and use those customizations.</p>
<p>The Preferences window in Gedit is the core which converts this simple text editor into a complete IDE. It has features to customize almost everything.</p>
<p><a href="http://sp2hari.com/wp-content/uploads/2007/11/preferences.png" title="Gedit Preferences"></a></p>
<p style="text-align: center"><a href="http://sp2hari.com/wp-content/uploads/2007/11/preferences.png" title="Gedit Preferences"><img src="http://sp2hari.com/wp-content/uploads/2007/11/preferences.png" alt="Gedit Preferences" /></a></p>
<h3>General Configurations</h3>
<p>Open Preferences Window (Edit -&gt; Preferences)</p>
<p><u>In the View Tab</u></p>
<ul>
<li> Check Enable text wrapping.</li>
</ul>
<p>I prefer to see the long lines in the same window, which reduces the pain of scrolling across the window using the mouse.</p>
<ul>
<li>Check Display line numbers.</li>
<li>Check Highlight current line</li>
</ul>
<p>In my Ubuntu Studio theme, it wasn&#8217;t easy to read when the current line is highlighted. So i disabled this in that theme. So check this whether this suits your gnome theme when you enable this.</p>
<ul>
<li>Highlight matching bracket</li>
</ul>
<p>An useful option if you are used to getting confused with brackets.</p>
<p><u>    In the Editor Tab</u></p>
<ul>
<li>Set the Tab width as 4</li>
</ul>
<ul>
<li>Check Enable automatic indentation</li>
</ul>
<ul>
<li>Uncheck Create a backup copy of files before saving</li>
</ul>
<p align="justify">Again this depends upon your need. Backup files are created by adding a &#8216;~&#8217; to the current file name. If you are a web developer and coding in any web development language, better don&#8217;t enable this option. Many times these &#8216;~&#8217; files created might create a security hole in your server. For example, mysql_connect.php file will have a backup called mysql_connect.php~ and your web server will parse the mysql_connect.php but it won&#8217;t do the same for the backup file. It&#8217;ll just display the source code to the client and thereby your your mysql password is gone :P</p>
<ul>
<li>Check Autosave files every 5 minutes and make that 2 mins</li>
</ul>
<p>If you don&#8217;t have the habit of saving the file often, then this might save you when something terrible happens :P</p>
<p><u>In the Font &amp; Colors Tab</u></p>
<ul>
<li>Uncheck the Use the system fixed width font</li>
<li>Set the size of the editor font as 10 or 12</li>
<li>Choose any one font from the following. Note that Mono space 10 is the system fixed with font.</li>
</ul>
<p>Standars Symbols L<br />
Serif<br />
Vemana<br />
Sans<br />
Monospace<br />
Mallige Normal<br />
Loma Book</p>
<ul>
<li> I prefer the Classic color scheme. Just three more clicks, you can see all the color scheme and choose anything you like.</li>
</ul>
<p><u>In the Plugins Tab</u></p>
<p align="center">&nbsp;</p>
<p align="center"><a href="http://sp2hari.com/wp-content/uploads/2007/11/plugins.png" title="Gedit Plugins"><img src="http://sp2hari.com/wp-content/uploads/2007/11/plugins.png" alt="Gedit Plugins" /></a></p>
<p align="justify">    This sections makes the gedit a really powerful text editor. By default gedit comes with few standard plugins but you can install more plugins by installing the gedit-plugins package. If you don&#8217;t have root access, download the plugins from gedit.org and copy it to your ~/.gnome2/gedit/plugins folder. You can continue if you are lazy to download the plugins now. You can do that when a need arises. ;)</p>
<p align="justify">After this jump to section which you might be interested in.</p>
<p align="justify"><u>Programming</u></p>
<ul>
<li>Bracket Completion ( You need to install this plugin)</li>
</ul>
<p align="justify"> A plugin which automatically adds closing brackets, single quotes and double quotes. Sometimes really useful and sometimes irritating. When you are typing the code, this is pretty useful but when you are editing a code already written, then this irritates you by adding closing brackets or quotes where you never intended to add.</p>
<ul>
<li>Code Comment ( You need to install this plugin)</li>
</ul>
<p align="justify"> A useful plugin for any programmer. You can comment or uncomment a selected block of code.</p>
<ul>
<li> Indent Lines</li>
</ul>
<p align="justify"> Very useful when you are specific about the indentation rules. Indents or un-indents a selected block of code. Very useful for python.</p>
<ul>
<li> Snippets</li>
</ul>
<p align="justify"> Want to insert a piece of code which just a few keystrokes, then this is for you. Yes lesser keystrokes than Ctrl C Ctrl V.</p>
<ul>
<li> External Tools</li>
</ul>
<p align="justify"> This gives amazing power to manipulate anything within gedit. I guess i can&#8217;t write about this here. Check out this post about External Tools. And don&#8217;t skip that post. It&#8217;s the BEST plugin for gedit.</p>
<p align="justify"><u>HTML</u></p>
<p align="justify"> Download the HTML tidy plugin from <a href="http://www.eng.tau.ac.il/~atavory/gedit-plugins/html-tidy/" title="HTML Tidy" target="_blank">here</a> and extract the folder to your ~/.gnome2/gedit/plugins folder. Enable the HTML Tidy plugin from the plugins tab in Preferences Window. HTML Tidy is an utility to clean up and pretty print HTML/XHTML/XML. Enable the Bottom Pane from the View Menu and you can clean up or check any HTML/XHTML/XML document.</p>
<p align="justify"> The default configurations are enough to use Tidy. If you want to tweak it according to your needs, then Configure Plugin ( There are so many options :P )</p>
<p><u>Snippets</u></p>
<p align="justify">This is an useful plugin once you know what gives what. If you code for online programming contests like spoj, topcoder, acm or usaco and if your programming language is C++, then download this <a href="http://sp2hari.com/wp-content/uploads/2007/11/cpp.xml" title="CPP Snippet">cpp.xml</a> file and put it in your ~/.gnome2/gedit/snippets folder.    Then press template[tab] or topcoder[tab] in a new cpp file.</p>
<p align="justify"> Apart from that, if you are a web developer, then check out the Snippets for HTML and PHP. Once you remember the shortcuts which you need, they&#8217;ll make your life really easy.</p>
]]></content:encoded>
			<wfw:commentRss>http://sp2hari.com/2007/11/06/gedit/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

