[Vim-l] Template:Help - Simple fixes

Sebastian Menge sebastian.menge at uni-dortmund.de
Tue Jun 26 07:44:14 UTC 2007


On Tue, 26 Jun 2007, John Beckett wrote:

> However what it gets back is a redirect to "xxx.sourceforge.net"
> (with no #word). That causes the three browsers I've tried to
> forget about the #word anchor.

Hi all

Ive made a copy of the script named "help-dev". It uses 
1) a sourceforge instead of sf as requested.
2) a second optional parameter "urlencode" that defaults to false.

So if you want to have the script to urlencode the parameter "tag" just
write something like
http://vimplguin.sourceforge.net/help-dev?tag=<tab>&urlencode=1

I also would like to have that script on vimdoc.sf.net, I posted a
request to them, but there was no reaction. I also asked Bram where to
put it - no reaction either. So I simply put it somewhere I had access
to. If some of you wanted to hack it, you could join the
vimplugin-project on sf.net and I could give group-write permission on
the script. Python is very easy to learn.

If that script is ok as it is, I will copy it back to "help"

Sebastian.
-------------- next part --------------
#!/usr/bin/python

import sys
import cgi
import os
import urllib

#global variables
#TODO: tags-file needs to be updated from time to time?
tagsfile="./tags"
baseurl="http://vimdoc.sourceforge.net/htmldoc/"
ext=".html"

#defaults to false
urlencode = False

if __name__ == '__main__':
    form = cgi.FieldStorage()

    #check urlencode parameter
    if form.has_key("urlencode"):
        urlencode = form["urlencode"]==1

    if form.has_key("tag") and form["tag"].value != "":
        #urlencode if necessary
        if urlencode:
            tag = urllib.urlencode(form["tag"].value)
        else:
            tag = form["tag"].value

        #read tags file
        files = dict()
	if not os.path.exists(tagsfile):
            print "Content-type: text/html\n"
            print "<h1>Error! Tagfile not found.</h1>"
        f = open(tagsfile)
        try:
           for line in f:
               a,b,c = line.split()
               files[a] = b
        finally:
           f.close()
    
        #do the actual redirect or print error
        try:
            print "Status: 302 Found"
            print 'Location: '+baseurl+files[tag].replace('.txt',ext)+'#'+tag
        except KeyError:
            print "Content-type: text/html\n"
            print "<h1>Error! Tag \"%s\" not found in help!</h1>"%tag
            print 'Location: '+baseurl+files[tag].replace('.txt',ext)
    	
    else:
        print "Content-type: text/html\n"
        print "<h1>Error! No tag given!</h1>"


More information about the Vim-l mailing list