/usr/share/jed/jed-extra/extra/complete.sl is in jed-extra 2.5.6-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 | #<perl>
=pod
;
#</perl>
% complete.sl
%
% $Id: complete.sl,v 1.2 2008/12/22 15:49:22 paul Exp paul $
%
% Copyright (c) 2004-2008 Paul Boekholt.
% Released under the terms of the GNU GPL (version 2 or later).
%
% This defines a function called "complete" that runs the blocal hook
% "complete_hook", and a function to find completions in a file. The idea
% is to bind complete() to a key (M-tab say), make a keywords file, and
% set some blocal variables. The keywords file is just a sorted file of
% keywords or function names, one per line. For example in php, write a
% php file like
%
% <?php
% $funs = get_defined_functions();
% sort ($funs["internal"]);
% foreach($funs["internal"] as $word)
% echo $word ."\n";
% ?>
%
% save the output to the file php_words in your Jed_Home_Directory, and add
% this to .jedrc:
%
% define php_mode_hook()
% {
% define_blocal_var("Word_Chars", "a-zA-Z_0-9");
% local_setkey("complete_word", "\e\t");
% define_blocal_var("complete_hook", "complete_from_file");
% }
%
% To do partial completion, press M-tab. To cycle through completions,
% press M-tab again.
%
% For S-Lang, run this script as
% jed-script complete.sl
% to make a completions file.
%
% For Perl, run Perl on this file to get a completions file:
% perl complete.sl
% To add functions from additional modules, add them as extra parameters,
% appending the export tags like in perl's -M option (see perlrun):
% perl complete.sl 'CGI=:standard' 'Debian::DictionariesCommon=:all'
if (__argv[0] == path_basename(__FILE__))
{
()=find_file(dircat(Jed_Home_Directory, "slang_words"));
erase_buffer();
variable words = _apropos("Global", "...", 15);
variable word;
foreach word (words[array_sort(words)])
{
insert(word);
newline();
}
save_buffer();
exit(0);
}
require("txtutils");
private variable context = NULL;
% find the completions of WORD in FILE
% The file should be sorted!
private define before_key_hook();
private define before_key_hook (fun)
{
if (typeof (fun) == Ref_Type) fun = "&";
ifnot (is_substr (fun, "complete_word"))
{
if (context.n) pop_mark_0();
remove_from_hook ("_jed_before_key_hooks", &before_key_hook);
context = NULL;
}
}
private define next_completion()
{
if (context.n) del_region();
if (context.n == context.n_completions)
{
remove_from_hook ("_jed_before_key_hooks", &before_key_hook);
context = NULL;
flush("no more completions");
}
else
{
push_mark();
insert(substr(context.completions[context.n], context.i, -1));
flush (strjoin(context.completions[[context.n:]], " "));
context.n++;
}
}
define complete_from_file() % (word [file])
{
variable word, file;
(word, file) = push_defaults(,, _NARGS);
if (context != NULL) return next_completion();
if (word == NULL || word == "") return message("no word"); % shouldn't happen
if (file == NULL) file = dircat(Jed_Home_Directory, strlow
(sprintf("%s_words", what_mode(), pop)));
if (1 != file_status(file)) return message ("no completions file");
variable n_completions, len = strlen(word);
word = str_quote_string (word, "\\^$[]*.+?", '\\');
n_completions= search_file(file, sprintf("\\c^%s", word), 50);
switch (n_completions)
{case 0: return message ("no completions");}
{case 50: return _pop_n(50);} % we can't do a partial completion
{case 1: variable completion = strtrim();
insert (substr(completion, len+1, -1));
return;};
variable completions = __pop_args(n_completions);
completions = array_map(String_Type, &strtrim, [__push_args(completions)]);
variable first_completion, last_completion, i, n = 0;
first_completion = completions[0];
last_completion = completions[-1];
_for i (len, strlen(first_completion), 1)
{
if (strncmp(first_completion, last_completion, i))
break;
}
then
{
i++;
}
insert (substr(first_completion, len+1, i - len - 1));
message (strjoin(completions, " "));
context = struct { completions, n_completions, n, i };
set_struct_fields(context, completions, n_completions, n, i);
add_to_hook ("_jed_before_key_hooks", &before_key_hook);
}
define complete_word()
{
variable word = get_word();
ifnot (strlen(word)) return message("nothing to complete");
run_blocal_hook("complete_hook", word);
}
provide("complete");
#<perl>
=cut
use strict;
# adapted from perl.sl
sub find_keywords {
local @ARGV = "perldoc -u perlfunc|";
while (<>) { last if /^=head2\s+Alphabetical/ } # cue up
my %kw = map { $_ => 1 }
(
# language elements + carp
qw(
else elsif foreach unless until while
carp cluck croak confess
),
# keywords
map { /^=item\s+([a-z\d]+)/ } <>,
);
return \%kw;
}
sub find_module_symbols {
my ($kw, $module) = @_;
my $fh;
my ($module_sans_tags)=split(/[ =]/, $module);
my @command = ( "perl",
"-M" . $module,
"-e",
'map {print "$_\n" if *$_{CODE} } keys %main::'. $module_sans_tags . '::'
);
my $fh;
open($fh, "-|") or exec @command;
while (<$fh>) {
chomp;
next if length($_) < 4;
next if /^_/ or not /[a-z]/;
$kw->{$_} = 1;
}
}
my $kw = find_keywords;
while (my $module = shift @ARGV) {
find_module_symbols($kw, $module);
}
map {print "$_\n" if length > 3 } sort keys %$kw;
#</perl>
|