1% Miscellaneous function for the abbrev tables 2 3require ("abbrev"); 4 5define define_abbrev_for_table (table, word) 6{ 7 variable n = what_line (); 8 variable use_bskip = 1; 9 variable exg = "exchange"; 10 variable abbrev, expans; 11 12 if (markp ()) 13 { 14 call (exg); 15 if (n == what_line (), call (exg)) use_bskip = 0; 16 } 17 18 push_spot (); 19 if (use_bskip) 20 { 21 push_mark (); 22 bskip_chars (word); 23 } 24 expans = bufsubstr (); 25 pop_spot (); 26 27 !if (strlen (expans)) 28 { 29 expans = read_mini("For what?", Null_String, Null_String); 30 !if (strlen (expans)) return; 31 } 32 33 abbrev = read_mini ("Enter abbrev for '" + expans + "'", "", ""); 34 !if (strlen (abbrev)) return; 35 36 define_abbrev (table, abbrev, expans); 37} 38 39define define_abbreviation () 40{ 41 variable tbl, word; 42 43 (tbl, word) = what_abbrev_table (); 44 !if (strlen (tbl)) 45 { 46 tbl = "Global"; 47 create_abbrev_table (tbl, Null_String); 48 (tbl, word) = what_abbrev_table (); 49 } 50 51 define_abbrev_for_table (tbl, word); 52} 53 54private define quote_this_line () 55{ 56 push_spot (); 57 while (ffind_char ('\\')) 58 { 59 insert_char ('\\'); 60 go_right_1 (); 61 } 62 pop_spot (); 63 push_spot (); 64 while (ffind_char ('"')) 65 { 66 insert_char ('\\'); 67 go_right_1 (); 68 } 69 pop_spot (); 70} 71 72define save_abbrevs () 73{ 74 variable file = read_file_from_mini ("Save abbrevs to:"); 75 variable n, table, word; 76 77 !if (strlen (extract_filename (file))) 78 { 79 file = dircat (file, Abbrev_File); 80 } 81 82 !if (strlen (extract_filename (file))) error ("Invalid file."); 83 84 n = list_abbrev_tables (); % tables on stack 85 !if (n) return; 86 87 () = read_file (file); 88 erase_buffer (); 89 90 loop (n) 91 { 92 table = (); 93 push_spot (); 94 word = dump_abbrev_table (table); % buffer now contain abbrevs 95 pop_spot (); 96 97 vinsert("create_abbrev_table (\"%s\", \"%s\");\n", table, word); 98 go_up_1 (); 99 100 while (down_1 () and not(eobp())) 101 { 102 insert ("define_abbrev (\""); insert(table); 103 insert ("\",\t\""); 104 quote_this_line (); 105 () = ffind_char ('\t'); 106 trim (); 107 insert ("\",\t\""); 108 eol (); 109 insert ("\");"); 110 } 111 } 112 save_buffer (); 113 delbuf (whatbuf); 114} 115 116 117 118 119 120 121