pyblosxom.vim
author Luke Macken <lewk@csh.rit.edu>
Sat Sep 01 05:37:40 2007 -0500 (10 months ago)
changeset 0 c8f7d7acfd31
permissions -rw-r--r--
Initial import
        1 " pyblosxom.vim
        2 " Handy functionality for using a Pyblosxom blog.
        3 " Based on the work done by Jordan Sissel,
        4 "    http://www.semicomplete.com/blog/geekery/pyblosxom-mdate-vim-hack.html
        5 
        6 augroup pybloxsom
        7     autocmd BufReadPost /home/derb/blog/entries/*/*/*/*.txt call Pybloxsom_checkdate()
        8     autocmd BufNewFile /home/derb/blog/entries/*/*/*/*.txt call Pybloxsom_putdate()
        9     autocmd BufWritePost /home/derb/blog/entries/*/*/*/*.txt call Pybloxsom_fudgedate()
       10 augroup end
       11 
       12 function Pybloxsom_checkdate() 
       13     " Look in the file for '#mdate foo' metadata
       14     normal 1G
       15     let dateline = search("^#mdate")
       16 
       17     " If not found, append the mdate of the file to line 2
       18     if dateline < 1
       19         let date = system("stat -c '#mdate %Sm' " . expand("%"))
       20 
       21         " Add the date to the file on line 1
       22         1put=date
       23     endif
       24 endfunction
       25 
       26 function Pybloxsom_putdate()
       27     let date=strftime("#mdate %b %e %H:%M:%S %Y")
       28     1put=date
       29     goto 1
       30 endfunction
       31 
       32 function Pybloxsom_fudgedate() 
       33     " Mark our position
       34     normal mZ
       35 
       36     " Find mdate
       37     let l=search("^#mdate")
       38     let l=strpart(getline(l), 7)
       39     let cmd="date -d '" . l . "' +%y%m%d%H%M"
       40     echo cmd
       41     let touchtime=system(cmd)
       42     let touchcmd="touch -t '" . strpart(touchtime,0,strlen(touchtime)-1) . "' '" . expand("%") . "'"
       43     echo touchcmd
       44     call system(touchcmd)
       45 
       46     " Reload the file (make vim notice the date change)
       47     e
       48 
       49     " Jump back to our old position
       50     normal `Z
       51   echo "Fudged date"
       52 endfunction