]> git.99rst.org Git - irssi-scripts.irssi.org.git/commitdiff
Make anchored string matching configurable
authormartin f. krafft <redacted>
Thu, 2 Feb 2017 01:40:44 +0000 (02:40 +0100)
committermartin f. krafft <redacted>
Wed, 8 Feb 2017 20:35:15 +0000 (21:35 +0100)
Introduces two new settings `go_match_anchored` and
`go_complete_anchored` that control whether the search string (the
argument to `/go`) matches only at the start of window/item names (the
default), or anywhere in the names.

Signed-off-by: martin f. krafft <redacted>
scripts/go.pl

index f9320b8daf2f2e418313f5478d1ddc6259663347..0b0a2a24ef56c9c2eee9307415c129fcdcb962d6 100644 (file)
@@ -14,10 +14,20 @@ use Irssi::Irc;
 #     Match window/item names sensitively (the default). Turning this off
 #     means e.g. "/go foo" would jump to a window named "Foobar", too.
 #
+#   /SET go_match_anchored [ON|OFF]
+#     Match window/names only at the start of the word (the default). Turning
+#     this off will mean that strings can match anywhere in the window/names.
+#     The leading '#' of channel names is optional either way.
+#
 #   /SET go_complete_case_sensitive [ON|OFF]
 #     When using tab-completion, match case-insensitively (the default).
 #     Turning this on means that "/go foo<tab>" will *not* suggest "Foobar".
 #
+#   /SET go_complete_anchored [ON|OFF]
+#     Match window/names only at the start of the word. The default is 'off',
+#     which causes completion to match anywhere in the window/names during
+#     completion. The leading '#' of channel names is optional either way.
+#
 
 $VERSION = '1.1';
 
@@ -31,9 +41,10 @@ $VERSION = '1.1';
 );
 
 sub _make_regexp {
-       my ($name, $ci) = @_;
-       my $re = "^#?\Q${name}\E";
+       my ($name, $ci, $aw) = @_;
+       my $re = "\Q${name}\E";
        $re = "(?i:$re)" unless $ci;
+       $re = "^#?$re" if $aw;
        return $re;
 }
 
@@ -44,7 +55,9 @@ sub signal_complete_go {
 
         return unless ($linestart =~ /^\Q${k}\Ego\b/i);
 
-       my $re = _make_regexp($word, Irssi::settings_get_bool('go_complete_case_sensitive'));
+       my $re = _make_regexp($word,
+               Irssi::settings_get_bool('go_complete_case_sensitive'),
+               Irssi::settings_get_bool('go_complete_anchored'));
        @$complist = ();
        foreach my $w (Irssi::windows) {
                my $name = $w->get_active_name();
@@ -64,7 +77,9 @@ sub cmd_go
        my($chan,$server,$witem) = @_;
 
        $chan =~ s/ *//g;
-       my $re = _make_regexp($chan, Irssi::settings_get_bool('go_match_case_sensitive'));
+       my $re = _make_regexp($chan,
+               Irssi::settings_get_bool('go_match_case_sensitive'),
+               Irssi::settings_get_bool('go_match_anchored'));
 
        foreach my $w (Irssi::windows) {
                my $name = $w->get_active_name();
@@ -79,9 +94,12 @@ Irssi::command_bind("go", "cmd_go");
 Irssi::signal_add_first('complete word', 'signal_complete_go');
 Irssi::settings_add_bool('go', 'go_match_case_sensitive', 1);
 Irssi::settings_add_bool('go', 'go_complete_case_sensitive', 0);
+Irssi::settings_add_bool('go', 'go_match_anchored', 1);
+Irssi::settings_add_bool('go', 'go_complete_anchored', 0);
 
 # Changelog
 #
 # 2017-02-02  1.1  martin f. krafft <madduck@madduck.net>
 #   - made case-sensitivity of match configurable
+#   - made anchoring of search strings configurable
 #
git clone https://git.99rst.org/PROJECT