Peter's Blog 30.4.2004

2004-04-30

More VIM based editing.

I don't know how long I can go on posting the evolution of this but anyway.

  • PostBlog now marks buffers as unmodified as after posting they do not need to be written to disk.

  • ReadBlog will now default to reading the last posted entry as that is most likely to need modifying.

def PostBlog():
  
import xmlrpclib
  
import re

  
#
  
# If first line contains a blog entry ID then edit existing post,
  
# otherwise write a new one.
  
#
  
nFirstLine = 0
  
strID = vim.current.buffer[0]
  
if not re.match( '^P\d+$', strID):
    
strID = ''
  
else:
    
nFirstLine = 1

  
strTitle = im.current.buffer[nFirstLine]
  
strText = "\n".join( vim.current.buffer[2:])

  
oPyds = xmlrpclib.ServerProxy( 'http://localhost:4334/RPC2')

  
oPost = { 'title': strTitle,
            
'description': strText}

  
if strID == '':
    
strID = oPyds.metaWeblog.newPost( '', 'peter', 'wibble', oPost, 1)
  
else:
    
bSuccess = oPyds.metaWeblog.editPost( strID, 'peter', 'wibble', oPost, 1)

  
print "Posted entry %s" % strID

  
#
  
# Don't intend to write posts to disk so unmodify the buffer and
  
# allow easy quit from VIM.
  
#
  
vim.command( 'set nomodified')

def ReadBlog( strID = None):
  
import xmlrpclib

  
oPyds = xmlrpclib.ServerProxy( 'http://localhost:4334/RPC2')
  
if strID:
    
oBlog = oPyds.metaWeblog.getPost( strID, 'peter', 'wibble')
  
else:
    
oBlogs = oPyds.metaWeblog.getRecentPosts( '', 'peter', 'wibble', 1)
  
oBlog = oBlogs[0]
  
strID = oBlog['postid']

  
vim.current.buffer[:] = []
  
vim.current.buffer[0] = strID
  
vim.current.buffer.append( oBlog['title'])
  
vim.current.buffer.append( '')
  
for strLine in oBlog['description'].split('\n'):
    
vim.current.buffer.append( strLine)
posted at 12:50:24    #    comment []    trackback []
 

Smileys

What has happened to my text smileys Unsmiley

This is the magic of shortcuts. Here are some I prepared earlier. Python is the language of my dreams. Microsoft is the company of my nightmares.

posted at 12:26:56    #    comment []    trackback []
 

Scrolling preformatted text

Something I noticed on the PYDS site is how a code snippet was in a box that could scroll horizontally. This is useful as it stops preformatted text from making the page grow too wide to be displayed nicely. The secret seems to be this:

.literal-block {
    overflow
: auto;
}

Here is an example:

This is a very long line of stuff. It is too long to go on one line and as it is preformatted it will not word wrap. You can scroll it horizontally.

Magical. It works in Mozilla but not in IE 5.0: that just creates a very wide web page. I'm not sure I have access to a later I.E. here at work.

Update: This makes Mozilla 1.6 on my laptop at home hang, gobbling cpu time and it doesn't work on IE6, so I ripped it out and reformatted the long lines.

posted at 11:57:04    #    comment []    trackback []
 

More VIM Editing

I cannot leave these things alone.

#
# Post a new blog item or write the changes to an existing item.
#
def PostBlog():
  
import xmlrpclib
  
import re

  
#
  
# If first line contains a blog entry ID then edit existing post,
  
# otherwise write a new one.
  
#
  
nFirstLine = 0
  
strID = vim.current.buffer[0]
  
if not re.match( '^P\d+$', strID):
    
strID = ''
  
else:
    
nFirstLine = 1

  
strTitle = vim.current.buffer[nFirstLine]
  
strText = "\n".join( vim.current.buffer[2:])

  
oPyds = xmlrpclib.ServerProxy( 'http://localhost:4334/RPC2')

  
oPost = { 'title': strTitle,
        
'description': strText}

  
if strID == '':
    
strID = oPyds.metaWeblog.newPost( '', 'peter', 'wibble', oPost, 1)
  
else:
    
bSuccess = oPyds.metaWeblog.editPost( strID, 'peter', 'wibble', oPost, 1)

  
print "Posted entry %s" % strID

#
# Edit an existing post.
#
def ReadBlog( strID):
  
import xmlrpclib

  
oPyds = xmlrpclib.ServerProxy( 'http://localhost:4334/RPC2')
  
oBlog = oPyds.metaWeblog.getPost( strID, 'peter', 'wibble')
  
vim.current.buffer[:] = []
  
vim.current.buffer[0] = strID
  
vim.current.buffer.append( oBlog['title'])
  
vim.current.buffer.append( '')
  
for strLine in oBlog['description'].split('\n'):
    
vim.current.buffer.append( strLine)

It seems to work.

posted at 11:29:20    #    comment []    trackback []
 

Syntax Highlighted Entries

If this works it will be really cool.

def HelloWorld():
  
print 'Hello World'

Well blow me. NOTE: two colons, case sensitive language name.

void HelloWorld() {
  
printf( "Hello World\n");
}

I installed the SilverCity python package and rebooted PYDS.

Does it support shitty languages?

System Message: ERROR/3 (<string>, line 20)

No SilverCity lexer found for language 'VB'.

.. code-block:: VB

    Sub HelloWorld()
        MsgBox "Hello World"
    End Sub

That would be a No.

I edited this entry using this:

def ReadBlog( strID):
  
import xmlrpclib

  
oPyds = xmlrpclib.ServerProxy( 'http://localhost:4334/RPC2')
  
oBlog = oPyds.metaWeblog.getPost( strID, 'peter', 'wibble')
  
vim.current.buffer[:] = []
  
vim.current.buffer.append( oBlog['title'])
  
vim.current.buffer.append( '')
  
for strLine in oBlog['description'].split('\n'):
    
vim.current.buffer.append( strLine)

def WriteBlog( strID):
  
import xmlrpclib

  
strTitle = vim.current.buffer[0]
  
strText = "\n".join( vim.current.buffer[2:])

  
oPyds = xmlrpclib.ServerProxy( 'http://localhost:4334/RPC2')

  
oPost = { 'title': strTitle,
        
'description': strText}

  
strID = oPyds.metaWeblog.editPost( strID, 'peter', 'wibble', oPost, 1)

  
print "Posted entry %s" % strID

Good isn't it?

posted at 10:48:48    #    comment []    trackback []
 

Posting Blog Entries from VIM

This is as easy as:

def PostBlog():
  import xmlrpclib

  strTitle = vim.current.buffer[0]
  strText = "\n".join( vim.current.buffer[2:])

  oPyds = xmlrpclib.ServerProxy( 'http://localhost:4334/RPC2')

  oPost = { 'title': strTitle, 'description': strText}

  strID = oPyds.metaWeblog.newPost( '', 'peter', 'wibble', oPost, 1)

  print "Posted entry %s" % strID

Ok, this uses VIM with python support.

posted at 09:34:08    #    comment []    trackback []
April 2004
MoTuWeThFrSaSu
    1 2 3 4
5 6 7 8 91011
12131415161718
19202122232425
2627282930  
Mar
2004
 May
2004

A blog documenting Peter's dabblings with Python, Gentoo Linux and any other cool toys he comes across.

XML-Image Letterimage

© 2004, Peter Wilkinson

Bisi and me