/* This set of functions was written by Frederick N. Brier on
February 20, 1990 and afterward. The initial ones are meant
to take some of the better feature/functions from BRIEF (tm).
Other function to be written will take advantage of eel's
powerful features and continually added to this file.
Copyright @1990 Frederick N. Brier
All rights reserved.
The author allows that the software may be freely distributed as
long as without charge or changing the author's name. Only Laguru
Software Ltd may incorporate these routines into one of their products
(preferably with some sort of honorable mention). These routines are
provided without warranty or liability.
Release 1.0 February 20-23, 1990:
home_key, end_key, kill_whole_line, create_filebuf_list,
next_file_buffer, and previous_file_buffer
*/
#include "eel.h" /* standard definitions */
#define TRUE (0 == 0)
#define FALSE (0 != 0)
#define min(x,y) (x>y?y:x)
#define max(x,y) (x>y?x:y)
command end_key()
/* This command will move the cursor to the end of the line. If
already at the end of the line it will move the cursor to the end
of the window. If at the end of a window, it will move it to the
end of the buffer. This function emulates the behavior of the
BRIEF (tm) editor's End key. */
{
if ('\n' == curchar())
{
/* At end of line - move to end of window */
refresh();
if (point == window_end)
{
/* Cursor at end of window - move to end of buffer */
if (size() != point)
{
/* Not at end of buffer */
point = size();
refresh();
}
}
else
/* Move point to end of window */
point = window_end;
}
else
/* Move point to end of line */
to_end_line();
} /* of command end_key */
command home_key()
/* This command will move the cursor to the beginning of the line.
If already at the beginning of the line, it will move it to the
beginning of the window. If already at the beginning of the window,
it will move it to the beginning of the buffer. This function emulates
the Home key of the BRIEF (tm) editor. */
{
if (0 == current_column())
{
refresh();
/* Already at beginning of line */
if (window_start == point)
{
/* Already at beginning of window - move to beginning of buffer */
if (0 != point)
point = 0;
} /* of if */
else
point = window_start;
} /* of if */
else
to_begin_line();
} /* of function home_key */
command kill_whole_line()
/* This function deletes a whole line and stuffs it in the kill
buffer. */
{
int start;
to_begin_line();
start = point;
to_end_line();
point++;
iter = 0;
do_save_kill(start, point);
} /* of command kill_whole_line */
int create_filebuf_list(CurrentBuffer)
char *CurrentBuffer;
/* This function is used by next_file_buffer and previous_file_buffer.
It builds a buffer with a list of buffers that have files. It then
places "point" at the beginning of the line that contains the current
buffer. */
{
char *BufList;
char *s, msg[80];
BufList = "_buffer_list";
create(BufList);
zap(BufList);
s = buffer_list(1);
do
{
bufname = s;
if (*filename != '\0')
{
sprintf(msg, "%-32s \n", bufname);
bufname = BufList;
stuff(msg);
}
}
while (s = buffer_list(0));
bufname = BufList;
if (0 == size())
/* No valid buffers to switch to */
{
say("No valid buffer to switch to from %s.", CurrentBuffer);
bufname = CurrentBuffer;
return(1);
}
point = 0;
col_search(CurrentBuffer, 0);
return(0);
} /* of function create_filebuf_list */
command next_file_buffer()
/* This command switches to the next buffer that has a file attached to
it. */
{
char CurrentBuffer[80], NewBuffer[80];
init_debugbuf();
sprintf(CurrentBuffer, "%s ",bufname);
if (create_filebuf_list(CurrentBuffer))
return;
/* Move forward one line to next valid buffer in file buffer list */
nl_forward();
if (size() == point)
/* Cycle forward to file buffer list beginning */
point = 0;
if (!parse_string(1, "[^ \n]*", NewBuffer))
{
bufname = CurrentBuffer;
say("Error: failed parse_string %s", NewBuffer);
}
else
to_buffer(NewBuffer);
} /* of command next_file_buffer */
command previous_file_buffer()
/* This command switches to the previous buffer that has a file
attached to it. */
{
char CurrentBuffer[80], NewBuffer[80];
init_debugbuf();
sprintf(CurrentBuffer, "%s ",bufname);
if (create_filebuf_list(CurrentBuffer))
return;
/* Move backward one line */
if (0 == point)
/* Cycle to end of file buffer list */
point = size();
nl_reverse();
to_begin_line();
if (!parse_string(1, "[^ \n]*", NewBuffer))
{
say("Error: failed parse_string %s", NewBuffer);
to_buffer(CurrentBuffer);
}
else
to_buffer(NewBuffer);
} /* of command previous_file_buffer */