diff options
author | Simon Ruderich <simon@ruderich.org> | 2010-10-14 21:33:41 +0000 |
---|---|---|
committer | Simon Ruderich <simon@ruderich.org> | 2010-10-14 21:33:41 +0000 |
commit | f7608ee4a3972c4fe52fe6c94721edac69c9e6c9 (patch) | |
tree | 8ba71a3c33f646bf0192a23087ed32ea37ee87cd /vim-mode | |
parent | vim_mode: Add THANKS section. (diff) | |
download | irssi-scripts-f7608ee4a3972c4fe52fe6c94721edac69c9e6c9.tar.gz irssi-scripts-f7608ee4a3972c4fe52fe6c94721edac69c9e6c9.zip |
vim_mode: Automatically register and sync options.
Diffstat (limited to 'vim-mode')
-rw-r--r-- | vim-mode/vim_mode.pl | 74 |
1 files changed, 64 insertions, 10 deletions
diff --git a/vim-mode/vim_mode.pl b/vim-mode/vim_mode.pl index e754815..4baad78 100644 --- a/vim-mode/vim_mode.pl +++ b/vim-mode/vim_mode.pl @@ -2538,10 +2538,10 @@ sub vim_mode_init { Irssi::statusbar_item_register ('vim_mode', 0, 'vim_mode_cb'); Irssi::statusbar_item_register ('vim_windows', 0, 'b_windows_cb'); - Irssi::settings_add_str('vim_mode', 'vim_mode_cmd_seq', ''); - Irssi::settings_add_bool('vim_mode', 'vim_mode_debug', 0); - Irssi::settings_add_bool('vim_mode', 'vim_mode_utf8', 1); - Irssi::settings_add_int('vim_mode', 'vim_mode_max_undo_lines', 50); + # Register all available settings. + foreach my $name (keys %$settings) { + _setting_register($name); + } # Load the vim_moderc file if it exists. ex_source('source'); @@ -2556,7 +2556,7 @@ sub setup_changed { if ($settings->{cmd_seq}->{value} ne '') { delete $imaps->{$settings->{cmd_seq}->{value}}; } - $value = Irssi::settings_get_str('vim_mode_cmd_seq'); + $value = _setting_get('cmd_seq'); if ($value eq '') { $settings->{cmd_seq}->{value} = $value; } else { @@ -2570,9 +2570,7 @@ sub setup_changed { } } - $settings->{debug}->{value} = Irssi::settings_get_bool('vim_mode_debug'); - - my $new_utf8 = Irssi::settings_get_bool('vim_mode_utf8'); + my $new_utf8 = _setting_get('utf8'); if ($new_utf8 != $settings->{utf8}->{value}) { # recompile the patterns when switching to/from utf-8 $word = qr/[\w_]/o; @@ -2585,8 +2583,13 @@ sub setup_changed { "Please disable the vim_mode_utf8 setting."); } - $settings->{max_undo_lines}->{value} - = Irssi::settings_get_int('vim_mode_max_undo_lines'); + # Sync $settings with current irssi values. + foreach my $name (keys %$settings) { + # These were already handled above. + next if $name eq 'cmd_seq' or $name eq 'cmd_seq'; + + $settings->{$name}->{value} = _setting_get($name); + } } sub UNLOAD { @@ -2863,6 +2866,57 @@ sub _set_prompt { Irssi::signal_emit('change prompt', $msg, 'UP_INNER'); } +sub _setting_get { + my ($name) = @_; + + my $type = $settings->{$name}->{type}; + $name = "vim_mode_$name"; + + if ($type == S_BOOL) { + return Irssi::settings_get_bool($name); + } elsif ($type == S_INT) { + return Irssi::settings_get_int($name); + } elsif ($type == S_STR) { + return Irssi::settings_get_str($name); + } else { + _warn("Unknown setting type '$type', please report."); + } + return undef; +} +sub _setting_set { + my ($name, $value) = @_; + + my $type = $settings->{$name}->{type}; + $name = "vim_mode_$name"; + + if ($type == S_BOOL) { + Irssi::settings_set_bool($name, $value); + } elsif ($type == S_INT) { + Irssi::settings_set_int($name, $value); + } elsif ($type == S_STR) { + Irssi::settings_set_str($name, $value); + } else { + _warn("Unknown setting type '$type', please report."); + } +} +sub _setting_register { + my ($name) = @_; + + my $value = $settings->{$name}->{value}; + my $type = $settings->{$name}->{type}; + $name = "vim_mode_$name"; + + if ($type == S_BOOL) { + Irssi::settings_add_bool('vim_mode', $name, $value); + } elsif ($type == S_INT) { + Irssi::settings_add_int('vim_mode', $name, $value); + } elsif ($type == S_STR) { + Irssi::settings_add_str('vim_mode', $name, $value); + } else { + _warn("Unknown setting type '$type', please report."); + } +} + sub _warn { my ($warning) = @_; |