home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD1.bin
/
new
/
util
/
edit
/
jade
/
src
/
movement.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-09-09
|
25KB
|
932 lines
/* movement.c -- Positioning the cursor
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 <ctype.h>
static long move_down_screens(long);
static long move_up_screens(long);
static bool prev_char(long, POS *, TX *);
static bool next_char(long, POS *, TX *);
static int find_matching_bracket(POS *, TX *, u_char esc);
_PR void movement_init(void);
_PR VALUE cmd_screen_top_line(void);
DEFUN("screen-top-line", cmd_screen_top_line, subr_screen_top_line, (void), V_Subr0, DOC_screen_top_line) /*
::doc:screen_top_line::
screen-top-line
Returns the line number of the first line being shown in the current window.
::end:: */
{
return(make_number(curr_vw->vw_StartLine));
}
_PR VALUE cmd_screen_bottom_line(void);
DEFUN("screen-bottom-line", cmd_screen_bottom_line, subr_screen_bottom_line, (void), V_Subr0, DOC_screen_bottom_line) /*
::doc:screen_bottom_line::
screen-bottom-line
Returns the line number of the last line being shown in the current window.
::end:: */
{
return(make_number(curr_vw->vw_StartLine + curr_vw->vw_MaxY - 1));
}
_PR VALUE cmd_screen_first_column(void);
DEFUN("screen-first-column", cmd_screen_first_column, subr_screen_first_column, (void), V_Subr0, DOC_screen_first_column) /*
::doc:screen_first_column::
screen-first-column
Returns the line number of the first column being shown in the current window.
::end:: */
{
return(make_number(curr_vw->vw_StartCol));
}
_PR VALUE cmd_screen_last_column(void);
DEFUN("screen-last-column", cmd_screen_last_column, subr_screen_last_column, (void), V_Subr0, DOC_screen_last_column) /*
::doc:screen_last_column::
screen-last-column
Returns the line number of the last column being shown in the current window.
::end:: */
{
return(make_number(curr_vw->vw_StartCol + curr_vw->vw_MaxX - 1));
}
_PR VALUE cmd_goto_char(VALUE pos);
DEFUN("goto-char", cmd_goto_char, subr_goto_char, (VALUE pos), V_Subr1, DOC_goto_char) /*
::doc:goto_char::
goto-char POS
Set the cursor position in the current window to the character position POS.
::end:: */
{
VW *vw = curr_vw;
DECLARE1(pos, POSP);
if(check_line(vw->vw_Tx, &VPOS(pos)))
{
vw->vw_CursorPos = VPOS(pos);
return(pos);
}
return(sym_nil);
}
_PR VALUE cmd_goto_glyph(VALUE pos);
DEFUN("goto-glyph", cmd_goto_glyph, subr_goto_glyph, (VALUE pos), V_Subr1, DOC_goto_glyph) /*
::doc:goto_glyph::
goto-glyph POS
Set the cursor position in the current window to the glyph position POS.
::end:: */
{
VW *vw = curr_vw;
DECLARE1(pos, POSP);
if(check_line(vw->vw_Tx, &VPOS(pos)))
{
vw->vw_CursorPos.pos_Col = char_col(vw->vw_Tx, VPOS(pos).pos_Col,
VPOS(pos).pos_Line);
vw->vw_CursorPos.pos_Line = VPOS(pos).pos_Line;
return(pos);
}
return(sym_nil);
}
_PR VALUE cmd_centre_display(VALUE vw);
DEFUN_INT("centre-display", cmd_centre_display, subr_centre_display, (VALUE vw), V_Subr1, DOC_centre_display, "") /*
::doc:centre_display::
centre-display [WINDOW]
Arrange it so that the line that the cursor is on is displayed in the
middle of the window (if possible).
::end:: */
{
long start_line;
if(!WINDOWP(vw))
vw = VAL(curr_vw);
start_line = VWIN(vw)->vw_CursorPos.pos_Line - (VWIN(vw)->vw_MaxY / 2);
if(start_line < 0)
start_line = 0;
if(start_line >= VWIN(vw)->vw_Tx->tx_NumLines)
start_line = VWIN(vw)->vw_Tx->tx_NumLines - 1;
VWIN(vw)->vw_StartLine = start_line;
return(vw);
}
_PR VALUE cmd_next_screen(VALUE number);
DEFUN_INT("next-screen", cmd_next_screen, subr_next_screen, (VALUE number), V_Subr1, DOC_next_screen, "p") /*
::doc:next_screen::
next-screen [NUMBER]
Move NUMBER (default: 1) screens forwards in the current window.
::end:: */
{
if(move_down_screens(NUMBERP(number) ? VNUM(number) : 1))
return(sym_t);
return(sym_nil);
}
_PR VALUE cmd_prev_screen(VALUE number);
DEFUN_INT("prev-screen", cmd_prev_screen, subr_prev_screen, (VALUE number), V_Subr1, DOC_prev_screen, "p") /*
::doc:prev_screen::
prev-screen [NUMBER]
Move NUMBER (default: 1) screens backwards in the current window.
::end:: */
{
if(move_up_screens(NUMBERP(number) ? VNUM(number) : 1))
return(sym_t);
return(sym_nil);
}
_PR VALUE cmd_buffer_end(VALUE tx);
DEFUN("buffer-end", cmd_buffer_end, subr_buffer_end, (VALUE tx), V_Subr1, DOC_buffer_end) /*
::doc:buffer_end::
buffer-end [BUFFER]
Return the position of the last character in BUFFER.
::end:: */
{
long x, y;
if(!BUFFERP(tx))
tx = VAL(curr_vw->vw_Tx);
y = VTX(tx)->tx_NumLines - 1;
x = VTX(tx)->tx_Lines[y].ln_Strlen - 1;
return(make_lpos2(x, y));
}
_PR VALUE cmd_goto_buffer_end(void);
DEFUN_INT("goto-buffer-end", cmd_goto_buffer_end, subr_goto_buffer_end, (void), V_Subr0, DOC_goto_buffer_end, "") /*
::doc:goto_buffer_end::
goto-buffer-end
Move to the last character in the current window.
::end:: */
{
VW *vw = curr_vw;
vw->vw_CursorPos.pos_Line = vw->vw_Tx->tx_NumLines - 1;
vw->vw_CursorPos.pos_Col = vw->vw_Tx->tx_Lines[vw->vw_CursorPos.pos_Line].ln_Strlen - 1;
return(sym_t);
}
_PR VALUE cmd_buffer_start(void);
DEFUN("buffer-start", cmd_buffer_start, subr_buffer_start, (void), V_Subr0, DOC_buffer_start) /*
::doc:buffer_start::
buffer-start
Return the position of the start of the buffer.
::end:: */
{
return(make_lpos2(0, 0));
}
_PR VALUE cmd_goto_buffer_start(void);
DEFUN_INT("goto-buffer-start", cmd_goto_buffer_start, subr_goto_buffer_start, (void), V_Subr0, DOC_goto_buffer_start, "") /*
::doc:goto_buffer_start::
goto-buffer-start
Move to the first character in the buffer displayed in the current window.
::end:: */
{
curr_vw->vw_CursorPos.pos_Col = 0;
curr_vw->vw_CursorPos.pos_Line = 0;
return(sym_t);
}
_PR VALUE cmd_line_end(VALUE pos, VALUE tx);
DEFUN("line-end", cmd_line_end, subr_line_end, (VALUE pos, VALUE tx), V_Subr2, DOC_line_end) /*
::doc:line_end::
line-end [POS] [BUFFER]
Return the position of the last character in the line pointed to by POS (or
the cursor).
::end:: */
{
POS res;
if(!BUFFERP(tx))
tx = VAL(curr_vw->vw_Tx);
if(POSP(pos))
res.pos_Line = VPOS(pos).pos_Line;
else
res.pos_Line = get_tx_cursor(VTX(tx))->pos_Line;
if(res.pos_Line < VTX(tx)->tx_NumLines)
{
res.pos_Col = VTX(tx)->tx_Lines[res.pos_Line].ln_Strlen - 1;
return(make_lpos(&res));
}
return(sym_nil);
}
_PR VALUE cmd_goto_line_end(void);
DEFUN_INT("goto-line-end", cmd_goto_line_end, subr_goto_line_end, (void), V_Subr0, DOC_goto_line_end, "") /*
::doc:goto_line_end::
goto-line-end
Move to the last character in the line.
::end:: */
{
VW *vw = curr_vw;
vw->vw_CursorPos.pos_Col = vw->vw_Tx->tx_Lines[vw->vw_CursorPos.pos_Line].ln_Strlen - 1;
return(sym_t);
}
_PR VALUE cmd_line_start(VALUE pos);
DEFUN("line-start", cmd_line_start, subr_line_start, (VALUE pos), V_Subr1, DOC_line_start) /*
::doc:line_start::
line-start [POS]
Return the position of the first character in the line pointed to by POS
(or the cursor).
::end:: */
{
POS res;
if(POSP(pos))
res.pos_Line = VPOS(pos).pos_Line;
else
res.pos_Line = curr_vw->vw_CursorPos.pos_Line;
res.pos_Col = 0;
return(make_lpos(&res));
}
_PR VALUE cmd_goto_line_start(void);
DEFUN_INT("goto-line-start", cmd_goto_line_start, subr_goto_line_start, (void), V_Subr0, DOC_goto_line_start, "") /*
::doc:goto_line_start::
goto-line-start
Move to the start of the current line.
::end:: */
{
VW *vw = curr_vw;
vw->vw_CursorPos.pos_Col = 0;
return(sym_t)