diff options
| author | Teddy Wing | 2018-02-04 00:32:47 +0100 |
|---|---|---|
| committer | Teddy Wing | 2018-02-04 00:32:47 +0100 |
| commit | 3fa851b55688da55687d0219572031f5db20cadd (patch) | |
| tree | c7948dd2a536cc2fc165ebcc51a01d8894a8427b /vimput.pl | |
| parent | df4bb1a20b33fc41471c78af3de70e586caf1df3 (diff) | |
| parent | 601aecbf549fd771541ac0b328d3c5e3a480c452 (diff) | |
| download | irssi-vimput-3fa851b55688da55687d0219572031f5db20cadd.tar.bz2 | |
Merge branch 'move-to-cursor-position-in-vim'
Diffstat (limited to 'vimput.pl')
| -rw-r--r-- | vimput.pl | 12 |
1 files changed, 8 insertions, 4 deletions
@@ -66,7 +66,7 @@ sub write_input { # Open a Tmux split containing a Vim instance editing the vimput_file. sub open_tmux_split { - my ($fifo, $error_handle) = @_; + my ($fifo, $error_handle, $cursor_position) = @_; if (!$ENV{TMUX}) { print $error_handle ERROR_PREFIX . 'Not running in tmux.'; @@ -76,7 +76,7 @@ sub open_tmux_split { my $random_unused_filename = tmpnam(); - my $command = "vim -c 'set buftype=acwrite' -c 'read ${\vimput_file}' -c '1 delete _' -c 'autocmd BufWriteCmd <buffer> :write $fifo | set nomodified' $random_unused_filename"; + my $command = "vim -c 'set buftype=acwrite' -c 'read ${\vimput_file}' -c '1 delete _' -c 'normal! ${cursor_position}l' -c 'autocmd BufWriteCmd <buffer> :write $fifo | set nomodified' $random_unused_filename"; system('tmux', 'split-window', $command); return 1; @@ -89,6 +89,8 @@ sub open_tmux_split { sub open_tmux_and_update_input_line_when_finished { return if $forked; + my ($cursor_position) = @_; + my ($read_handle, $write_handle); pipe($read_handle, $write_handle); @@ -113,7 +115,7 @@ sub open_tmux_and_update_input_line_when_finished { if (is_child_fork($pid)) { my $fifo_path = tmpnam(); - open_tmux_split($fifo_path, $write_handle) or do { + open_tmux_split($fifo_path, $write_handle, $cursor_position) or do { cleanup(); POSIX::_exit(1); }; @@ -251,6 +253,8 @@ Irssi::command_bind('help', sub { # Main entrypoint. sub vimput { + my $cursor_position = Irssi::gui_input_get_pos(); + write_input(Irssi::parse_special('$L', undef, 0)); - open_tmux_and_update_input_line_when_finished(); + open_tmux_and_update_input_line_when_finished($cursor_position); } |
