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 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
|
% -*- SLang -*- bufed.sl
%
% Simple JED `bufed' mode by Mark Olesen <olesen@me.QueensU.CA>
%
% Bufed is a simple buffer manager -- patterned somewhat after dired.
% Provides easy, interactive switching, saving and killing of buffers.
%
% To invoke Bufed, do `M-x bufed'.
% Or re-bind to the key sequence which is normally bound to the
% `list_buffers' function `C-x C-b' (emacs)
%
% ------------------------------------------------------------------------
% TO USE THIS MODE: add the line
%
% autoload ("bufed", "bufed"); to ~/.jedrc
%
% and optionally re-bind to the `C-x C-b' (emacs) key sequence
%
% setkey ("bufed", "^X^B");
% ------------------------------------------------------------------------
variable Bufed_buf = "*BufferList*"; % as used by `list_buffers' (buf.sl)
% save the buffer
define bufed_savebuffer (buf)
{
variable file, dir, flags, ch, this_buf;
ch = int (buf);
if ((ch == 32) or (ch == '*')) return; % internal buffer or special
this_buf = whatbuf ();
setbuf (buf);
(file,dir,,flags) = getbuf_info ();
ERROR_BLOCK { setbuf (this_buf); }
if (strlen (file) and (flags & 1)) % file assciated with it
{
!if (write_buffer (dircat (dir, file)))
error ("Error writing buffer " + buf);
}
EXECUTE_ERROR_BLOCK;
}
% extract the buffer name associated with the current line
% Note: The details of this routine will depend upon how buf.sl formats
% the line. Currently, this looks like:
% ----------- 0000 "*scratch*" /aluche/h1/davis/src/jed/lib/
define bufed_get ()
{
variable buf;
push_spot_bol ();
EXIT_BLOCK { pop_spot (); }
!if (ffind_char ('"'))
return Null_String;
go_right_1 ();
push_mark ();
!if (ffind_char ('"'))
{
pop_mark_1 ();
return Null_String;
}
buf = bufsubstr ();
!if (bufferp (buf)) buf = Null_String;
return buf;
}
define bufed_list ()
{
list_buffers ();
pop2buf (Bufed_buf);
go_down (4);
}
% kill a buffer, if it has been modified then pop to it so it's obvious
define bufed_kill ()
{
variable file, dir, flags, buf = bufed_get ();
variable line;
!if (strlen (buf)) return;
line = what_line ();
setbuf (buf);
(file,dir,,flags) = getbuf_info ();
if (flags & 1) % modified
{
pop2buf (buf);
update (1);
}
delbuf (buf);
if (strcmp (buf, Bufed_buf))
bufed_list ();
goto_line (line);
}
define bufed_save ()
{
variable buf = bufed_get ();
!if (int (buf)) return;
bufed_savebuffer (buf);
}
% try to re-load the file from disk
define bufed_update ()
{
variable file, dir, flags;
(file,dir,,flags) = getbuf_info ();
if (flags & 2) % file on disk modified?
{
!if (find_file (dircat (dir, file)))
error ("Error reading file");
}
}
define bufed_pop2buf ()
{
variable buf = bufed_get ();
!if (int (buf)) return;
% if the buffer is already visible, scroll down
buffer_visible (buf); % leave on the stack
pop2buf (buf);
if (() and not(eobp ()))
call ("page_down");
bufed_update ();
pop2buf (Bufed_buf);
}
define bufed_sw2buf (one)
{
variable buf = bufed_get ();
!if (int (buf)) return;
sw2buf (buf);
bufed_update ();
if (one) onewindow ();
}
define bufed_exit ()
{
delbuf (whatbuf ());
}
variable Bufed_help;
Bufed_help = "k:kill, s:save, g:refresh, SPC,f:pop2buf, CR,TAB:sw2buf, q:quit, h:help, ?:this help";
define bufed_help ()
{
message (Bufed_help);
}
$1 = "bufed";
!if (keymap_p ($1)) make_keymap ($1);
definekey ("bufed_list", "g", $1);
definekey ("describe_mode", "h", $1);
definekey ("bufed_kill", "k", $1);
definekey ("bufed_save", "s", $1);
definekey ("bufed_pop2buf", "f", $1);
definekey ("bufed_pop2buf", " ", $1);
definekey (".0 bufed_sw2buf", "\r", $1);
definekey (".1 bufed_sw2buf", "\t", $1);
definekey ("bufed_exit", "q", $1);
definekey ("bufed_help", "?", $1);
% Also possible,
% U toggle_undo
% O toggle_overwrite
% R toggle_readonly
% C toggle_crmode
%!%Mode designed to aid in navigating through multiple buffers
%!%patterned somewhat after dired.
%!%
%!%To invoke Bufed, do @M-x bufed@ or bind to @C-x C-b@ (emacs)
%!%
%!% @g@ Update the buffer listing.
%!%
%!% @k@ Kill the buffer described on the current line, like typing
%!% @M-x kill_buffer@ and supplying that buffer name.
%!%
%!% @s@ Save the buffer described on the current line.
%!%
%!% @f@, @SPC@, @CR@, @TAB@
%!% Visit the buffer described on the current line.
%!% @f@ and @SPC@ will create a new window if required.
%!% @CR@ will use the current window.
%!% @TAB@ will revert to a single window.
%!%
%!% @Q@ Quit bufed mode.
define bufed ()
{
variable mode = "bufed";
variable this_buf;
this_buf = sprintf ("\"%s\"", whatbuf ());
bufed_list ();
() = fsearch (this_buf); bol ();
bufed_help ();
use_keymap (mode);
set_mode (mode, 0);
runhooks ("bufed_hook");
}
|