jed-users mailing list

[2002 Date Index] [2002 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

site.sl extensions


Hi jedies,

For a jolly long time, I have some extensions to site.sl in my defaults.sl
that I would like to see in the next release:

A new function save_buffer_as()

A version of save_buffer that calls this when no filename is bound to the
buffer.

A fix of what I consider a bug in rename_buffer().

All of them work for me.

Guenter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


% New function save_buffer_as: Similar to the internal write_buffer
% (Attention: there is another (intrinsic) write_buffer function!!!)
% but with ask for overwrite.

%{{{ save_buffer_as(force_overwrite = 0)
%!%+
%\function{save_buffer_as}
%\synopsis{Save the buffer to a different file/directory}
%\usage{Void save_buffer_as([force_overwrite = 0])}
%\description
%   Asks for a new filename and saves the buffer under this name.
%   Asks before overwriting an existing file, if not envoced with
%   force_overwrite = 1. Sets readonly flag to 0, becouse if we are 
%   able to write, we can also modify.
%\seealso{save_buffer, write_buffer}
%!%-
define save_buffer_as()
{
   variable force_overwrite = 0;
   if (_NARGS)
     force_overwrite = ();
   
   variable file = read_file_from_mini(sprintf("Save %s to:", whatbuf()));
   if (file_status(file) == 2) % directory
     file += whatbuf();
   if (file_status(file) == 1 and not(force_overwrite)) % file exists
     if(get_y_or_n(sprintf("File \"%s\" exists, overwrite?", file)) != 1)
       return;
   () = write_buffer(file);
   set_readonly(0);       % if we are able to write, we can also modify
} add_completion("save_buffer_as");
%}}}


%{{{ save_buffer()
%!%+
%\function{save_buffer}
%\synopsis{save_buffer}
%\usage{Void save_buffer();}
%\description
% Save current buffer.
%!%-
define save_buffer()
{
   variable file;
   
   !if (buffer_modified())
     {
        message("Buffer not modified.");
        return;
     }
   
   file = buffer_filename();
   !if (strlen(file))
       save_buffer_as();

   () = write_buffer(file);

} add_completion("save_buffer");
%}}}


% this is an enhancement/fix of the function in site.sl that produces two 
% buffers with indentical names if a buffer with this name already
%   exists.)

%!%+
%\function{rename_buffer}
%\synopsis{rename the buffer, overwriting an existing buffer}
%\usage{ Void rename_buffer (String name, [Integer force_overwrite])}
%\description
%   renames the active buffer to name, if a buffer of this name already
%   exists, ask before overwriting (i.e.  deleting the existing buffer).
%   (The optional argument force_overwrite skips the question)
%\seealso{rename_buffer}
%!%-
define rename_buffer() % (name, [overwrite])
{
   variable name, force_overwrite = 0;
   if (_NARGS == 2)
     force_overwrite = ();
   name = ();

   if (bufferp(name))
     {
        !if (force_overwrite)
          if(get_y_or_n("File exists, overwrite?") != 1)
            return;
        delbuf(name);
     }
   variable flags = getbuf_info(); 
   pop(); 
   setbuf_info(name, flags);
}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

--
G.Milde@xxxxxxxxxxxxxxxxxxxx


--------------------------
To unsubscribe send email to <jed-users-request@xxxxxxxxxxx> with
the word "unsubscribe" in the message body.
Need help? Email <jed-users-owner@xxxxxxxxxxx>.


[2002 date index] [2002 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]