home *** CD-ROM | disk | FTP | other *** search
- /* 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:
- vw->vw_BlockE = vw->vw_CursorPos;
- vw->vw_BlockStatus = 0;
- orderblock(vw);
- setblockrefresh(vw);
- break;
- case 2:
- vw->vw_BlockS = vw->vw_CursorPos;
- vw->vw_BlockStatus = 0;
- orderblock(vw);
- setblockrefresh(vw);
- break;
- case -1:
- vw->vw_BlockS = vw->vw_CursorPos;
- vw->vw_BlockStatus = 1;
- break;
- }
- return(sym_t);
- }
-
- _PR VALUE cmd_block_start(VALUE pos);
- DEFUN("block-start", cmd_block_start, subr_block_start, (VALUE pos), V_Subr1, DOC_block_start) /*
- ::doc:block_start::
- (block-start [POS])
- Always returns the position of the block-start as it is, if POS is given
- it is used as the new position of the start of the block.
- ::end:: */
- {
- VW *vw = CurrVW;
- VALUE res;
- if(!vw->vw_BlockStatus || (vw->vw_BlockStatus == 1))
- res = newlpos(&vw->vw_BlockS);
- else
- res = sym_nil;
- if(POSP(pos) && checkline(vw->vw_Tx, &VPOS(pos)))
- {
- switch(vw->vw_BlockStatus)
- {
- case 0:
- setblockrefresh(vw);
- vw->vw_BlockS = VPOS(pos);
- orderblock(vw);
- setblockrefresh(vw);
- break;
- case 2:
- vw->vw_BlockS = VPOS(pos);
- vw->vw_BlockStatus = 0;
- orderblock(vw);
- setblockrefresh(vw);
- break;
- case -1:
- vw->vw_BlockStatus = 1;
- /* FALL THROUGH */
- case 1:
- vw->vw_BlockS = VPOS(pos);
- break;
- }
- }
- return(res);
- }
-
- _PR VALUE cmd_block_end(VALUE pos);
- DEFUN("block-end", cmd_block_end, subr_block_end, (VALUE pos), V_Subr1, DOC_block_end) /*
- ::doc:block_end::
- (block-end [POS])
- Always returns the position of the block-end as it is, if POS is given
- it is used as the new position of the end of the block.
- ::end:: */
- {
- VW *vw = CurrVW;
- VALUE res;
- if(!vw->vw_BlockStatus || (vw->vw_BlockStatus == 2))
- res = newlpos(&vw->vw_BlockE);
- else
- res = sym_nil;
- if(POSP(pos) && checkline(vw->vw_Tx, &VPOS(pos)))
- {
- switch(vw->vw_BlockStatus)
- {
- case 0:
- setblockrefresh(vw);
- vw->vw_BlockE = VPOS(pos);
- orderblock(vw);
- setblockrefresh(vw);
- break;
- case 1:
- vw->vw_BlockE = VPOS(pos);
- vw->vw_BlockStatus = 0;
- orderblock(vw);
- setblockrefresh(vw);
- break;
- case -1:
- vw->vw_BlockStatus = 2;
- /* FALL THROUGH */
- case 2:
- vw->vw_BlockE = VPOS(pos);
- break;
- }
- }
- return(res);
- }
-
- _PR VALUE cmd_block_kill(void);
- DEFUN("block-kill", cmd_block_kill, subr_block_kill, (void), V_Subr0, DOC_block_kill) /*
- ::doc:block_kill::
- (block-kill)
- Unmarks the block.
- ::end:: */
- {
- VW *vw = CurrVW;
- if(vw->vw_BlockStatus == 0)
- {
- setblockrefresh(vw);
- vw->vw_BlockStatus = -1;
- }
- return(sym_t);
- }
-
- _PR VALUE cmd_blockp(void);
- DEFUN("blockp", cmd_blockp, subr_blockp, (void), V_Subr0, DOC_blockp) /*
- ::doc:blockp::
- (blockp)
- Returns true if a block is currently marked.
- ::end:: */
- {
- if(CurrVW->vw_BlockStatus == 0)
- return(sym_t);
- return(sym_nil);
- }
-
- _PR VALUE cmd_translate_area(VALUE vstart, VALUE vend, VALUE table, VALUE tx);
- DEFUN("translate-area", cmd_translate_area, subr_translate_area, (VALUE vstart, VALUE vend, VALUE table, VALUE tx), V_Subr4, DOC_translate_area) /*
- ::doc:translate_area:
- (translate-area START-POS END-POS TRANSLATION-TABLE [BUFFER])
- Applies the TRANSLATION-TABLE to the text between START-POS and END-POS.
- TRANSLATION-TABLE is a string, each character represents the translation
- for an ascii character of that characters position in the string. If the
- string is less than 256 chars long any undefined characters will remain
- unchanged.
- ::end:: */
- {
- POS start, end;
- if(!BUFFERP(tx))
- tx = CurrVW->vw_Tx;
- DECLARE1(vstart, POSP);
- DECLARE2(vend, POSP);
- DECLARE3(table, STRINGP);
- start = VPOS(vstart);
- end = VPOS(vend);
- if(!readonly(VTX(tx)) && checksect(VTX(tx), &start, &end))
- {
- LINE *line = VTX(tx)->tx_Lines + start.pos_Line;
- int tablen = strlen(VSTR(table));
- register u_char *str;
- flagmodification(VTX(tx), &start, &end);
- while(start.pos_Line < end.pos_Line)
- {
- int llen = line->ln_Strlen - 1;
- str = line->ln_Line + start.pos_Col;
- while(start.pos_Col++ < llen)
- {
- register u_char c = *str;
- *str++ = (c < tablen) ? VSTR(table)[c] : c;
- }
- start.pos_Col = 0;
- start.pos_Line++;
- line++;
- }
- str = line->ln_Line + start.pos_Col;
- while(start.pos_Col++ < end.pos_Col)
- {
- register u_char c = *str;
- *str++ = (c < tablen) ? VSTR(table)[c] : c;
- }
- return(sym_t);
- }
- return(NULL);
- }
-
- _PR VALUE cmd_alpha_char_p(VALUE ch);
- DEFUN("alpha-char-p", cmd_alpha_char_p, subr_alpha_char_p, (VALUE ch), V_Subr1, DOC_alpha_char_p) /*
- ::doc:alpha_char_p::
- (alpha-char-p CHAR)
- Returns t if CHAR is an alphabetic character.
- ::end:: */
- {
- DECLARE1(ch, CHARP);
- if(isalpha(VCHAR(ch)))
- return(sym_t);
- return(sym_nil);
- }
- _PR VALUE cmd_upper_case_p(VALUE ch);
- DEFUN("upper-case-p", cmd_upper_case_p, subr_upper_case_p, (VALUE ch), V_Subr1, DOC_upper_case_p) /*
- ::doc:upper_case_p::
- (upper-case-p CHAR)
- Returns t if CHAR is upper case.
- ::end:: */
- {
- DECLARE1(ch, CHARP);
- if(isupper(VCHAR(ch)))
- return(sym_t);
- return(sym_nil);
- }
- _PR VALUE cmd_lower_case_p(VALUE ch);
- DEFUN("lower-case-p", cmd_lower_case_p, subr_lower_case_p, (VALUE ch), V_Subr1, DOC_lower_case_p) /*
- ::doc:lower_case_p::
- (lower-case-p CHAR)
- Returns t if CHAR is lower case.
- ::end:: */
- {
- DECLARE1(ch, CHARP);
- if(islower(VCHAR(ch)))
- return(sym_t);
- return(sym_nil);
- }
- _PR VALUE cmd_digit_char_p(VALUE ch);
- DEFUN("digit-char-p", cmd_digit_char_p, subr_digit_char_p, (VALUE ch), V_Subr1, DOC_digit_char_p) /*
- ::doc:digit_char_p::
- (digit-char-p CHAR)
- Returns t if CHAR is a digit.
- ::end:: */
- {
- DECLARE1(ch, CHARP);
- if(isdigit(VCHAR(ch)))
- return(sym_t);
- return(sym_nil);
- }
- _PR VALUE cmd_alphanumericp(VALUE ch);
- DEFUN("alphanumericp", cmd_alphanumericp, subr_alphanumericp, (VALUE ch), V_Subr1, DOC_alphanumericp) /*
- ::doc:alphanumericp::
- (alphanumericp CHAR)
- Returns t if CHAR is alpha-numeric.
- ::end:: */
- {
- DECLARE1(ch, CHARP);
- if(isalnum(VCHAR(ch)))
- return(sym_t);
- return(sym_nil);
- }
- _PR VALUE cmd_space_char_p(VALUE ch);
- DEFUN("space-char-p", cmd_space_char_p, subr_space_char_p, (VALUE ch), V_Subr1, DOC_space_char_p) /*
- ::doc:space_char_p::
- (space-char-p CHAR)
- Returns t if CHAR is whitespace.
- ::end:: */
- {
- DECLARE1(ch, CHARP);
- if(isspace(VCHAR(ch)))
- return(sym_t);
- return(sym_nil);
- }
- _PR VALUE cmd_char_upcase(VALUE ch);
- DEFUN("char-upcase", cmd_char_upcase, subr_char_upcase, (VALUE ch), V_Subr1, DOC_char_upcase) /*
- ::doc:char_upcase::
- (char-upcase CHAR)
- Returns the upper-case equivalent of CHAR.
- ::end:: */
- {
- DECLARE1(ch, CHARP);
- return(newnumber(toupper(VCHAR(ch))));
- }
- _PR VALUE cmd_char_downcase(VALUE ch);
- DEFUN("char-downcase", cmd_char_downcase, subr_char_downcase, (VALUE ch), V_Subr1, DOC_char_downcase) /*
- ::doc:char_downcase::
- (char-downcase CHAR)
- Returns the lower-case equivalent of CHAR.
- ::end:: */
- {
- DECLARE1(ch, CHARP);
- return(newnumber(toupper(VCHAR(ch))));
- }
-
- _PR VALUE cmd_pos_line(VALUE pos);
- DEFUN("pos-line", cmd_pos_line, subr_pos_line, (VALUE pos), V_Subr1, DOC_pos_line) /*
- ::doc:pos_line::
- (pos-line POS)
- Returns the line number which POS points to.
- ::end:: */
- {
- DECLARE1(pos, POSP);
- return(newnumber(VPOS(pos).pos_Line + 1));
- }
- _PR VALUE cmd_pos_col(VALUE pos);
- DEFUN("pos-col", cmd_pos_col, subr_pos_col, (VALUE pos), V_Subr1, DOC_pos_col) /*
- ::doc:pos_col::
- (pos-col POS)
- Return the column number which POS points to.
- ::end:: */
- {
- DECLARE1(pos, POSP);
- return(newnumber(VPOS(pos).pos_Col + 1));
- }
- _PR VALUE cmd_set_pos_line(VALUE pos, VALUE line);
- DEFUN("set-pos-line", cmd_set_pos_line, subr_set_pos_line, (VALUE pos, VALUE line), V_Subr2, DOC_set_pos_line) /*
- ::doc:set_pos_line::
- (set-pos-line POS LINE)
- Sets the line number of POS to LINE.
- ::end:: */
- {
- DECLARE1(pos, POSP);
- DECLARE2(line, NUMBERP);
- VPOS(pos).pos_Line = VNUM(line) - 1;
- return(line);
- }
- _PR VALUE cmd_set_pos_col(VALUE pos, VALUE col);
- DEFUN("set-pos-col", cmd_set_pos_col, subr_set_pos_col, (VALUE pos, VALUE col), V_Subr2, DOC_set_pos_col) /*
- ::doc:set_pos_col::
- (set-pos-col POS COL)
- Sets the column number of POS to COL.
- ::end:: */
- {
- DECLARE1(pos, POSP);
- DECLARE2(col, NUMBERP);
- VPOS(pos).pos_Col = VNUM(col) - 1;
- return(col);
- }
-
- _PR VALUE cmd_posp(VALUE arg);
- DEFUN("posp", cmd_posp, subr_posp, (VALUE arg), V_Subr1, DOC_posp) /*
- ::doc:posp::
- (posp ARG)
- Returns t if ARG is a position object.
- ::end:: */
- {
- if(POSP(arg))
- return(sym_t);
- return(sym_nil);
- }
-
- _PR VALUE cmd_cursor_pos(void);
- DEFUN("cursor-pos", cmd_cursor_pos, subr_cursor_pos, (void), V_Subr0, DOC_cursor_pos) /*
- ::doc:cursor_pos::
- (cursor-pos)
- Returns the position of the cursor in the current window.
- ::end:: */
- {
- return(newlpos(&CurrVW->vw_CursorPos));
- }
-
- _PR VALUE cmd_empty_line_p(VALUE lpos, VALUE tx);
- DEFUN("empty-line-p", cmd_empty_line_p, subr_empty_line_p, (VALUE lpos, VALUE tx), V_Subr2, DOC_empty_line_p) /*
- ::doc:empty_line_p::
- (empty-line-p [POS] [BUFFER])
- Returns t if the line pointer to by POS (or the cursor) in BUFFER is
- empty, ie, blank or only containing spaces.
- ::end:: */
- {
- VW *vw = CurrVW;
- POS pos;
- LINE *line;
- if(POSP(lpos))
- pos = VPOS(lpos);
- else
- pos = vw->vw_CursorPos;
- if(!BUFFERP(tx))
- tx = vw->vw_Tx;
- line = VTX(tx)->tx_Lines + pos.pos_Line;
- if(line->ln_Strlen == 1)
- return(sym_t);
- else
- {
- u_char *s = line->ln_Line;
- while(*s && isspace(*s))
- s++;
- if(!(*s))
- return(sym_t);
- }
- return(sym_nil);
- }
-
- _PR VALUE cmd_indent_pos(VALUE lpos, VALUE tx);
- DEFUN("indent-pos", cmd_indent_pos, subr_indent_pos, (VALUE lpos, VALUE tx), V_Subr2, DOC_indent_pos) /*
- ::doc:indent_pos::
- (indent-pos [POS] [BUFFER])
- Returns the position of the first non-space character in the line pointer
- to by POS (or the cursor), in BUFFER.
- ::end:: */
- {
- VW *vw = CurrVW;
- POS pos;
- long len;
- u_char *line;
- if(!BUFFERP(tx))
- tx = vw->vw_Tx;
- if(POSP(lpos) && checkline(VTX(tx), &VPOS(lpos)))
- pos = VPOS(lpos);
- else
- pos = vw->vw_CursorPos;
- line = VTX(tx)->tx_Lines[pos.pos_Line].ln_Line;
- for(len = 0; *line && isspace(*line); len++, line++)
- ;
- return(newlpos2(len, pos.pos_Line));
- }
-
- _PR VALUE cmd_set_indent_pos(VALUE indpos, VALUE tx);
- DEFUN("set-indent-pos", cmd_set_indent_pos, subr_set_indent_pos, (VALUE indpos, VALUE tx), V_Subr2, DOC_set_indent_pos) /*
- ::doc:set_indent_pos::
- (set-indent-pos POS [BUFFER])
- Sets the indentation of the line pointed to by POS to the column pointed
- to by POS by either deleting characters from the start of the line, or
- inserting spaces.
- ::end:: */
- {
- DECLARE1(indpos, POSP);
- if(!BUFFERP(tx))
- tx = CurrVW->vw_Tx;
- if((!readonly(VTX(tx))) && checkline(VTX(tx), &VPOS(indpos)))
- {
- LINE *line = VTX(tx)->tx_Lines + VPOS(indpos).pos_Line;
- u_char *s = line->ln_Line;
- POS pos = VPOS(indpos), end;
- long oldind, diff;
- bool empty = FALSE;
- while(*s && isspace(*s))
- s++;
- oldind = s - line->ln_Line;
- if(!(*s))
- empty = TRUE;
- diff = oldind - pos.pos_Col;
- if(diff > 0)
- {
- deletechars(VTX(tx), &pos, diff);
- end.pos_Line = pos.pos_Line;
- end.pos_Col = pos.pos_Col + diff;
- flagdeletion(VTX(tx), &pos, &end);
- }
- else if(diff < 0)
- {
- diff = -diff;
- pos.pos_Col = oldind;
- insertgap(VTX(tx), diff, &pos);
- end.pos_Line = pos.pos_Line;
- end.pos_Col = pos.pos_Col + diff;
- flaginsertion(VTX(tx), &pos, &end);
- memset(line->ln_Line + oldind, ' ', diff);
- }
- return(indpos);
- }
- return(sym_nil);
- }
-
- _PR VALUE cmd_clear_buffer(VALUE tx);
- DEFUN("clear-buffer", cmd_clear_buffer, subr_clear_buffer, (VALUE tx), V_Subr1, DOC_clear_buffer) /*
- ::doc:clear_buffer::
- (clear-buffer [BUFFER])
- Remove all text from BUFFER, leaving just one empty line.
- ::end:: */
- {
- if(!BUFFERP(tx))
- tx = CurrVW->vw_Tx;
- if(clearlinelist(VTX(tx)))
- {
- resetallviews(VTX(tx));
- return(tx);
- }
- return(sym_nil);
- }
-
- void
- edit_init(void)
- {
- int i;
- ADD_SUBR(subr_split_line);
- ADD_SUBR(subr_insert);
- ADD_SUBR(subr_insert_rect);
- ADD_SUBR(subr_delete_area);
- ADD_SUBR(subr_delete_rect);
- ADD_SUBR(subr_copy_area);
- ADD_SUBR(subr_copy_rect);
- ADD_SUBR(subr_cut_area);
- ADD_SUBR(subr_cut_rect);
- ADD_SUBR(subr_block_toggle);
- ADD_SUBR(subr_block_start);
- ADD_SUBR(subr_block_end);
- ADD_SUBR(subr_block_kill);
- ADD_SUBR(subr_blockp);
- ADD_SUBR(subr_translate_area);
- ADD_SUBR(subr_alpha_char_p);
- ADD_SUBR(subr_upper_case_p);
- ADD_SUBR(subr_lower_case_p);
- ADD_SUBR(subr_digit_char_p);
- ADD_SUBR(subr_alphanumericp);
- ADD_SUBR(subr_space_char_p);
- ADD_SUBR(subr_char_upcase);
- ADD_SUBR(subr_char_downcase);
- ADD_SUBR(subr_pos_line);
- ADD_SUBR(subr_pos_col);
- ADD_SUBR(subr_set_pos_line);
- ADD_SUBR(subr_set_pos_col);
- ADD_SUBR(subr_posp);
- ADD_SUBR(subr_cursor_pos);
- ADD_SUBR(subr_empty_line_p);
- ADD_SUBR(subr_indent_pos);
- ADD_SUBR(subr_set_indent_pos);
- ADD_SUBR(subr_clear_buffer);
-
- UpCaseTable[0] = DownCaseTable[0] = V_StaticString;
- /* jade can't handle zeros in strings :-( */
- UpCaseTable[1] = DownCaseTable[1] = ' ';
- for(i = 1; i < 256; i++)
- UpCaseTable[i+1] = toupper(i);
- for(i = 1; i < 256; i++)
- DownCaseTable[i+1] = tolower(i);
- INTERN(sym_upcase_table, "upcase-table");
- VSYM(sym_upcase_table)->sym_Value = (String *)UpCaseTable;
- INTERN(sym_downcase_table, "downcase-table");
- VSYM(sym_downcase_table)->sym_Value = (String *)DownCaseTable;
- }
-