<?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>muhuk.com &#187; kate</title>
	<atom:link href="http://www.muhuk.com/tag/kate/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.muhuk.com</link>
	<description>know thyself</description>
	<lastBuildDate>Thu, 29 Dec 2011 05:05:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Editors, Conventions and Evdenevenaklederiz.biz</title>
		<link>http://www.muhuk.com/2009/01/editors-conventions-and-evdenevenaklederizbiz/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=editors-conventions-and-evdenevenaklederizbiz</link>
		<comments>http://www.muhuk.com/2009/01/editors-conventions-and-evdenevenaklederizbiz/#comments</comments>
		<pubDate>Tue, 06 Jan 2009 21:43:32 +0000</pubDate>
		<dc:creator>Atamert Ölçgen</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[convention]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[editor]]></category>
		<category><![CDATA[ide]]></category>
		<category><![CDATA[kate]]></category>
		<category><![CDATA[pep]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.muhuk.com/?p=76</guid>
		<description><![CDATA[I went editor hunting again today. Lame, but I can&#8217;t help doing it time to time. My main editor is Kate for some time now. I use Pâté´s source browser when I am editing Python files. This is all fine for me. I love Kate. A multi-document editor and simple source inspection to jump through [...]<div><a class="addthis_button" href="//addthis.com/bookmark.php?v=250" addthis:url='http://www.muhuk.com/2009/01/editors-conventions-and-evdenevenaklederizbiz/' addthis:title='Editors, Conventions and Evdenevenaklederiz.biz '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div>]]></description>
			<content:encoded><![CDATA[<p>I went editor hunting again today. Lame, but I can&#8217;t help doing it time to time. My main editor is <a href="http://kate-editor.org/">Kate</a> for some time now. I use <a href="http://www.muhuk.com/2008/11/extending-kate-with-pate/">Pâté</a>´s source browser when I am editing Python files. This is all fine for me. I love Kate. A multi-document editor and simple source inspection to jump through within the current file is all I need. But it gets hung. Depending on uptime it freezes up to ten seconds. This is sad.</p>

<p>A few days back I have installed <a href="http://pythonide.stani.be/">SPE</a>. All in all, it is a nice Python oriented editor<sup>1</sup>. I have had a good experience with it working on my main project. But when I tried to switch to my <a href="http://github.com/muhuk/tms/tree">side project</a> today, it did something amazingly stupid. When you change the workspace it fails to close currently opened files, and then adds them to the other workspace. Well, maybe it was me being amazingly stupid failing to figure out how to disable this <em>feature</em>. But this is unacceptable behaviour nevertheless.</p>

<p>I tried (again) <a href="http://eric-ide.python-projects.org/">eric</a> after that. This time I didn&#8217;t panic when I saw an IDE style GUI on my screen. Eric should have done the job as well. I could have forgiven it not letting me customize the toolbars<sup>2</sup>&#8230; But <strong>it doesn&#8217;t show a static word wrap marker</strong><sup>3</sup>! How can an editor feature dynamic word wrapping but could be unable to show a static word wrap marker?</p>

<p>When I was searching for something else, I had stumbled upon<sup>4</sup> an e-mail message about <a href="http://www.kdevelop.org/">KDevelop</a>´s <em>Class Browser</em>. Did I ever mention that my searching skill is pathetic? It is. Anyway, I decided to try it out. So far so good. The class browser is not designed with Python in mind. But it is better than nothing. And the best news is the editor component is a KatePart. I&#8217;ll use KDevelop for programming and continue using Kate for other text editing, such as this one. We&#8217;ll see how it goes.</p>

<h3>Conventions: A Necessary Evil?</h3>

<p>OK, conventions are not evil at all. I have a bad habit of doing the opposite of what is <a href="http://en.wikipedia.org/wiki/Benevolent_Dictator_For_Life">dictated</a>. It would be good thing if I had stopped and made an assessment. I should change from reactive to forethoughtful. Regardless, conventions from <strong>smart people</strong> are usually the right stuff.</p>

<p>For a long time I have been thinking; &#8220;<em>why should I manually break lines, in this modern age of dynamic word wrapping</em>&#8221; until I edited a configuration file on my server with <a href="http://www.nano-editor.org/">Nano</a> and spent two hours after, trying to find out why it wasn&#8217;t working. <a href="http://www.python.org/dev/peps/pep-0008/">PEP8</a> says &#8220;<em>Limit all lines to a maximum of 79 characters.</em>&#8220;, <strong>do it</strong>. Because you can find yourself in a situation where you have to do without dynamic word wrapping and get your line breaks all messed up. Also, if you haven&#8217;t already done that; I would suggest you to take some time to read PEP8 and <a href="http://www.python.org/dev/peps/pep-0257/">PEP257</a>.</p>

<p>Another set of conventions I am interested in are <a href="http://ericholscher.com/blog/2008/dec/3/starting-django-conventions-project/">Django conventions</a>. I am in the process of splitting apps in my main project. I wasn&#8217;t planning a <a href="http://www.b-list.org/weblog/2006/sep/10/django-tips-laying-out-application/">monolytic project</a> in the beginning. But those two apps just got bigger and bigger and uglier&#8230; Now, as you can imagine; it is a painful process making them several smaller applications.</p>

<h3>Why Am I Neglecting My Blog Lately</h3>

<p>This <em>main project</em> I have been talking about from the beginning of this post is online now. You can visit here; <a href="http://evdenevenaklederiz.biz">Evdenevenaklederiz.biz</a> (in Turkish). It is a simple tool for helping you find a mover. Critics and comments are very much appreciated.</p>

<p>I will be blogging regularly again soon. 3~5 posts per month is acceptable for me. Especially if at least one of them has some valuable information in it. I am not very ambitious about blogging.</p>

<p>Since this turned out to be more like a status update I should mention one last thing; <a href="http://www.muhuk.com/2008/10/dieting-again/">my diet</a> is finished last week. Currently I am 77 kgs, less than 15% fat. I am very happy with the results. For now my goal is to stay below 80 kgs, and focus on work. <img src='http://www.muhuk.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>

<hr />

<p><strong>1</strong>: Read: pretty much useless for anything other than Python.</p>

<p><strong>2</strong>: Appereantly a newer version allows you to hide the toolbars.</p>

<p><strong>3</strong>: You know that vertical line marking the 79th (or 80th) column.</p>

<p><strong>4</strong>: No, not that <a href="http://www.stumbleupon.com">stumbling upon</a>.</p>
<div><a class="addthis_button" href="http://www.muhuk.com//addthis.com/bookmark.php?v=250" addthis:url='http://www.muhuk.com/2009/01/editors-conventions-and-evdenevenaklederizbiz/' addthis:title='Editors, Conventions and Evdenevenaklederiz.biz '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div><p>Related posts:<ol>
<li><a href='http://www.muhuk.com/2011/06/pycon-apac-optimizing-media-performance-with-django_compressor/' rel='bookmark' title='My PyCon APAC 2011 Presentation: Optimizing Media Performance with django_compressor'>My PyCon APAC 2011 Presentation: Optimizing Media Performance with django_compressor</a></li>
<li><a href='http://www.muhuk.com/2011/11/working-with-files-in-django/' rel='bookmark' title='Working with files in Django &#8211; Part 1'>Working with files in Django &#8211; Part 1</a></li>
<li><a href='http://www.muhuk.com/2011/11/working-with-files-in-django-part-2/' rel='bookmark' title='Working with files in Django &#8211; Part 2'>Working with files in Django &#8211; Part 2</a></li>
</ol></p> <p><a href="http://www.muhuk.com/?flattrss_redirect&amp;id=76&amp;md5=6ee93ca236ca4bcaffc45234ce9df95b" title="Flattr" target="_blank"><img src="http://www.muhuk.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.muhuk.com/2009/01/editors-conventions-and-evdenevenaklederizbiz/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<atom:link rel="payment" href="http://www.muhuk.com/?flattrss_redirect&amp;id=76&amp;md5=6ee93ca236ca4bcaffc45234ce9df95b" type="text/html" />
	</item>
		<item>
		<title>Extending Kate With Pâté</title>
		<link>http://www.muhuk.com/2008/11/extending-kate-with-pate/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=extending-kate-with-pate</link>
		<comments>http://www.muhuk.com/2008/11/extending-kate-with-pate/#comments</comments>
		<pubDate>Wed, 12 Nov 2008 16:39:22 +0000</pubDate>
		<dc:creator>Atamert Ölçgen</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[kate]]></category>
		<category><![CDATA[pate]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.muhuk.com/?p=60</guid>
		<description><![CDATA[Pâté is a plugin for Kate (of KDE Desktop) that exposes editor&#8217;s functionality to Python. In short; with Pâté, you can write Kate plugins in Python. I use Kate for (almost) all my text editing. I think it suits my needs perfectly. It is both as simple as I would be comfortable with and has [...]<div><a class="addthis_button" href="//addthis.com/bookmark.php?v=250" addthis:url='http://www.muhuk.com/2008/11/extending-kate-with-pate/' addthis:title='Extending Kate With Pâté '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div>]]></description>
			<content:encoded><![CDATA[<p><a href="http://paul.giannaros.org/pate/">Pâté</a> is a plugin for <a href="http://kate-editor.org/">Kate</a> (of KDE Desktop) that exposes editor&#8217;s functionality to <a href="http://www.python.org/">Python</a>. In short; with Pâté, you can write Kate plugins in Python.</p>

<p>I use Kate for (almost) all my text editing. I think it suits my needs perfectly. It is both as simple as I would be comfortable with and has as many features (such as multi document interface, regex search and replace, etc.) as I need to be productive. I am not an <a href="http://en.wikipedia.org/wiki/Integrated_development_environment">IDE</a> person. Nothing against IDE&#8217;s, I have just never been comfortable with them. On the other side I have never taken the time to learn the classic (read antique) editors such as Emacs and Vim. I am sure learning them would be <a href="http://steve-yegge.blogspot.com/2008/04/xemacs-is-dead-long-live-xemacs.html">worth my time</a>. But I doubt I will ever take the time for that. At present, I just fire up my Kate and it works pretty well.</p>

<p>Meanwhile, I keep hearing about these neat hacks with Emacs that when you do <code>C-t</code>, <code>C-M-w</code> and then <code>C-k</code> your active buffer is translated to Chinese and then automatically sent to your grandmother&#8217;s cell phone as SMS. Wow! And you can write your own macros (in Lisp, <a href="http://en.wikipedia.org/wiki/Emacs_Lisp">elisp</a>) to extend the editor&#8217;s capabilities. There is virtually no limit to what you can do and it is not rare that these extensions exceed the borders of an editor. Of course you have to use (and learn) Emacs to take advantage.</p>

<p>This was true, before I discovered Pâté. It was always possible to write plugins for Kate, but Kate was not <em>scriptable</em>. Now using Pâté, you can extend Kate with ease (at least much much easier than writing C). The only thing that bugs me is I couldn&#8217;t figure out a way to reload my plugins without restarting Kate.</p>

<h3>Creating Simple Pâté Plugins</h3>

<p>The first plugin we write will turn the selection into a Django password hash. I use this when I want to create initial_data fixtures for <code>User</code>&#8216;s quickly.</p>

<p>Since we do not want to instantiate a complete Django environment we won&#8217;t be able to import anything from <code>django.contrib.auth.models</code>. Instead let us copy a dumbed down version of <code>get_hexdigest</code> into our own module.</p>

<pre><code>import random


def get_hexdigest(algorithm, salt, raw_password):
    try:
        import hashlib
    except ImportError:
        import sha
        return sha.new(salt + raw_password).hexdigest()
    else:
        return hashlib.sha1(salt + raw_password).hexdigest()
</code></pre>

<p>It should be clear enough, it returns a hash of the given password using the given salt[1]. Now we simply add <code>kate</code> to our imports (remember <code>kate</code> and not <code>pate</code>):</p>

<pre><code>import kate
</code></pre>

<p>And add our own callback code:</p>

<pre><code>@kate.onAction('Django Password', 'Shift+Alt+P')
def setPassword():
    v = kate.view()
    raw_password = v.selection.text
    v.selection.removeSelectedText()
    algo = 'sha1'
    salt = get_hexdigest(algo, str(random.random()), \
        str(random.random()))[:5]
    hsh = get_hexdigest(algo, salt, raw_password)
    v.insertText('%s$%s$%s' % (algo, salt, hsh))
</code></pre>

<p>The first line makes our function kate-aware. <code>'Django Password'</code> will be the label for our menu item (it will be listed under <code>Tools</code>) and <code>Shift-Alt-P</code> will be the keyboard shortcut. The rest of the code should be self-explanatory.[2]</p>

<p>Now we copy our module into ~/.kde/share/apps/kate/pyplugins/ and restart Kate. It should show up in the menu and work now.</p>

<p>Second example is a JSON prettifier. I use JSON format for my fixtures, but valid JSON is not very readable. So I have this small plugin to convert a document between JSON and Python literals:</p>

<pre><code>import sys, pprint
import kate
from django.utils import simplejson


HEADER = '# Pretty Printed\\n'

@kate.onAction('Django Pretty Json', 'Shift+Alt+J')
def togglePrettyJsonFormat():
    d = kate.document()
    source = d.text
    if source.startswith(HEADER):
        target = simplejson.dumps(eval(source))
    else:
        pp = pprint.PrettyPrinter(indent=2)
        target = HEADER + pp.pformat(simplejson.loads(source))
    d.text = target
</code></pre>

<p>I need <code>HEADER</code> to distinguish between two states. It can actually be anything, but it would be a good idea to make it a quote to have valid Python just in case.</p>

<h3>Pâté Is Fun</h3>

<p>I have enjoyed experimenting with Pâté. I hope it gets more attention and therefore ends up a much better plugin. If you ask me it should already ship with Kate. Kate is a nice editor, and empowering the users would only make it nicer and more popular.</p>

<p>If you have any ideas for pâté plugins, especially stuff that is useful in Django context, please add it to the comments. I would love to play a little more with pâté.</p>

<hr />

<p><strong>1</strong>: If it is not clear, take a look at <a href="http://code.djangoproject.com/browser/django/tags/releases/1.0/django/contrib/auth/models.py"><code>django.contrib.auth.models</code></a>.</p>

<p><strong>2</strong>: To learn API, you can fire up <code>Interactive Console</code> under <code>View</code> and type <code>help(kate)</code>.</p>
<div><a class="addthis_button" href="http://www.muhuk.com//addthis.com/bookmark.php?v=250" addthis:url='http://www.muhuk.com/2008/11/extending-kate-with-pate/' addthis:title='Extending Kate With Pâté '><img src="//cache.addthis.com/cachefly/static/btn/v2/lg-share-en.gif" width="125" height="16" alt="Bookmark and Share" style="border:0"/></a></div><p>Related posts:<ol>
<li><a href='http://www.muhuk.com/2011/06/pycon-apac-optimizing-media-performance-with-django_compressor/' rel='bookmark' title='My PyCon APAC 2011 Presentation: Optimizing Media Performance with django_compressor'>My PyCon APAC 2011 Presentation: Optimizing Media Performance with django_compressor</a></li>
<li><a href='http://www.muhuk.com/2011/11/working-with-files-in-django/' rel='bookmark' title='Working with files in Django &#8211; Part 1'>Working with files in Django &#8211; Part 1</a></li>
<li><a href='http://www.muhuk.com/2011/11/working-with-files-in-django-part-2/' rel='bookmark' title='Working with files in Django &#8211; Part 2'>Working with files in Django &#8211; Part 2</a></li>
</ol></p> <p><a href="http://www.muhuk.com/?flattrss_redirect&amp;id=60&amp;md5=466b185663234ec6cd1e3e8bf05d3cf8" title="Flattr" target="_blank"><img src="http://www.muhuk.com/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.muhuk.com/2008/11/extending-kate-with-pate/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<atom:link rel="payment" href="http://www.muhuk.com/?flattrss_redirect&amp;id=60&amp;md5=466b185663234ec6cd1e3e8bf05d3cf8" type="text/html" />
	</item>
	</channel>
</rss>

