vim-frontend for dashboard.



Hi!

I've written a frontend for vim. It's not 100% done yet but it works
great for me.

When Kevin Godby tried it out it crashed but I've traced that to be a
problem of the vim-version that comes with redhat 9.

So, to use this make sure you have perl-support in vim (:version look
for +perl).  Then make sure you don't have the buggy vim.  If you try to
run ":perl $mybuf = $curwin->Buffer()" and it dies you have it :)

Other than that, the info is in the file.  Any comments are welcome.

Regards,
Erik
ps. I'm not on the lists so please CC me or add me to the list :)
" Dashboard frontend for vim.
" Author Erik Bågfors <erik bagfors nu>
"
" Just dump this file and Dashboard.pm into ~/.vim/plugin and everything
" should work, if you have perl-support in your vim.
"
" It sends cluepackages when you are in insert mode and hit <space>, 
" <return> or when you hit <esc> to go out of insert mdoe
"
" It sends the following cluepackages to dashboard
" word_at_point with the relevance 10
" sentence_at_point with the relevance 8 (currently same as line_at_point)
" line_at_point with relevance 6
" textblock with relevance 4
" identifier with relevance 10
"
" sentence_at_point are currenly the same as line_at_point. This will be fixed
" textblock is 10 lines before and 10 lines after current line.
" identifier is there to make sure it uses the manpage backend get's the clue
"

if has('perl')

fun! SendDash()
	perl <<EOF
        # For some reason I cannot move the "use blaha" code
	# Above the function, this means that this runs very time which is 
	# unnecessary
	#
	use lib ("$ENV{HOME}/.vim/plugin");
	use Dashboard;
	use Encode;

	sub to_utf8 { $convert?encode("utf8", $_[0]):$_[0]; }

	unless(defined $dash) { # set these global variables
	    $frontend = "vim";
	    $focused = 1; # Vim never does anything unless it's in focus..
	    $dash = new Dashboard($frontend);
	    my ($success, $enc) = VIM::Eval('&encoding');
	    $convert = 1 unless ($enc eq "utf-8");
	} 
	my $context = $curbuf->Name();
	my ($row, $col) = $curwin->Cursor();
	if ($col == 0) {
		$col=9999;
		$row--;
	}

	my $from = $row - 10 > 0?$row - 10:1; 
	my $to = $row + 10;
	my @lines = $curbuf->Get($from .. $to);
	my $spaceposs = 0;
	my $line_at_point = $lines[$row-$from];
	my $inp = rindex $line_at_point, " ", $col-2;
	my $outp = index $line_at_point, " ", $col-2;
	my $word_at_point;
	if ($outp == -1) {
		$word_at_point = &to_utf8(substr $line_at_point, $inp+1);
	} else {
		$word_at_point = &to_utf8(substr $line_at_point, $inp+1, $outp - $inp);
	}
	$line_at_point = &to_utf8($line_at_point);

	my $sentence_at_point = $line_at_point;
	my $textblock = &to_utf8(join "\n", @lines);

	my $clue = [
	   {'type' => 'word_at_point', 'relevance' => 10, 'data' => $word_at_point}, 
	   {'type' => 'sentence_at_point', 'relevance' => 8, 'data' => $sentence_at_point}, 
	   {'type' => 'line_at_point', 'relevance' => 6, 'data' => $line_at_point},
	   {'type' => 'textblock', 'relevance' => 4, 'data' => $textblock},
	   {'type' => 'identifier', 'relevance' => 10, 'data' => $word_at_point}
	];
	$dash->send_cluepacket($context, $focused, $clue);
EOF
	return ""
endfun

:inoremap <Esc> <c-r>= SendDash()<CR><Esc>
:inoremap <space> <space><c-r>=SendDash()<CR>
:inoremap <Return> <Return><c-r>=SendDash()<CR>

endif "has('perl')


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]