aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2018-01-22 23:10:12 +0100
committerTeddy Wing2018-01-22 23:10:12 +0100
commit601aecbf549fd771541ac0b328d3c5e3a480c452 (patch)
treec7948dd2a536cc2fc165ebcc51a01d8894a8427b
parentdf4bb1a20b33fc41471c78af3de70e586caf1df3 (diff)
downloadirssi-vimput-601aecbf549fd771541ac0b328d3c5e3a480c452.tar.bz2
open_tmux_split: Mirror cursor position in Vim
Get the current cursor position in Irssi and make the Vim cursor position the same. Makes editing more cognitively coherent. This way, if you've already been editing the Irssi line and the cursor is in the middle of the line, you can pick up right where you left off in Vim.
-rw-r--r--vimput.pl12
1 files changed, 8 insertions, 4 deletions
diff --git a/vimput.pl b/vimput.pl
index 2597933..a316528 100644
--- a/vimput.pl
+++ b/vimput.pl
@@ -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);
}