Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

ethan (3163)

ethan
  reversethis-{ed. ... rap.nov.olissat}

Being a 25-year old chap living in the western-most town of Germany. Stuying communication and information science and being a huge fan of XS-related things.

Journal of ethan (3163)

Monday November 11, 2002
08:20 AM

The great moment: first entry through vim!

[ #8876 ]

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.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • 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.)
    • 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 coul