[Tags] Use 'readtags' if query string is given

This pre-filtering is critical when working with large tag files.

'readtags' can perform a binary search for the given prefix string
but fzf has to load the entire file into memory just to start searching.

Close #1529
Close #1524
This commit is contained in:
Junegunn Choi
2024-03-11 11:54:08 +09:00
parent 8ea9574b3e
commit 0b3e015ad8
2 changed files with 11 additions and 2 deletions

View File

@@ -2,8 +2,16 @@
use strict;
my $prefix = shift @ARGV;
foreach my $file (@ARGV) {
open my $lines, $file;
my $lines;
if ($prefix eq "") {
open $lines, $file;
} else {
# https://perldoc.perl.org/perlopentut#Expressing-the-command-as-a-list
open $lines, '-|', 'readtags', '-t', $file, '-e', '-p', $prefix;
}
while (<$lines>) {
unless (/^\!/) {
s/^[^\t]*/sprintf("%-24s", $&)/e;