home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 4
/
FreshFish_May-June1994.bin
/
bbs
/
may94
/
util
/
edit
/
jade.lha
/
Jade
/
src
/
editcommands.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-04-19
|
22KB
|
790 lines
/* editcommands.c -- Lisp functions for editing
Copyright (C) 1993, 1994 John Harper <jsh@ukc.ac.uk>
This file is part of Jade.
Jade is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
Jade is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Jade; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "jade.h"
#include "jade_protos.h"
#include <string.h>
#include <ctype.h>
_PR void edit_init(void);
static VALUE sym_upcase_table, sym_downcase_table;
/* These are actually 256-byte-long Lisp strings, they're initialised in
edit_init(). If struct String changes these will have to as well. */
static u_char UpCaseTable[257], DownCaseTable[257];
_PR VALUE cmd_split_line(void);
DEFUN("split-line", cmd_split_line, subr_split_line, (void), V_Subr0, DOC_split_line) /*
::doc:split_line::
(split-line)
Splits the line into two at the cursor position, if the auto-indent option
is enabled the cursor will be placed at the same level of indentation as
the previous line.
::end:: */
{
VW *vw = CurrVW;
TX *tx = vw->vw_Tx;
if(!readonly(tx))
{
POS old = vw->vw_CursorPos;
if(padcursor(vw))
{
if(splitline(tx, &vw->vw_CursorPos))
{
flaginsertion(tx, &old, &vw->vw_CursorPos);
return(sym_t);
}
}
}
return(sym_nil);
}
_PR VALUE cmd_insert(VALUE string, VALUE pos, VALUE buff);
DEFUN("insert", cmd_insert, subr_insert, (VALUE string, VALUE lpos, VALUE buff), V_Subr3, DOC_insert) /*
::doc:insert::
(insert STRING [POS] [BUFFER])
Inserts STRING into BUFFER at POS.
::end:: */
{
POS pos;
DECLARE1(string, STRINGP);
if(POSP(lpos))
pos = VPOS(lpos);
else
pos = CurrVW->vw_CursorPos;
if(!BUFFERP(buff))
buff = CurrVW->vw_Tx;
if(!readonly(VTX(buff)) && padpos(VTX(buff), &pos))
{
if(insertstring(VTX(buff), VSTR(string), VTX(buff)->tx_TabSize, &pos))
return(sym_t);
else
settitle(NoMemMsg);
}
return(sym_nil);
}
_PR VALUE cmd_insert_rect(VALUE str, VALUE pos, VALUE buff);
DEFUN("insert-rect", cmd_insert_rect, subr_insert_rect, (VALUE str, VALUE lpos, VALUE buff), V_Subr3, DOC_insert_rect) /*
::doc:insert_rect::
(insert-rect STRING [POS] [BUFFER])
Inserts STRING into BUFFER at POS treating it as a ``rectangle'' of
text -- that is, each separate line in STRING (separated by newlines) is
inserted at the *same* column in successive lines.
::end:: */
{
POS pos;
DECLARE1(str, STRINGP);
if(POSP(lpos))
pos = VPOS(lpos);
else
pos = CurrVW->vw_CursorPos;
if(!BUFFERP(buff))
buff = CurrVW->vw_Tx;
if(!readonly(VTX(buff)) && padpos(VTX(buff), &pos))
{
if(rectinsertstring(VTX(buff), VSTR(str), &pos))
return(sym_t);
else
settitle(NoMemMsg);
}
return(sym_nil);
}
_PR VALUE cmd_delete_area(VALUE start, VALUE end, VALUE buff);
DEFUN("delete-area", cmd_delete_area, subr_delete_area, (VALUE lstart, VALUE lend, VALUE buff), V_Subr3, DOC_delete_area) /*
::doc:delete_area::
(delete-area START-POS END-POS [BUFFER])
Deletes from START-POS up to (but not including) END-POS.
::end:: */
{
POS start, end;
DECLARE1(lstart, POSP);
DECLARE2(lend, POSP);
start = VPOS(lstart);
end = VPOS(lend);
if(!BUFFERP(buff))
buff = CurrVW->vw_Tx;
if(!readonly(VTX(buff)) && checksect(VTX(buff), &start, &end))
{
deletesection(VTX(buff), &start, &end);
return(sym_t);
}
return(sym_nil);
}
_PR VALUE cmd_delete_rect(VALUE lstart, VALUE lend, VALUE buff);
DEFUN("delete-rect", cmd_delete_rect, subr_delete_rect, (VALUE lstart, VALUE lend, VALUE buff), V_Subr3, DOC_delete_rect) /*
::doc:delete_rect::
(delete-rect START-POS END-POS [BUFFER])
Deletes the rectangle of text from one corner, START-POS, to the opposite
corner, END-POS.
::end:: */
{
POS start, end;
DECLARE1(lstart, POSP);
DECLARE2(lend, POSP);
if(!BUFFERP(buff))
buff = CurrVW->vw_Tx;
orderrect(&start, &end, &VPOS(lstart), &VPOS(lend));
if(!readonly(VTX(buff)) && checkline(VTX(buff), &end))
{
rectdeletesection(VTX(buff), &start, &end);
return(sym_t);
}
return(sym_nil);
}
_PR VALUE cmd_copy_area(VALUE lstart, VALUE lend, VALUE buff);
DEFUN("copy-area", cmd_copy_area, subr_copy_area, (VALUE lstart, VALUE lend, VALUE buff), V_Subr3, DOC_copy_area) /*
::doc:copy_area::
(copy-area START-POS END-POS [BUFFER])
Returns the string from START-POS up to END-POS.
::end:: */
{
POS start, end;
DECLARE1(lstart, POSP);
DECLARE2(lend, POSP);
start = VPOS(lstart);
end = VPOS(lend);
if(!BUFFERP(buff))
buff = CurrVW->vw_Tx;
if(checksect(VTX(buff), &start, &end))
{
long tlen = sectionlength(VTX(buff), &start, &end) + 1;
VALUE str = valstralloc(tlen);
if(str)
{
copysection(VTX(buff), &start, &end, VSTR(str));
VSTR(str)[tlen - 1] = 0;
return(str);
}
}
return(sym_nil);
}
_PR VALUE cmd_copy_rect(VALUE lstart, VALUE lend, VALUE buff);
DEFUN("copy-rect", cmd_copy_rect, subr_copy_rect, (VALUE lstart, VALUE lend, VALUE buff), V_Subr3, DOC_copy_rect) /*
::doc:copy_rect::
(copy-rect START-POS END-POS [BUFFER])
Returns the rectangle of text marked out by START-POS and END-POS.
::end:: */
{
POS start, end;
DECLARE1(lstart, POSP);
DECLARE2(lend, POSP);
if(!BUFFERP(buff))
buff = CurrVW->vw_Tx;
orderrect(&start, &end, &VPOS(lstart), &VPOS(lend));
if(checkline(VTX(buff), &end))
{
long tlen = rectsectionlength(VTX(buff), &start, &end) + 1;
VALUE str = valstralloc(tlen);
if(str)
{
rectcopysection(VTX(buff), &start, &end, VSTR(str));
VSTR(str)[tlen - 1] = 0;
return(str);
}
}
return(sym_nil);
}
_PR VALUE cmd_cut_area(VALUE lstart, VALUE lend, VALUE buff);
DEFUN("cut-area", cmd_cut_area, subr_cut_area, (VALUE lstart, VALUE lend, VALUE buff), V_Subr3, DOC_cut_area) /*
::doc:cut_area::
(cut-area START-POS END-POS [BUFFER])
The same as `copy-area' except that the section of text copied (START-POS to
END-POS) is deleted from the file after being duplicated.
::end:: */
{
POS start, end;
DECLARE1(lstart, POSP);
DECLARE2(lend, POSP);
start = VPOS(lstart);
end = VPOS(lend);
if(!BUFFERP(buff))
buff = CurrVW->vw_Tx;
if(!readonly(VTX(buff)) && checksect(VTX(buff), &start, &end))
{
long tlen = sectionlength(VTX(buff), &start, &end) + 1;
VALUE str = valstralloc(tlen);
if(str)
{
copysection(VTX(buff), &start, &end, VSTR(str));
VSTR(str)[tlen - 1] = 0;
deletesection(VTX(buff), &start, &end);
return(str);
}
}
return(sym_nil);
}
_PR VALUE cmd_cut_rect(VALUE lstart, VALUE lend, VALUE buff);
DEFUN("cut-rect", cmd_cut_rect, subr_cut_rect, (VALUE lstart, VALUE lend, VALUE buff), V_Subr3, DOC_cut_rect) /*
::doc:cut_rect::
(cut-rect START-POS END-POS [BUFFER])
The same as `copy-rect' except that the section of text copied (START-POS
to END-POS) is deleted from the file after being duplicated.
::end:: */
{
POS start, end;
DECLARE1(lstart, POSP);
DECLARE2(lend, POSP);
if(!BUFFERP(buff))
buff = CurrVW->vw_Tx;
orderrect(&start, &end, &VPOS(lstart), &VPOS(lend));
if(!readonly(VTX(buff)) && checkline(VTX(buff), &end))
{
long tlen = rectsectionlength(VTX(buff), &start, &end) + 1;
VALUE str = valstralloc(tlen);
if(str)
{
rectcopysection(VTX(buff), &start, &end, VSTR(str));
VSTR(str)[tlen - 1] = 0;
rectdeletesection(VTX(buff), &start, &end);
return(str);
}
}
return(sym_nil);
}
_PR VALUE cmd_block_toggle(void);
DEFUN("block-toggle", cmd_block_toggle, subr_block_toggle, (void), V_Subr0, DOC_block_toggle) /*
::doc:block_toggle::
(block-toggle)
::end:: */
{
VW *vw = CurrVW;
switch(vw->vw_BlockStatus)
{
case 0:
vw->vw_BlockStatus = -1;
setblockrefresh(vw);
break;
case 1: