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 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
%% Buffer routines for Jed. Functions included here are:
%%
%% list_buffers : pop up a list of buffers
%% save_buffers : saves buffers that are associated with a file
%% with no user intervention
%% recover_file : restore buffer from autosave file.
%%
%%
define list_buffers ()
{
variable i, j, tmp, this, name, flags, flag_chars, skip;
variable umask;
variable name_col, dir_col, mode_col;
name_col = 21;
mode_col = 13;
dir_col = 45;
skip = 0;
if (prefix_argument(-1) == -1) skip = 1;
tmp = "*BufferList*";
this = whatbuf();
pop2buf(tmp);
set_readonly(0);
erase_buffer();
TAB = 8;
insert("U:Undo O:Overwrite R:Readonly D:Disk File Changed, A:Autosave, M:Modified\n");
insert("C:CRmode, B:Binary File, K:Not backed up, N:No autosave\n\n");
flag_chars = "CBKN-UORDAM";
goto_column (mode_col);
insert ("umask");
goto_column (name_col);
insert ("Buffer Name");
goto_column(dir_col); insert("Dir/File\n");
loop (buffer_list())
{
name = ();
if (skip and (int(name) == ' ')) continue; %% internal buffers begin with a space
setbuf(name);
flags = getbuf_info(); % more on stack
umask = set_buffer_umask (-1);
setbuf(tmp);
bol();
i = 0x400; j = 0;
while (i)
{
if (flags & i) flag_chars[j]; else '-';
insert_char (());
i = i shr 1; j++;
}
goto_column (mode_col);
vinsert ("0%03o", umask, 1);
goto_column (name_col);
% Since the buffername may contain whitespace, enclose it in quotes
insert_char ('"');
insert(()); %% buffer name
insert_char ('"');
goto_column(dir_col);
!if (eolp())
{
eol(); insert_single_space();
}
insert(()); insert(()); %% dir/file
newline();
}
bob();
set_buffer_modified_flag(0);
set_readonly (1);
pop2buf(this);
}
%!% Prototype: Void save_buffers ();
%!% Save all modified buffers that are associated with a file without
%!% user intervention.
define save_buffers ()
{
variable file, dir, flags, buf, ch;
loop (buffer_list())
{
buf = ();
ch = int(buf);
if ((ch == 32) or (ch == '*')) continue; %% internal buffer or special
setbuf(buf);
(file, dir,, flags) = getbuf_info();
!if (strlen(file)) continue; %% no file assciated with it
if (flags & 1)
{
!if (write_buffer(dircat (dir, file)))
error ("Error writing buffer " + buf);
}
}
}
%% write region to file
define write_region()
{
variable file;
!if (markp) error("Set Mark first!");
file = read_file_from_mini("File:");
write_region_to_file(file);
}
define append_region ()
{
variable file;
!if (markp) error("Set Mark first!");
file = read_file_from_mini("Append to File:");
if (-1 == append_region_to_file(file)) error ("Append failed.");
}
;%% restores buffer from autosave file.
define recover_file ()
{
variable flags, file, dir, as, buf;
(file, dir,, flags) = getbuf_info();
!if (strlen(file)) error("Buffer not associated with a file.");
as = make_autosave_filename (dir, file);
if (file_status(as) != 1)
{
error (as + " not readable.");
}
buf = whatbuf();
as;
if (file_time_compare(as, dircat (dir, file)))
{
" more recent. Use it";
}
else " not recent. Use it";
if (get_yes_no(() + ()) > 0)
{
what_line();
setbuf(buf);
erase_buffer();
() = insert_file(as);
goto_line();
}
}
|