The great moment: first entry through vim!

ethan on 2002-11-11T13:20:23

Aren't I astonishing? I finally made it to make my first journal entry with vim.

It turned out to be a long fight. Initially, it did not work for a silly typo I made when using jjohn's code as a template. I should have used copy-and-paste instead.

I still need to do a couple of things though. Most notably, finally implement the delete action plus modifying entries. Also, before I make this thing public I really should clean it up a little. The vim-script part of the whole matter is so badly written it makes you cry. This mixture of vim-scripting and Perl is obviously something I don't have much experience with. It is not half as well and cleanly written as jjohn's emacs-equivalent. Want to get a taste of the mess? Here we go (also a good test what happens when I dump raw code into my vim buffer):

function! Use_perl_submit() let g:success = 0 perl <<EOP require Use_Perl_from_vim; my @content = map { $_ . "\n" } $curbuf->Get(1 .. $curbuf->Count); my $subject = VIM::Eval("g:newentry_subject"); my $res = Use_Perl_from_vim::add_entry($subject || "no subject", \@content); print $res, "\n"; VIM::DoCommand("let g:success = \"$res\""); EOP

if g:success != 0 1,%delete let g:newentry_subject = "" echohl Normal | echo "Submit ok. New ID is ".g:success | echohl None perl <<EOP $curwin->SetHeight(5); my $idxw = VIM::Windows(1); my $idxb = $idxw->Buffer; $idxw->SetHeight($idxb->Count <= 7 ? $idxb->Count : 7); sleep(1); EOP call Restore_title(1) else echohl ErrorMsg | echo "Submit failed!" | echohl None perl sleep 1; endif unlet g:success redraw! endfunction


Could be cleaner, couldn't it? Alas, rafaël told me that baby-vim is ok. Hope he remembers.


Great!

rafael on 2002-11-11T20:13:48

I'll give it a try -- if I figure out how to port it to a non-perl-enabled vim. (On the other hand, I compile from time to time vim with bleadperl, just to check it works.)

Re:Great!

ethan on 2002-11-11T21:02:35

I'll give it a try -- if I figure out how to port it to a non-perl-enabled vim.

Short ago I wanted to remove the Perl-interpreter dependency but abolished this idea temporarily. The script uses three windows inside vim and, oddly enough, I was only able to set their size and some other properties through the Perl extension. I know there are means to do it with vim-scripting but I wasn't able to find them.

Other than that, it should not be that hard. The module can easily be made polymorphic in that it could also be used as a stand-alone script that gets its data through STDIN. Just as jjohn did it.

I just added a README and packed it all up in a tarball so if anyone is interested it can be retrieved from here. A little bit of polishing would do no harm, but basically it should be usable.