File: abbrmisc.sl

package info (click to toggle)
jed 0.98.7-14
  • links: PTS
  • area: main
  • in suites: slink
  • size: 3,088 kB
  • ctags: 3,851
  • sloc: ansic: 29,315; makefile: 257; sh: 248
file content (108 lines) | stat: -rw-r--r-- 2,061 bytes parent folder | download | duplicates (2)
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
% Miscellaneous function for the abbrev tables

evalfile ("abbrev.sl");
   
define define_abbrev_for_table (table, word)
{
   variable n = what_line ();
   variable use_bskip = 1;
   variable exg = "exchange";
   variable abbrev, expans;
   
   if (markp ())
     {
	call (exg);
	if (n == what_line (), call (exg)) use_bskip = 0;
     }
   
   push_spot ();
   if (use_bskip)
     {
	push_mark ();
	bskip_chars (word);
     }
   expans = bufsubstr ();
   pop_spot ();

   !if (strlen (expans)) 
     {
	expans = read_mini("For what?", Null_String, Null_String);
	!if (strlen (expans)) return;
     }
   
   abbrev = read_mini ("Enter abbrev for '" + expans + "'", "", "");
   !if (strlen (abbrev)) return;
   
   define_abbrev (table,  abbrev, expans);
}

define define_abbreviation ()
{
   variable tbl, word;
   
   (tbl, word) = what_abbrev_table ();
   !if (strlen (tbl)) 
     {
	tbl = "Global";
	create_abbrev_table (tbl, Null_String);
	(tbl, word) = what_abbrev_table ();
     }

   define_abbrev_for_table (tbl, word);
}

define save_abbrevs ()
{
   variable file = read_file_from_mini ("Save abbrevs to:");
   variable n, table, word;
   
   !if (strlen (extract_filename (file)))
     {
	file = dircat (file, Abbrev_File);
     }
   
   !if (strlen (extract_filename (file))) error ("Invalid file.");
   
   n = list_abbrev_tables ();	       %  tables on stack
   !if (n) return;
   
   read_file (file); pop ();
   erase_buffer ();
   
   loop (n)
     {
	table = ();
	push_spot ();
	word = dump_abbrev_table (table);
	pop_spot ();
	
	vinsert("create_abbrev_table (\"%s\", \"%s\");\n", table, word, 2);
	go_up_1 ();
	
	while (down_1 () and not(eobp()))
	  {
	     insert ("define_abbrev (\""); insert(table);
	     insert ("\",\t\"");
	     push_spot ();
	     while (ffind_char ('\\'))
	       {
		  insert_char ('\\');
		  go_right_1 ();
	       }
	     pop_spot ();
	     () = ffind_char ('\t'); 
	     trim ();
	     insert ("\",\t\"");
	     eol ();
	     insert ("\");");
	  }
     }
   save_buffer ();
   delbuf (whatbuf);
}