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

  1. % misc functions that should be in site.sl but they are not because we want
  2. % jed to start up fast and they are not always needed.
  3.  
  4.  
  5. %!% Prototype: String make_tmp_buffer_name (String base);
  6. %!% Generates a unique buffer name using the string 'base' for the beginning
  7. %!% of the name.  The buffer name is returned.  The buffer is not created.
  8. define make_tmp_buffer_name (tmp)
  9. {
  10.    variable n = 0, buf;
  11.    variable t = time ();
  12.    
  13.    tmp = strcat (tmp, time);
  14.    do 
  15.      {
  16.     buf = Sprintf("%s%d", tmp, n);
  17.     n++;
  18.      }
  19.    while (bufferp(buf));
  20.    buf;
  21. }
  22.  
  23. define misc_do_write_to_file (str, file, write_function)
  24. {
  25.    variable ret = -1;   
  26.    variable buf = make_tmp_buffer_name (Null_String);
  27.    variable cbuf = whatbuf ();
  28.    
  29.    setbuf (buf);
  30.    insert (str);
  31.    set_buffer_modified_flag (0);
  32.    push_mark ();
  33.    bob ();
  34.    
  35.    ERROR_BLOCK 
  36.      {
  37.     _clear_error ();
  38.      }
  39.    ret = write_function (file);
  40.    
  41.    setbuf (cbuf);
  42.    delbuf (buf);
  43.    ret;
  44. }
  45.  
  46. %!% Prototype: Integer append_string_to_file (String str, String file);
  47. %!% The string 'str' is appended to file 'file'.  This function returns -1
  48. %!% upon failure or the number of lines written upon success.
  49. %!% See append_region_to_file for more information.
  50. define append_string_to_file (str, file)
  51. {
  52.    misc_do_write_to_file (str, file, &append_region_to_file);
  53. }
  54.  
  55. %!% Prototype: Integer write_string_to_file (String str, String file);
  56. %!% The string 'str' is written to file 'file'.  This function returns -1
  57. %!% upon failure or the number of lines written upon success.
  58. %!% This function does not modify a buffer visiting the file.
  59. define write_string_to_file (str, file)
  60. {
  61.    misc_do_write_to_file (str, file, &write_region_to_file);
  62. }
  63.