App-ShellCompleter-emacs
view release on metacpan or search on metacpan
#!perl
our $DATE = '2016-10-21'; # DATE
our $VERSION = '0.04'; # VERSION
# FRAGMENT id=shcompgen-hint completer=1 for=emacs
use 5.010001;
use strict;
use warnings;
#use Log::Any::IfLOG '$log';
use Complete::File qw(complete_file);
use Complete::Unix qw(complete_user);
use Complete::Util qw(complete_array_elem combine_answers);
use Getopt::Long::Complete qw(GetOptionsWithCompletion);
die "This script is for shell completion only\n"
unless $ENV{GETOPT_LONG_DUMP} || $ENV{COMP_LINE} || $ENV{COMMAND_LINE};
my $noop = sub {};
$Getopt::Long::Complete::opt_bundling = 0;
# this is gathered from emacs manpage and should be updated from time to time.
GetOptionsWithCompletion(
sub {
my %args = @_;
my $type = $args{type};
my $word = $args{word};
if ($type eq 'arg') {
#$log->tracef("Completing arg");
return complete_file(word => $word);
# XXX +number
# XXX +line:column
} elsif ($type eq 'optval') {
my $ospec = $args{ospec};
my $opt = $args{opt};
#$log->tracef("Completing optval (opt=$opt)");
if ($opt eq '--file' || $opt eq '--find-file' || $opt eq '--visit') {
return complete_file(word => $word);
} elsif ($opt eq '--user' || $opt eq '-u') {
return complete_user(word => $word);
} elsif ($opt eq '--terminal' || $opt eq '-t') {
return complete_file(word => $word);
} elsif ($opt eq '--load' || $opt eq '-l') {
return complete_file(word => $word);
} elsif ($opt eq '--script') {
return complete_file(word => $word);
} elsif ($opt eq '--insert') {
return complete_file(word => $word);
} elsif ($opt eq '--directory' || $opt eq '-L') {
return complete_user(word => $word, filter=>'d');
} elsif ($opt eq '--color') {
return complete_array_elem(word => $word, array=>[qw/auto never always ansi8/]);
}
# XXX funcall/f -> list of Lisp functions
# XXX name -> list of window names
# XXX font/fn -> list of font names
# XXX fg/bg/bd/... -> list of colors
# XXX display/d -> list of X display names (:0.0 only as default?)
}
return [];
},
'file|find-file|visit=s' => $noop,
'no-init-file|q' => $noop,
'no-site-file' => $noop,
'no-desktop' => $noop,
'quick|Q' => $noop,
'no-splash' => $noop,
'debug-init' => $noop,
'user|u=s' => $noop,
'terminal|t=s' => $noop,
'daemon' => $noop,
'version' => $noop,
'help' => $noop,
'funcall|f=s' => $noop,
'load|l=s' => $noop,
'eval|execute=s' => $noop,
'batch' => $noop,
'script=s' => $noop,
'insert=s' => $noop,
'kill' => $noop,
( run in 1.336 second using v1.01-cache-2.11-cpan-39bf76dae61 )