home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / AP / JED / JED097-1.TAR / jed / lib / abbrmisc.sl < prev    next >
Encoding:
Text File  |  1994-12-12  |  2.0 KB  |  109 lines

  1. % Miscellaneous function for the abbrev tables
  2.  
  3. evalfile ("abbrev.sl");
  4.    
  5. define define_abbrev_for_table (table, word)
  6. {
  7.    variable n = whatline ();
  8.    variable use_bskip = 1;
  9.    variable exg = "exchange";
  10.    variable abbrev, expans;
  11.    
  12.    if (markp ())
  13.      {
  14.     call (exg);
  15.     if (n == whatline (), 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 (strncat ("Enter abbrev for '", expans, "'", 3), Null_String, Null_String);
  34.    !if (strlen (abbrev)) return;
  35.    
  36.    define_abbrev (table,  abbrev, expans);
  37. }
  38.  
  39. define 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.  
  54. define save_abbrevs ()
  55. {
  56.    variable file = read_file_from_mini ("Save abbrevs to:");
  57.    variable n, table, word;
  58.    
  59.    !if (strlen (extract_filename (file)))
  60.      {
  61.     file = dircat (file, Abbrev_File);
  62.      }
  63.    
  64.    !if (strlen (extract_filename (file))) error ("Invalid file.");
  65.    
  66.    n = list_abbrev_tables ();           %  tables on stack
  67.    !if (n) return;
  68.    
  69.    read_file (file); pop ();
  70.    erase_buffer ();
  71.    
  72.    loop (n)
  73.      {
  74.     table = ();
  75.     push_spot ();
  76.     word = dump_abbrev_table (table);
  77.     pop_spot ();
  78.     
  79.     insert(Sprintf ("create_abbrev_table (\"%s\", \"%s\");\n", table, word, 2));
  80.     go_up(1);
  81.     
  82.     while (down (1) and not(eobp()))
  83.       {
  84.          insert ("define_abbrev (\""); insert(table);
  85.          insert ("\",\t\"");
  86.          push_spot ();
  87.          while (ffind("\\"))
  88.            {
  89.           insert ("\\");
  90.           go_right (1);
  91.            }
  92.          pop_spot ();
  93.          ffind ("\t"); pop ();
  94.          trim ();
  95.          insert ("\",\t");
  96.          eol ();
  97.          insert ("\");");
  98.       }
  99.      }
  100.    save_buffer ();
  101.    delbuf (whatbuf);
  102. }
  103.  
  104.          
  105.     
  106.     
  107.    
  108.     
  109.