tag:blogger.com,1999:blog-74383320295229928002024-03-08T07:47:07.523-08:00thomas blogA blog about all the things I want to write about, mostly things I have interest in, like: python, vim, linux, kubuntu, kde,...thomashttp://www.blogger.com/profile/13728973542307461536noreply@blogger.comBlogger13125tag:blogger.com,1999:blog-7438332029522992800.post-20929020958356101352009-01-10T05:17:00.000-08:002009-01-10T05:49:09.029-08:00Some days ago I discovered <a href="http://labs.mozilla.com/2008/08/introducing-ubiquity/">ubiquity</a> and I like it very much.<br />Because I use google define a lot, I wrote a very simple script for it.<br />You can find my script here: <a href="http://gist.github.com/45454">http://gist.github.com/45454</a> (I just changed the default google search script)<br /><br />To use it, install the script, launch ubiquity and then just type <span style="font-family: courier new;">gdefine [word]</span>, or type gdefine with a selected word and press enter. It's that simple :-)<br /><br />I use this script all the time, so I hope it's useful for some of you! (there is already a define script but that uses <a href="http://www.answers.com">http://www.answers.com</a> but I don't like it as much as google define)<br /><br />Other commands that I recommend: switching tabs (just type the name of the tab), tagging sites (<span style="font-family: courier new;">tag [tag1 tag2 ...]</span>), <a href="http://www.rememberthemilk.com">remember the milk</a> commands (you can find it <a href="http://garyhodgson.github.com/ubiquity-rtm-api/">here</a>), <a href="http://www.twitter.com">twitter</a>thomashttp://www.blogger.com/profile/13728973542307461536noreply@blogger.com12tag:blogger.com,1999:blog-7438332029522992800.post-48585660192159810832008-12-03T06:13:00.000-08:002008-12-03T06:30:54.894-08:00How I organize my gmailSince I first started using gmail, I started using labels for everything. Every time I start a new project or subscribe to some mailing list I created a new label (mostly with a corresponding filter) without thinking too much about how I ordered them. At first this was no real problem, but after a while I had too much unordered labels. You can Imagine the clutter. The moment gmail introduced labs and with it, the quick links feature, I rejoiced. I started saving links for all my most used labels.<br />But this was definitely no solution for the problem. So I recently decided it was time to think about a real solution.<br />I started reading blogs about how other people organize their mail. Soon I came to the conclusion that all those solutions are good in a certain way, but they didn't suffice for me.<br />So In this post I'll explain what I do want, how my labels look now and what gmail still lacks.<br /><br /><h2> What do I want? </h2> I want to organize my mail so that I don't need to spend much time organizing it (apart from spending quite a lot of time with this now). This means that I have to be able to quickly process and search mail.<br /><br /><u>The most important things are these:</u><br /><div> <ul><li> I need to be able to access my most accessed labels fastest. </li></ul> <div style="margin-left: 40px;"> Quick search is a bit of a solution for this, but only a partial solution, it can still take some time to give a label to a mail if you have to search the label way down on the list. So my labels need a good and logical order.<br /></div> <ul><li> I don't want an inbox full of mails.</li></ul> <div style="margin-left: 40px;"> This means that I need to be able to label mail or to archive it the moment I read it.<br /></div> <ul><li> Things I don't need may not clutter my mail.</li></ul> <div style="margin-left: 40px;"> Archive/delete those messages at once. (I almost never delete mail)<br /></div> <ul><li> I don't want to spend my time on mail I don't need.</li></ul> <div style="margin-left: 40px;"> There are three things you can do here: If this is a message from something you can unsubscribe easily, do that, if not mark it is as spam and if that doesn't work, create a filter to mark the message as read and archive it.<br /></div> <ul><li> Be able to decide whether a message is important to read now or if it can wait.</li></ul><br /></div> <h2> Organizing my labels </h2> <div> <div> <div> <u>I use a prefix to create a first ordering.</u> <div> Things I am working on now, and thus have to access often have a _ as prefix so it's on top of the list: </div> <div> _/study/project </div> <div> If I'm finished with the project or task, I label them with a P (for processed and it doesn't clutter my first labels): </div> <div> P/study/project.<br />When you rename this task, you can also add a timestamp for projects that return every year or every month, or you can sort the label more fine grained.<br /> </div> <div> Things I always need like personal or important mails, those I label with an A (for always and just below the _) </div> <div> A/important<br /> A/notes<br />If you have many labels that are only for personal use, you could create a secondary ordering for example A/me/important.<br /> </div> <div> </div> <div><u> Other labels I use </u></div> <div> things I almost never need: Z (way down)<br />If you create a label Z/unimportant you should delete that label and archive those mails as they are unimportant anyway! I use the Z label for backups of old mail, or for my starred messages as sometimes desktop mail clients delete all the stars.<br />The important remark here is that you should only label those messages with a Z that you want to find later, mail that you'll never need again needs to be archived.<br /> <br /> </div> <div> mailing lists: L<br />You should make a filter for mailing lists. If you make the filter so that you never look at the mail anymore, you should unsubscribe from the list </div> <div> </div> <div> You can use as many prefix as you want but a rule that I like is to keep most used labels on top with _ and A! </div> <div> Things you can filter and don't need to access often doesn't matter much, make sure they don't get on top though.<br /> <br /><u> Things that don't need a label</u><br />- all mail coming from one person, you can perfectly fine search for all that mail (from:person) and if typing that is too much, you can still create a quick link.<br /> - unimportant mail.<br /> <br /> <h2> What with new mail? </h2> </div> I try to process all incoming mail at the moment I read it. If you do have to defer it, for example when you have too much mail and don't have the time to read them all now, make a label for mail that you should access later, something like __/reply or __/waiting. I personally don't have those labels. If I label them like that, I just forget about that mail most of the time. </div> <div> <p> I think it's more useful to distinguish between important unread mails and other unread mails. That's why I have always two quick links: "important unread" and "unread". When I don't have much time I only read the important unread messages, and I can always come back to the other unread messages. </p> <p> If there are then still mails that cannot be processed right away, I keep those mails in my inbox, so that they are always there when I open my mail. But that are the only mails in my inbox.<br /> </p> <p> If you have mail that you don't need it anymore, archive it.<br /> </p> <p> <br /> </p> <h2> Some tips </h2> <ul><li> For abbreviations I use all caps, other words with all small letters. (it doesn't matter what you use, but be sure to use it everywhere to keep things clean). </li><li> I use simple and short names for labels. </li><li> I write drafts of notes/text to myself and mail them to <a href="mailto:myemail+note@gmail.com">myemail+note@gmail.com</a>. You can use the +note to create a filter and label those mails like this: A/notes. If I want to write nicely formatted text, I use google docs, and reply it to my note (the google docs gadget in labs makes drag and drop possible)<br /> </li><li> I also have a filter for unwanted mail to mark the as read and archive/delete them, I use 1 filter for that, so I don't clutter my filters to much (this has the disadvantage that this filter becomes harder to edit if it becomes bigger). </li><li> I don't keep a todo list in gmail because I forget to do those items, I use remember the milk for my todo list which you can integrate in gmail. </li></ul> <br /> <h2> What gmail still lacks </h2> <h2> </h2> Not much! that's for sure, it's becoming more and more feature complete with support for gadgets like google docs, calendar and remember the milk, quick links.<br /> But 2 more things would be great:<br />- Search labels with wild cards, so you can do something like this: search for "l:L-*" to search for all emails from mailing lists.<br />- Support for folders in the labels (there are plugins for this though, but official support would be great as the plugins don't always seem to work)<br />There is one more thing, but I don't think this is really a gmail thing. It would be great if desktop mail clients would now when an email has a double label. Not having to mark those messages as read twice would be great.<br /><br /> <h2> Conclusion </h2> I've been using this scheme now for some days and I haven't yet found any issues with it. One small thing is that you manually have to change the prefix _ to P for projects that are finished.<br /> This sort of scheme will probably not work for everybody but for me it's great so far!<br /><br /> Now it's time to sort my google reader subscriptions.<br /><br /> </div> </div> </div>thomashttp://www.blogger.com/profile/13728973542307461536noreply@blogger.com0tag:blogger.com,1999:blog-7438332029522992800.post-51004911202231672952008-02-06T13:44:00.000-08:002008-02-06T13:51:46.911-08:00My kde svn accountI applied today for an svn account and already have it :) so I just commited my first patch. It's a simple patch to the Picture Frame applet and also some refactorings. I'll sure be commiting more patches to plasma and kde.<br /><br />I also made a techbase page with all the current known plasmoids. (I still need to add those from playground) you can see the page here: <a href="http://techbase.kde.org/index.php?title=Projects/Plasma/Plasmoids">http://techbase.kde.org/index.php?title=Projects/Plasma/Plasmoids</a>thomashttp://www.blogger.com/profile/13728973542307461536noreply@blogger.com1tag:blogger.com,1999:blog-7438332029522992800.post-47209933072336006802008-01-18T02:27:00.000-08:002008-01-18T02:44:00.242-08:00I wanted an easy way of following some matches on the australian open. But since I couldn't get the IBM scoreboard working under linux<sup>1</sup> I wanted to try write something myself.<br><br>So I've come up with something really simple.<br><br>I've just made a python script and with urllib2 I pull the results and format them simply.<br><br><b>Here is the script.</b><br><br /><pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"><code>#!/usr/bin/python<br><br><br>#The players you want to follow.<br>players =["Roger Federer", "Justine Henin", "Andy Roddick", "Rafael Nadal", "Maria Sharapova", "Lleyton Hewitt", "David Nalbandian", "Amelie Mauresmo"]<br>#The maximum width of the display (maximum chars)<br>max_width= 14<br><br>#Only change below this if you know what you're doing.<br>import urllib2<br>import urllib<br><br><br>url = 'http://www.australianopen.com/en_AU/scores/index2.html'<br><br><br><br>def find_player_in_data(player, data):<br> startString = '<table width="440" height="100" border="0" cellspacing="0" cellpadding="0" background="/images/scores/ao_sc_0000g5.gif"'<br> endString = '<sup></sup></td><td width="5"><spacer type="block" height="1" width="1"></td></tr><tr><td colspan="16" height="4">'<br> index = data.find(player)<br> if index != -1:<br> index = data.find(startString, index-200)<br> endIndex = data.find(endString, index)<br> return data[index: endIndex+len(endString)]<br> else:<br> return ""<br><br>def find_numbers(data):<br> lineBegin = '<td width="1"><spacer type="block" height="1" width="1"></td><td width="19" valign="middle">'<br> lineEnd = '</sup></td>'<br> <br> first = 0<br> numbers = []<br> last = 0<br> while (first != (-1+len(lineBegin))):<br> first = data.find(lineBegin)+len(lineBegin)<br> last = data.find(lineEnd,first)<br> numbers.append(getNumber(data[first:last]))<br> data = data[last:]<br> return numbers<br> <br>def find_game_number(data):<br> firstLine = '<td width="21" valign="middle">'<br> vet = "<b><b>"<br> first = data.find(firstLine)<br> if (data.find(vet) != -1):<br> return data[first+len(firstLine):2]<br> else:<br> return data[first+len(firstLine)+len(vet):2]<br> <br>def is_serving(data):<br> """ returns if the player is serving or not"""<br> firstLine = '<td width="21" valign="middle">'<br> vet = "<b><b>"<br> first = data.find(firstLine)<br> return (data.find(vet) != -1)<br><br>def player(data):<br> start = '<td width="264" align="left" valign="middle">&nbsp;&nbsp;<a href='<br> startNext = 'class="blue">'<br> end = "</a>"<br> winner_start = '<b>'<br> winner_end = '</b>'<br> first = data.find(start)<br> next = data.find(startNext,first)<br> end = data.find(end,next)<br> player_name = data[next+len(startNext):end]<br> if player_name.find(winner_start) != -1:<br> player_name = player_name[len(winner_start):-len(winner_end)]<br> win = True<br> else:<br> win = False<br> <br> if len(player_name) > max_width:<br> player_name_list = player_name.split(" ")<br> first_len = max_width - (len(player_name_list[1])+1)<br> result = player_name_list[0][0:first_len] + " " + player_name_list[1]<br> return [result, win]<br> <br>def getNumber(char):<br> if char[0].isdigit():<br> return char[0]<br> else:<br> return ""<br> <br>def do(data):<br> if data == "":<br> return<br> <br> lastBlock = '<td width="5"><spacer type="block" height="1" width="1"></td></tr><tr>'<br> firstBlockLastIndex = data.find(lastBlock)<br> first = data[0:firstBlockLastIndex]<br> last = data[firstBlockLastIndex:]<br> first_player = player(first)<br> last_player = player(last)<br> message = ""<br> if (first_player[1] == True | last_player[1] == True):<br> message += "Completed\nWinner:\n"<br> if (first_player[1] == True):<br> winner = first_player<br> else:<br> winner = last_player<br> message += winner[0]<br> else:<br> serving_1 = is_serving(first)<br> serving_2 = is_serving(last)<br> message = join_results(first_player[0], find_numbers(first), serving_1) <br> message += "\n"<br> message += join_results(last_player[0], find_numbers(last), serving_2)<br> return message<br><br>def join_results(player, numbers, serving):<br> result = player + "\n"<br> if serving == True:<br> result+= "* "<br> else:<br> result += " "<br> result += " ".join(numbers)<br> return result<br> <br> <br>data = urllib2.urlopen(url)<br>stringData = data.read()<br> <br><br><br>for p in players:<br> data = find_player_in_data(p, stringData)<br> result = do(data)<br> if result != None:<br> print result<br><br></code></pre><br /><br><b>features:</b><br>show who's serving <br>truncate for maximum width (edit max_width in the script)<br>choose which players to follow (edit players in the script)<br>show the match winners<br><br><b>bugs/missing:</b><br>cannot show 15,30,40,AD,De (this should be simple to add, so maybe I'll add this later)<br>This script won't probably work for the double matches and if two<br />players in your list play against each other it will display the match<br />twice<br><br><b>how to use:</b><br>you can choose yourself but I use it in conky. (just add this line in conkyrc<sup>2</sup>: "${texeci 90 python ~/path/to/script.py}") (<a title="screenshot" href="http://lh5.google.com/thomas.coopman/R5CCh2wx06I/AAAAAAAAAHU/b4KY-EK8T40/snapshot1.png?imgmax=800" id="fxyf">screenshot</a>)<br>other possible use would be: a cron script and terminal, a superkaramba widget, a plasmoid,...<br><br><br>I know this is only a really simple script. There are probably better ways of doing this but it works and it was written fast.<br>If you have request, you can always ask, I'll see if I have the time for it (exams for now).<br>You can change the script as you like but if you made improvments it would always be cool if you shared them.<br><br><sup>1</sup>Didn't work in konqueror, firefox nor opera (I have flash 9 installed), I wrote them an email about this but haven't yet received a response.<br><sup>2</sup>To get conky working in kde I have installed feh and added this line to my conkyrc: "${exec feh --bg-scale `dcop kdesktop KBackgroundIface currentWallpaper 1`}" (source: <a title="http://briancarper.net/2006/08/25/transparent-conky-in-kde-part-2/" href="http://briancarper.net/2006/08/25/transparent-conky-in-kde-part-2/" id="v2x0">http://briancarper.net/2006/08/25/transparent-conky-in-kde-part-2/</a> )<br><br><br><br><br>thomashttp://www.blogger.com/profile/13728973542307461536noreply@blogger.com0tag:blogger.com,1999:blog-7438332029522992800.post-39933744924146438152007-06-25T06:03:00.000-07:002007-06-25T06:10:27.399-07:00Finally some timeThe exams are over so I have some time again to blog, and to continue work on snipper. I have some big plans for it :-)<br /><br />I want to add some features, <br />fix some bugs, <br />make it easier to adapt,<br />make it easier to make it work on windows.<br /><br />When I have done that, I'll try to write a plugin for some other text editor to use snipper, I want to see how hard that is, because I would love it if I could use snipper in more than one editor.<br />The advantages are obvious: you only need to have on template file per filetype and you can use it on all your editors.<br />This may be a bit of a dream, but it should be rather easy to let it work with at least some editors so I'll try it!<br /><br />I still haven't got much time, so the development won't be too fast for the moment.thomashttp://www.blogger.com/profile/13728973542307461536noreply@blogger.com2tag:blogger.com,1999:blog-7438332029522992800.post-87250062301507255852007-05-29T07:30:00.000-07:002007-05-29T07:33:12.228-07:00Vim colorshemeif you're looking for a good colorsheme for vim,<br />I found <a href="http://www.cs.cmu.edu/~maverick/VimColorSchemeTest/index-pl.html">this</a> sitethomashttp://www.blogger.com/profile/13728973542307461536noreply@blogger.com0tag:blogger.com,1999:blog-7438332029522992800.post-67253353504930435532007-05-29T04:14:00.001-07:002007-05-29T07:34:02.528-07:00Snipper 0.2 releasedI've just released snipper 0.2,<br /><br />snipper 0.2 is a completely refactored version of 0.1,<br />now it should work with python 2.4 and it also works when editing multiple buffers with different filetypes at the same time<br /><br />download it <a href="https://launchpad.net/snipper/trunk/0.2/+download/snipper-0.2.tar.gz">here</a><br />or on <a href="http://www.vim.org/scripts/script.php?script_id=1908">vim.org</a><br /><br />After this refactoring, I think I will be able to add new features much easier, so new features will be coming soon (but not too soon because I have to study also)thomashttp://www.blogger.com/profile/13728973542307461536noreply@blogger.com6tag:blogger.com,1999:blog-7438332029522992800.post-19977228228942530812007-05-28T06:01:00.000-07:002007-05-28T07:12:04.077-07:00Snipper video availableI made a small video of snipper in action, it's an ogg<br /><br /><a href="http://snipper.googlecode.com/files/snipper-0.1-example.ogg">http://snipper.googlecode.com/files/snipper-0.1-example.ogg</a>thomashttp://www.blogger.com/profile/13728973542307461536noreply@blogger.com0tag:blogger.com,1999:blog-7438332029522992800.post-22669720633128956652007-05-27T02:40:00.000-07:002007-05-28T07:25:53.063-07:00SnipperSnipper 0.1 released,<br /><br />After some days of working on vim scripting in python, I wanted to try the real deal, write a script that is really useful, so I wrote a snippets script for vim.<br /><br />For all of you who don't know what snippets are: snippets or templates are predefined pieces of text that you would like to insert in your text fast. You basically type an alias and press a button and the complete text is inserted.<br />I will be making a video of it soon but for now if you want more information, look at <a href="http://scribes.sourceforge.net/">http://scribes.sourceforge.net/</a> or at <a href="http://macromates.com/">http://macromates.com/</a>, two cool editors for if you don't know vim :-)<br /><br />So now everyone knows what snippets are, I can continue my explanation of my script that you can find on <a href="https://launchpad.net/snipper/">https://launchpad.net/snipper/</a>, download it <a href="https://launchpad.net/snipper/+download">here</a><br />Documentation will be available very soon. (for installation and use)<br /><br />This is the first version of the script, so expect some bugs. If you find any bugs that haven't been posted, please do (<a href="https://bugs.launchpad.net/snipper/">https://bugs.launchpad.net/snipper/</a>)<br /><br />I hope you like this script (if you do, please add a comment) and stay tuned for more info.thomashttp://www.blogger.com/profile/13728973542307461536noreply@blogger.com1tag:blogger.com,1999:blog-7438332029522992800.post-54964035601055755262007-05-23T00:24:00.000-07:002007-05-23T00:47:45.153-07:00some helpful vim tipsHi,<br /><br />In this blog I want to show a few helpful tips about vim, that you can use in my tutorials about vim scripting in python<br /><br /><span style="font-weight: bold;">first of all</span><br />everyone should know the help command!<br /><span style="font-family: courier new; font-weight: bold;">:help somecommand</span><br /><br /><span style="font-weight: bold;">syntax highlighting on in console</span><br /><span style="font-weight: bold; font-family: courier new;">:syn on</span><br /><br /><span style="font-weight: bold;">set commands based on filetype</span><br />first set<br /><span style="font-weight: bold; font-family: courier new;">:filetype on</span><br />now, vim will try to recognize the type of file you are editing,<br />then you can use<br /><span style="font-family: courier new; font-weight: bold;">au FileType python source /path/to/python/commands</span><br /><br />au, automatically execute on event<br />source, read the source file with commands<br /><br /><span style="font-weight: bold;">execute command from .vimrc without having to press enter</span><br /><span style="font-family: courier new; font-weight: bold;">:someCommand()^M</span><br />and ^M you have to enter by typing <ctrl-v><ctrl-m> (so pressing those combinations)thomashttp://www.blogger.com/profile/13728973542307461536noreply@blogger.com0tag:blogger.com,1999:blog-7438332029522992800.post-35880345075504417902007-05-21T00:36:00.000-07:002007-05-23T01:45:54.094-07:00python scripting in vim (2)Hi,<br /><br />Hopefully you all found my first tutorial helpfull,<br />this will be a second more advanced tutorial about scripting vim in python.<br />In this tutorial we will make a script to test if your python script doesn't contain syntax errors, we will use pyflakes for this<c-v><br /><br />let' s get started with the module pyflakse,<br />you can find pyflakes on http://divmod.org/trac/wiki/DivmodPyflakes<br />install it on ubuntu: apt-get install pyflakes<br /><br />We will use pyflakes because it is fast, if you're interested you can also look at pylint and pychecker.<br /><br /><span style="font-weight: bold;">first let's do some tests with pyflakes</span><br />open some python interpreter:<br /><br /><span style="font-weight: bold;font-family:courier new;" ><br />>>>file = "/path/to/file"<br />>>>code = open(file, 'r').read()<br />>>>tree = compiler.parse(code)<br />>>>w = pyflakes.Checker(tree)<br />>>>for warning in w.messages: print warning<br /></span><br /><br />if your file contains an error, it should be shown. If the code has a syntax or indentation error, the compiler fase will fail but we will handle that in the script.<br /><br /><span style="font-weight: bold;">Now lets write this in a vim script,</span><br />we will write this script in a seperate file,<br />this is because we can keep or .vimrc clean and because we only want to load this file when we are editing python scripts (see <a href="http://tmske.blogspot.com/2007/05/some-helpful-vim-tips.html">this</a> blog)<br /><br />the script we will write, will toggle a buffer to show the errors. If no errors are found the scirpt will just write a message.<br />We write 4 functions,<br />checkSyntax<br />doSyntaxCheck<br />closeBuffer<br />bufferOpen<br /><br />checkSyntax is the main function that you have to call when you want to have a map to this script<br /><br /><span style="font-weight: bold;font-family:courier new;" ><br />#!/usr/bin/python<br /><br />import vim<br />import pyflakes<br />import compiler<br /><br />def checkSyntax():<br /><dir>"""This function checks if the output buffer is already open. If it is open,<br />we will close it (because we want to toggle). If it is not open, we will<br />create<br />the output buffer and do the real syntax check with (doSyntaxCheck)<br />"""<br />#first save the current buffer<br />current = vim.current.buffer<br />#check if the buffer is open<br />b = bufferOpen()<br />if not b:<br /><dir>vim.command("bel silent new output")<br />output = vim.current.buffer<br />doSyntaxCheck(current, output)</dir><br />else:<br /><dir>closeBuffer(b)</dir></dir><br /><br />def doSyntaxCheck(current, output):<br /><dir>"""This function will do the real syntax check, first we will create a string<br />that contains<br />the current buffer, we will then try to parse the code with compiler and then<br />run pyflakes on it.<br />All errors are printed in the output window, if no errors are found, a message<br />is printed and the buffer is closed again<br />"""<br />#convert the list of lines to a string<br />code = "\n".join(current)<br />try:<br /><dir>tree = compiler.parse(code)</dir><br />except (SyntaxError, IndentationError), inst:<br /><dir>output[0:0] = [str(inst).strip()]</dir><br />else:<br /><dir>w = pyflakes.Checker(tree)<br />w.messages.sort(lambda a,b: cmp(a.lineno, b.lineno))</dir><br />if w.messages:<br /><dir>for warning in w.messages:<br /> <dir>output[0:0] = [str(warning).strip()]</dir></dir><br />else:<br /><dir>closeBuffer(output)<br />print "code ok"</dir></dir><br /><br />def bufferOpen():<br /><dir>"""This function checks all the buffers if a buffer with a name containing<br />output exists. If it exists we return that buffer, else we return None<br />"""<br />for b in vim.buffers:<br /><dir>if "output" in b.name:<br /><dir>return b</dir></dir><br />return None</dir><br /><br />def closeBuffer(buffer):<br /><dir>"""Completely delete buffer"""<br />cmd = "bwipeout! " + buffer.name</dir><br />vim.command(cmd)</span><br /><br /><span style="font-weight: bold;">Stay tuned...</span><br />I hope you all liked this tutorial.<br />reactions are always welcome, and I'll do my best to publish a new tutorial soon!</c-v>thomashttp://www.blogger.com/profile/13728973542307461536noreply@blogger.com5tag:blogger.com,1999:blog-7438332029522992800.post-23859877399872415112007-05-20T01:01:00.001-07:002007-05-21T00:26:09.733-07:00My first blogHi,<br /><br />I just started a blog,<br />I will try to write regular about things I'm most interested in, like linux, ubuntu, python, kde.<br /><br />Hopefully you like it,<br /><br />Thomasthomashttp://www.blogger.com/profile/13728973542307461536noreply@blogger.comtag:blogger.com,1999:blog-7438332029522992800.post-77395042465599527642007-05-20T00:57:00.000-07:002007-05-21T00:26:50.199-07:00python scripting in vim (1)This is a short tutorial about writing vim scripts in python.<br />This tutorial is for everyone who likes vim and python.<br /><br /><font style="font-weight: bold;">Preperations:</font><br /><br />To write vim scripts in python you need to have vim compiled with +python<br /><br /><font style="font-style: italic;">Fedora/CentOS: vim-enhanced</font><br /><font style="font-style: italic;">Debian/Ubuntu: vim-python</font><br /><br /><font style="font-weight: bold;">Let's get started:</font><br /><br />first a thing about how you can use python for vim-scripting,<br />you can set these things in your <font style="font-style: italic;">~/.vimrc</font><br /><ul><li><font style="font-style: italic;">autocmd FileType python [commands]</font><br />Run commands when this type of file is edited </li><li><font style="font-style: italic;">python [python code]</font><br />Evaluate the python code given<br /></li><li><font style="font-style: italic;">python << EOF</font><br />Read python code untill the EOF</li><li><font style="font-style: italic;">pyfile [filename]</font><br />Read python commands from a python file<br /></li><li><font style="font-style: italic;">map [keys] [command]</font><br />Run the specified command when the key(s) are pressed</li></ul><font style="font-weight: bold;">Simple start...</font><br /><font style="font-weight: bold;" face="courier new"><br />"first tutorial hello world<br />imap & <Esc>:python pythonHelloWorld()<br />python << EOF<br /><br />#start the function<br />def pythonHelloWorld():<br /><dir>import vim #so you can use the vim functions<br />buffer = vim.current.buffer #returns the current buffer<br />buffer[0] = "hello world"<br />#sets the first line of the buffer to "hello world"</dir><br />EOF<br /></font><br /><font style="font-weight: bold;">What we have so far</font><br />a line starting with " is a comment in the .vimrc<br /><font style="font-weight: bold;" face="courier new"><br />imap & <Esc>:python pythonHelloWorld()<br /></font><br />press the & in insert mode to execute the command :python pythonHelloWordl(), notice the <Esc> so you leave insert mode and go to the command mode.<br /><font style="font-weight: bold;" face="courier new"><br />python << EOF</font><br />everything between these lines will be read as python code<br /><br /><br /><font style="font-weight: bold;">slightly improved version</font><br />We will improve the previous version so that we insert the "hello world" line before the current line, so we don't overwrite anything.<br /><font style="font-weight: bold;" face="courier new"><br />def pythonInsertHelloWorld():<br /><dir>import vim<br />buffer = vim.current.buffer<br />#returns the row and column of the current cursor<br />#position<br />(row, col) = vim.current.window.cursor<br />#python starts numbering from 0, vim from 1.<br />#insert line above current cursor position<br />#the argument must be a list, or it won't work<br />buffer[row-1:row-1] = ["hello world"]<br /></dir>EOF<br /></font><br /><br /><font style="font-weight: bold;">and further...</font><br />this was the first really basic tutorial, more will follow soon, but you should have a start now.<br />If you have questions, see mistakes or have comments, please add your reaction.<br /><br /><br /><font style="font-weight: bold;">see also:</font><br />about python scripting:<a href="http://www.tummy.com/Community/Presentations/vimpython-20070225/vim.html">http://www.tummy.com/Community/Presentations/vimpython-20070225/vim.html</a><br />in vim :help python<br />help about map: <a href="http://www.linux.com/article.pl?sid=06/06/08/1431210">http://www.linux.com/article.pl?sid=06/06/08/1431210</a>thomashttp://www.blogger.com/profile/13728973542307461536noreply@blogger.com