/usr/share/jed/jed-extra/extra/autotext.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 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | % File: autotext.sl -*- mode: SLang; mode: fold -*-
%
% $Id: autotext.sl,v 1.20 2003/09/16 12:46:22 paul Exp paul $
%
% Copyright (c) 2002, 2003 Paul Boekholt.
% Released under the terms of the GNU GPL (version 2 or later).
% This file provides autotext a la MS Word
#iffalse
%add this to .jedrc
require("autotext");
setkey("complete_autotext", "[[C"); % f3
#endif
public variable autotext = Assoc_Type[String_Type];
custom_variable("Autotext_File", dircat(Jed_Home_Directory,
#ifdef UNIX
".autotext"));
#else
"autotext"));
#endif
static variable autotext_has_changed = 0;
%{{{ inserting autotext
% Insert() does not wrap, so here is a hack to insert some text and wrap it
% by formatting the first paragraph (up to the first empty line).
% If you don't want wrapping, define your autotext to begin with an empty line
% or switch to no_mode
public define insert_wrap(string)
{
variable flags;
( , flags) = what_mode();
!if (flags & 1) % wrap-flag
{
insert(string);
return;
}
%{{{ see if we are in an indented paragraph
push_spot();
bol();
skip_white();
what_column();
pop_spot();
%}}}
what_column();
push_mark();
insert("\n\n\n\n");
push_spot();
%{{{ create the wrapped text
()=up(2);
goto_column();
insert("X"); % the first line of a paragraph may be indented
push_spot();
insert("\n");
push_spot();
goto_column(); % indentation for the rest of the paragraph
insert(string);
push_mark();
pop_spot();
call("format_paragraph");
pop_spot();
if (looking_at_char(' ')) call("next_char_cmd"); % extra space
bufsubstr(); % got it!
%}}}
pop_spot();
del_region();
insert();
}
%}}}
%{{{ Adding autotext items
% This is to define a new autotext item.
public define new_autotext_item()
{
variable key, text;
!if(markp())
{
flush("no region is defined");
return;
}
text = bufsubstr();
!if(strlen(text)) return;
key = strtrim_end(substr(extract_element(strtrim_beg(text), 0,'\n'), 1,40));
forever
{
key = read_mini("Keyword? ", "", key);
!if(assoc_key_exists(autotext, key)) break;
if(1 == get_y_or_n("Keyword exists. Overwrite")) break;
}
!if(strlen(key)) return;
autotext[key]=text;
autotext_has_changed = 1;
}
%}}}
%{{{ Building the menus
%menu for removing autotext items
static define autotext_remove_callback(popup)
{
variable k;
foreach (autotext) using ("keys")
{
k = ();
menu_append_item(popup, k, sprintf
("assoc_delete_key(autotext, %s)",make_printable_string(k)));
}
autotext_has_changed = 1;
}
%menu for inserting autotext
static define autotext_menu_callback(popup)
{
variable key, cmd;
menu_append_item(popup, "new", "new_autotext_item");
menu_append_popup(popup, "&Remove");
menu_set_select_popup_callback(popup+".&Remove", &autotext_remove_callback);
menu_append_separator(popup);
foreach (autotext) using ("keys")
{
key = ();
cmd = sprintf("insert_wrap(autotext[%s])", make_printable_string(key));
menu_append_item(popup, "&" + key, cmd);
}
}
%create the menu
static define add_autotext_popup_hook(menubar)
{
variable menu = "Global.&Edit";
menu_append_separator(menu);
menu_append_popup(menu, "&Autotext");
menu_set_select_popup_callback(menu+".&Autotext", &autotext_menu_callback);
}
%}}}
%{{{ completion on autotext
define complete_autotext()
{
bskip_word_chars();
push_mark();
push_mark();
skip_word_chars();
variable word = bufsubstr();
!if(strlen(word))
{
pop_mark_0();
return;
}
variable vals = assoc_get_values(autotext)
[where(array_map(Integer_Type, &is_substr,
assoc_get_keys(autotext), word))];
variable valslen = length(vals);
!if(valslen)
{
message("no autotext found");
pop_mark_0();
return;
}
del_region();
push_mark();
%{{{ cyclic inserting, stolen from dabbrev.sl
variable fun_type, fun, i = 0;
forever
{
if(i == valslen)
{
insert(word);
i=0;
}
else
{
insert_wrap(vals[i]);
i++;
}
update_sans_update_hook(1);
(fun_type, fun) = get_key_binding();
!if(fun == "complete_autotext") break;
del_region();
push_mark();
}
pop_mark_0();
if(fun_type) call(fun); else eval(fun);
%}}}
}
%}}}
%{{{ file stuff.
% the autotext file is evaluated as slang code, and since a slang literal
% string is limited to 256 char, we need to split it up
define slang_string(string)
{
variable outstring = make_printable_string(substr(string, 1, 100));
variable i = 101;
loop(strlen(string) / 100)
{
outstring += "\n+ " + make_printable_string(substr(string, i, 100));
i+=100;
}
return outstring;
}
public define save_autotext_file()
{
variable key, value, fp;
if(0 == autotext_has_changed) return 1;
fp = fopen(Autotext_File, "w");
if(fp == NULL)
{
flush("could not save autotext");
return 1;
}
ERROR_BLOCK
{
flush("I failed to save your autotext");
() = getkey();
_clear_error();
}
foreach (autotext) using ("keys", "values")
{
(key, value) = ();
() = fputs("autotext[" + make_printable_string(key) + "] = \n" +
slang_string(value) + ";\n", fp);
}
return 1;
}
public define read_autotext_file()
{
!if(1 == file_status(Autotext_File)) return;
ERROR_BLOCK
{
flush("error reading the autotext in " + Autotext_File);
_clear_error();
}
() = evalfile(Autotext_File);
}
%}}}
append_to_hook("load_popup_hooks", &add_autotext_popup_hook);
add_to_hook("_jed_exit_hooks", &save_autotext_file);
read_autotext_file();
provide("autotext");
|