home *** CD-ROM | disk | FTP | other *** search
- /* 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>
-
- _PR long movedownpages(long);
- _PR long moveuppages(long);
- static int findmatchingbracket(POS *, TX *);
- _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(newnumber(CurrVW->vw_StartLine + 1));
- }
-
- _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(newnumber(CurrVW->vw_StartLine + CurrVW->vw_MaxY));
- }
-
- _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(newnumber(CurrVW->vw_StartCol + 1));
- }
-
- _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(newnumber(CurrVW->vw_StartCol + CurrVW->vw_MaxX));
- }
-
- _PR VALUE cmd_goto(VALUE pos);
- DEFUN("goto", cmd_goto, subr_goto, (VALUE pos), V_Subr1, DOC_goto) /*
- ::doc:goto::
- (goto POS)
- Set the cursor position in the current window to POS.
- ::end:: */
- {
- VW *vw = CurrVW;
- DECLARE1(pos, POSP);
- if(checkline(vw->vw_Tx, &VPOS(pos)))
- {
- vw->vw_CursorPos = VPOS(pos);
- return(pos);
- }
- return(sym_nil);
- }
-
- _PR VALUE cmd_next_screen(VALUE number);
- DEFUN("next-screen", cmd_next_screen, subr_next_screen, (VALUE number), V_Subr1, DOC_next_screen) /*
- ::doc:next_screen::
- (next-screen [NUMBER])
- Move NUMBER (default: 1) screens forwards in the current window.
- ::end:: */
- {
- if(movedownpages(NUMBERP(number) ? VNUM(number) : 1))
- return(sym_t);
- return(sym_nil);
- }
-
- _PR VALUE cmd_prev_screen(VALUE number);
- DEFUN("prev-screen", cmd_prev_screen, subr_prev_screen, (VALUE number), V_Subr1, DOC_prev_screen) /*
- ::doc:prev_screen::
- (prev-screen [NUMBER])
- Move NUMBER (default: 1) screens backwards in the current window.
- ::end:: */
- {
- if(moveuppages(NUMBERP(number) ? VNUM(number) : 1))
- return(sym_t);
- return(sym_nil);
- }
-
- _PR VALUE cmd_file_end(VALUE tx);
- DEFUN("file-end", cmd_file_end, subr_file_end, (VALUE tx), V_Subr1, DOC_file_end) /*
- ::doc:file_end::
- (file-end [BUFFER])
- Return the position of the last character in BUFFER.
- ::end:: */
- {
- long x, y;
- if(!BUFFERP(tx))
- tx = CurrVW->vw_Tx;
- y = VTX(tx)->tx_NumLines - 1;
- x = VTX(tx)->tx_Lines[y].ln_Strlen - 1;
- return(newlpos2(x, y));
- }
-
- _PR VALUE cmd_goto_file_end(void);
- DEFUN("goto-file-end", cmd_goto_file_end, subr_goto_file_end, (void), V_Subr0, DOC_goto_file_end) /*
- ::doc:goto_file_end::
- (goto-file-end)
- Move to the last character in the current window.
- ::end:: */
- {
- VW *vw = CurrVW;
- 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_file_start(void);
- DEFUN("file-start", cmd_file_start, subr_file_start, (void), V_Subr0, DOC_file_start) /*
- ::doc:file_start::
- (file-start)
- Return the position of the start of the file.
- ::end:: */
- {
- return(newlpos2(0, 0));
- }
-
- _PR VALUE cmd_goto_file_start(void);
- DEFUN("goto-file-start", cmd_goto_file_start, subr_goto_file_start, (void), V_Subr0, DOC_goto_file_start) /*
- ::doc:goto_file_start::
- (goto-file-start)
- Move to the first character in the buffer displayed in the current window.
- ::end:: */
- {
- CurrVW->vw_CursorPos.pos_Col = 0;
- CurrVW->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 = CurrVW->vw_Tx;
- if(POSP(pos))
- res.pos_Line = VPOS(pos).pos_Line;
- else
- res.pos_Line = gettxcurspos(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(newlpos(&res));
- }
- return(sym_nil);
- }
-
- _PR VALUE cmd_goto_line_end(void);
- DEFUN("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 = CurrVW;
- 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 = CurrVW->vw_CursorPos.pos_Line;
- res.pos_Col = 0;
- return(newlpos(&res));
- }
-
- _PR VALUE cmd_goto_line_start(void);
- DEFUN("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 = CurrVW;
- vw->vw_CursorPos.pos_Col = 0;
- return(sym_t);
- }
-
- _PR VALUE cmd_next_line(VALUE lines, VALUE pos);
- DEFUN("next-line", cmd_next_line, subr_next_line, (VALUE lines, VALUE pos), V_Subr2, DOC_next_line) /*
- ::doc:next_line::
- (next-line [NUMBER] [POS])
- Return the position of the NUMBERth (def: 1) line down from that pointed to
- by POS (or the cursor). POS is altered.
- ::end:: */
- {
- if(!POSP(pos))
- pos = newlpos(&CurrVW->vw_CursorPos);
- VPOS(pos).pos_Line += NUMBERP(lines) ? VNUM(lines) : 1;
- if(VPOS(pos).pos_Line > 0)
- return(pos);
- return(sym_nil);
- }
-
- _PR VALUE cmd_goto_next_line(VALUE lines);
- DEFUN("goto-next-line", cmd_goto_next_line, subr_goto_next_line, (VALUE lines), V_Subr1, DOC_goto_next_line) /*
- ::doc:goto_next_line::
- (goto-next-line [NUMBER])
- Move NUMBER lines (def: 1) downwards.
- ::end:: */
- {
- VW *vw = CurrVW;
- vw->vw_CursorPos.pos_Line += NUMBERP(lines) ? VNUM(lines) : 1;
- if(vw->vw_CursorPos.pos_Line >= vw->vw_Tx->tx_NumLines)
- {
- vw->vw_CursorPos.pos_Line = vw->vw_Tx->tx_NumLines - 1;
- return(sym_nil);
- }
- else if(vw->vw_CursorPos.pos_Line < 0)
- {
- vw->vw_CursorPos.pos_Line = 0;
- return(sym_nil);
- }
- return(sym_t);
- }
-
- _PR VALUE cmd_prev_line(VALUE lines, VALUE pos);
- DEFUN("prev-line", cmd_prev_line, subr_prev_line, (VALUE lines, VALUE pos), V_Subr2, DOC_prev_line) /*
- ::doc:prev_line::
- (prev-line [NUMBER] [POS])
- Return the position of the NUMBERth (def: 1) line up from that pointed to
- by POS (or the cursor). POS is altered.
- ::end:: */
- {
- if(!POSP(pos))
- pos = newlpos(&CurrVW->vw_CursorPos);
- VPOS(pos).pos_Line -= NUMBERP(lines) ? VNUM(lines) : 1;
- if(VPOS(pos).pos_Line >= 0)
- return(pos);
- return(sym_nil);
- }
-
- _PR VALUE cmd_goto_prev_line(VALUE lines);
- DEFUN("goto-prev-line", cmd_goto_prev_line, subr_goto_prev_line, (VALUE lines), V_Subr1, DOC_goto_prev_line) /*
- ::doc:goto_prev_line::
- (goto-next-line [NUMBER])
- Move NUMBER lines (def: 1) upwards.
- ::end:: */
- {
- VW *vw = CurrVW;
- vw->vw_CursorPos.pos_Line -= NUMBERP(lines) ? VNUM(lines) : 1;
- if(vw->vw_CursorPos.pos_Line >= vw->vw_Tx->tx_NumLines)
- {
- vw->vw_CursorPos.pos_Line = vw->vw_Tx->tx_NumLines - 1;
- return(sym_nil);
- }
- else if(vw->vw_CursorPos.pos_Line < 0)
- {
- vw->vw_CursorPos.pos_Line = 0;
- return(sym_nil);
- }
- return(sym_t);
- }
-
- _PR VALUE cmd_left_char(VALUE chars, VALUE pos);
- DEFUN("left-char", cmd_left_char, subr_left_char, (VALUE chars, VALUE pos), V_Subr2, DOC_left_char) /*
- ::doc:left_char::
- (left-char [NUMBER] [POS])
- Return the position of the NUMBERth character (def: 1) to the left of the
- one pointed to by POS (or the cursor). If that position is before the
- beginning of the line, returns nil. POS is altered.
- ::end:: */
- {
- if(!POSP(pos))
- pos = newlpos(&CurrVW->vw_CursorPos);
- VPOS(pos).pos_Col -= NUMBERP(chars) ? VNUM(chars) : 1;
- if(VPOS(pos).pos_Col >= 0)
- return(pos);
- return(sym_nil);
- }
-
- _PR VALUE cmd_goto_left_char(VALUE chars);
- DEFUN("goto-left-char", cmd_goto_left_char, subr_goto_left_char, (VALUE chars), V_Subr1, DOC_goto_left_char) /*
- ::doc:goto_left_char::
- (goto-left-char [NUMBER])
- Move NUMBER chars (def: 1) to the left.
- ::end:: */
- {
- VW *vw = CurrVW;
- vw->vw_CursorPos.pos_Col -= NUMBERP(chars) ? VNUM(chars) : 1;
- if(vw->vw_CursorPos.pos_Col > 0)
- return(sym_t);
- vw->vw_CursorPos.pos_Col = 0;
- return(sym_nil);
- }
-
- _PR VALUE cmd_right_char(VALUE chars, VALUE pos);
- DEFUN("right-char", cmd_right_char, subr_right_char, (VALUE chars, VALUE pos), V_Subr2, DOC_right_char) /*
- ::doc:right_char::
- (right-char [NUMBER] [POS])
- Return the position of the NUMBERth character (def: 1) to the right of the
- one pointed to by POS (or the cursor). Doesn't pay any attention to newlines.
- POS is altered.
- ::end:: */
- {
- if(!POSP(pos))
- pos = newlpos(&CurrVW->vw_CursorPos);
- VPOS(pos).pos_Col += NUMBERP(chars) ? VNUM(chars) : 1;
- if(VPOS(pos).pos_Col >= 0)
- return(pos);
- return(sym_nil);
- }
-
- _PR VALUE cmd_goto_right_char(VALUE chars);
- DEFUN("goto-right-char", cmd_goto_right_char, subr_goto_right_char, (VALUE chars), V_Subr1, DOC_goto_right_char) /*
- ::doc:goto_right_char::
- (goto-right-char [NUMBER])
- Move NUMBER chars (def: 1) to the right
- ::end:: */
- {
- VW *vw = CurrVW;
- vw->vw_CursorPos.pos_Col += NUMBERP(chars) ? VNUM(chars) : 1;
- if(vw->vw_CursorPos.pos_Col > 0)
- return(sym_t);
- vw->vw_CursorPos.pos_Col = 0;
- return(sym_nil);
- }
-
- _PR VALUE cmd_prev_tab(VALUE num, VALUE pos);
- DEFUN("prev-tab", cmd_prev_tab, subr_prev_tab, (VALUE num, VALUE pos), V_Subr2, DOC_prev_tab) /*
- ::doc:prev_tab::
- (prev-tab [NUMBER] [POS])
- Return the position of the NUMBERth (def: 1) tab stop to the left of POS (or
- the cursor). Returns nil if that position is past the beginning of the line.
- POS is altered.
- ::end:: */
- {
- int tabs = 1;
- VW *vw = CurrVW;
- if(!POSP(pos))
- pos = newlpos(&CurrVW->vw_CursorPos);
- if(NUMBERP(num))
- tabs = VNUM(num);
- if(tabs > 0)
- {
- while(tabs--)
- VPOS(pos).pos_Col = (((VPOS(pos).pos_Col - 1) / vw->vw_Tx->tx_TabSize)) * vw->vw_Tx->tx_TabSize;
- }
- else if(tabs < 0)
- {
- while(tabs++)
- VPOS(pos).pos_Col = ((VPOS(pos).pos_Col / vw->vw_Tx->tx_TabSize) + 1) * vw->vw_Tx->tx_TabSize;
- }
- if(VPOS(pos).pos_Col >= 0)
- return(pos);
- VPOS(pos).pos_Col = 0;
- return(sym_nil);
- }
-
- _PR VALUE cmd_goto_prev_tab(VALUE num);
- DEFUN("goto-prev-tab", cmd_goto_prev_tab, subr_goto_prev_tab, (VALUE num), V_Subr1, DOC_goto_prev_tab) /*
- ::doc:goto_prev_tab::
- (goto-prev-tab [NUMBER])
- Move NUMBER (def: 1) tab stops to the left.
- ::end:: */
- {
- int tabs = 1;
- VW *vw = CurrVW;
- if(NUMBERP(num))
- tabs = VNUM(num);
- if(tabs > 0)
- {
- while(tabs--)
- vw->vw_CursorPos.pos_Col = (((vw->vw_CursorPos.pos_Col - 1) / vw->vw_Tx->tx_TabSize)) * vw->vw_Tx->tx_TabSize;
- }
- else if(tabs < 0)
- {
- while(tabs++)
- vw->vw_CursorPos.pos_Col = ((vw->vw_CursorPos.pos_Col / vw->vw_Tx->tx_TabSize) + 1) * vw->vw_Tx->tx_TabSize;
- }
- if(vw->vw_CursorPos.pos_Col >= 0)
- return(sym_t);
- vw->vw_CursorPos.pos_Col = 0;
- return(sym_nil);
- }
-
- _PR VALUE cmd_next_tab(VALUE num, VALUE pos);
- DEFUN("next-tab", cmd_next_tab, subr_next_tab, (VALUE num, VALUE pos), V_Subr2, DOC_next_tab) /*
- ::doc:next_tab::
- (next-tab [NUMBER] [POS])
- Return the position of the NUMBERth (def: 1) tab stop to the right of POS (or
- the cursor). POS is altered.
- ::end:: */
- {
- int tabs = 1;
- VW *vw = CurrVW;
- if(!POSP(pos))
- pos = newlpos(&CurrVW->vw_CursorPos);
- if(NUMBERP(num))
- tabs = VNUM(num);
- if(tabs > 0)
- {
- while(tabs--)
- VPOS(pos).pos_Col = ((VPOS(pos).pos_Col / vw->vw_Tx->tx_TabSize) + 1) * vw->vw_Tx->tx_TabSize;
- }
- else if(tabs < 0)
- {
- while(tabs++)
- VPOS(pos).pos_Col = (((VPOS(pos).pos_Col - 1) / vw->vw_Tx->tx_TabSize)) * vw->vw_Tx->tx_TabSize;
- }
- if(VPOS(pos).pos_Col >= 0)
- return(pos);
- VPOS(pos).pos_Col = 0;
- return(sym_nil);
- }
-
- _PR VALUE cmd_goto_next_tab(VALUE num);
- DEFUN("goto-next-tab", cmd_goto_next_tab, subr_goto_next_tab, (VALUE num), V_Subr1, DOC_goto_next_tab) /*
- ::doc:goto_next_tab::
- (goto-next-tab [NUMBER])
- Move NUMBER (def: 1) tab stops to the right
- ::end:: */
- {
- int tabs = 1;
- VW *vw = CurrVW;
- if(NUMBERP(num))
- tabs = VNUM(num);
- if(tabs > 0)
- {
- while(tabs--)
- vw->vw_CursorPos.pos_Col = ((vw->vw_CursorPos.pos_Col / vw->vw_Tx->tx_TabSize) + 1) * vw->vw_Tx->tx_TabSize;
- }
- else if(tabs < 0)
- {
- while(tabs++)
- vw->vw_CursorPos.pos_Col = (((vw->vw_CursorPos.pos_Col - 1) / vw->vw_Tx->tx_TabSize)) * vw->vw_Tx->tx_TabSize;
- }
- if(vw->vw_CursorPos.pos_Col >= 0)
- return(sym_t);
- vw->vw_CursorPos.pos_Col = 0;
- return(sym_nil);
- }
-
- static INLINE int
- prevchar(POS *pos, TX *tx)
- {
- if(--pos->pos_Col < 0)
- {
- if(--pos->pos_Line >= 0)
- {
- pos->pos_Col = tx->tx_Lines[pos->pos_Line].ln_Strlen - 1;
- return(TRUE);
- }
- else
- pos->pos_Col = pos->pos_Line = 0;
- }
- else
- return(TRUE);
- return(FALSE);
- }
- static INLINE int
- nextchar(POS *pos, TX *tx)
- {
- if(++pos->pos_Col >= tx->tx_Lines[pos->pos_Line].ln_Strlen)
- {
- if(++pos->pos_Line < tx->tx_NumLines)
- {
- pos->pos_Col = 0;
- return(TRUE);
- }
- else
- {
- pos->pos_Line = tx->tx_NumLines - 1;
- pos->pos_Col = tx->tx_Lines[pos->pos_Line].ln_Strlen - 1;
- }
- }
- else
- return(TRUE);
- return(FALSE);
- }
-
- _PR VALUE cmd_next_char(VALUE pos, VALUE tx);
- DEFUN("next-char", cmd_next_char, subr_next_char, (VALUE pos, VALUE tx), V_Subr2, DOC_next_char) /*
- ::doc:next_char::
- (next-char [POS])
- Returns the position of the next character after POS (or the cursor).
- Will move to the start of the next line after the end of the current line.
- POS is altered.
- ::end:: */
- {
- if(!BUFFERP(tx))
- tx = CurrVW->vw_Tx;
- if(!POSP(pos))
- pos = newlpos(gettxcurspos(VTX(tx)));
- else
- checkpos(VTX(tx), &VPOS(pos));
- if(nextchar(&VPOS(pos), VTX(tx)))
- return(pos);
- return(sym_nil);
- }
-
- _PR VALUE cmd_goto_next_char(void);
- DEFUN("goto-next-char", cmd_goto_next_char, subr_goto_next_char, (void), V_Subr0, DOC_goto_next_char) /*
- ::doc:goto_next_char::
- (goto-next-char)
- Moves to the next character. Will move to the start of the next line after
- the end of the current line.
- ::end:: */
- {
- VW *vw = CurrVW;
- if(nextchar(&vw->vw_CursorPos, vw->vw_Tx))
- return(sym_t);
- return(sym_nil);
- }
-
- _PR VALUE cmd_prev_char(VALUE pos, VALUE tx);
- DEFUN("prev-char", cmd_prev_char, subr_prev_char, (VALUE pos, VALUE tx), V_Subr2, DOC_prev_char) /*
- ::doc:prev_char::
- (prev-char [POS])
- Returns the position of the character before POS (or the cursor). Will move
- to the start of the next line after the end of the current line.
- POS is altered.
- ::end:: */
- {
- if(!BUFFERP(tx))
- tx = CurrVW->vw_Tx;
- if(!POSP(pos))
- pos = newlpos(gettxcurspos(VTX(tx)));
- else
- checkpos(VTX(tx), &VPOS(pos));
- if(prevchar(&VPOS(pos), VTX(tx)))
- return(pos);
- return(sym_nil);
- }
-
- _PR VALUE cmd_goto_prev_char(void);
- DEFUN("goto-prev-char", cmd_goto_prev_char, subr_goto_prev_char, (void), V_Subr0, DOC_goto_prev_char) /*
- ::doc:goto_prev_char::
- (goto-prev-char)
- Moves to the previous character. Will move to the start of the next line
- after the end of the current line.
- ::end:: */
- {
- VW *vw = CurrVW;
- if(prevchar(&vw->vw_CursorPos, vw->vw_Tx))
- return(sym_t);
- return(sym_nil);
- }
-
- _PR VALUE cmd_match_brackets(VALUE pos, VALUE tx);
- DEFUN("match-brackets", cmd_match_brackets, subr_match_brackets, (VALUE pos, VALUE tx), V_Subr2, DOC_match_brackets) /*
- ::doc:match_brackets::
- (match-brackets [POS] [BUFFER])
- Find a bracket matching the one at POS (or the cursor). The things that match
- each other are, { }, ( ), [ ], ` ', < >. POS is altered.
- ::end:: */
- {
- if(!BUFFERP(tx))
- tx = CurrVW->vw_Tx;
- if(!POSP(pos))
- pos = newlpos(gettxcurspos(VTX(tx)));
- else
- checkpos(VTX(tx), &VPOS(pos));
- if(findmatchingbracket(&VPOS(pos), VTX(tx)))
- return(pos);
- return(sym_nil);
- }
-
- _PR VALUE cmd_mouse_pos(void);
- DEFUN("mouse-pos", cmd_mouse_pos, subr_mouse_pos, (void), V_Subr0, DOC_mouse_pos) /*
- ::doc:mouse_pos::
- (mouse-pos)
- Return the position of the mouse pointer, relative to the display origin of
- the buffer in the current window.
- ::end:: */
- {
- VALUE pos;
- if((pos = newlpos2(0, 0)) && makemousepos(&VPOS(pos), CurrVW))
- return(pos);
- return(sym_nil);
- }
-
- long
- movedownpages(long pages)
- {
- VW *vw = CurrVW;
- long newline, rc;
- newline = vw->vw_CursorPos.pos_Line + (pages * vw->vw_MaxY);
- if(newline >= vw->vw_Tx->tx_NumLines)
- {
- newline = vw->vw_Tx->tx_NumLines - 1;
- rc = FALSE;
- }
- else
- {
- vw->vw_StartLine += (pages * vw->vw_MaxY);
- vw->vw_Flags |= VWFF_FORCE_REFRESH;
- rc = TRUE;
- }
- vw->vw_CursorPos.pos_Line = newline;
- return(rc);
- }
-
- long
- moveuppages(long pages)
- {
- VW *vw = CurrVW;
- long newline, rc;
- newline = vw->vw_CursorPos.pos_Line - (pages * vw->vw_MaxY);
- if(newline < 0)
- {
- newline = 0;
- rc = FALSE;
- }
- else
- {
- vw->vw_StartLine -= (pages * vw->vw_MaxY);
- if(vw->vw_StartLine < 0)
- vw->vw_StartLine = 0;
- vw->vw_Flags |= VWFF_FORCE_REFRESH;
- rc = TRUE;
- }
- vw->vw_CursorPos.pos_Line = newline;
- return(rc);
- }
-
- static int
- findmatchingbracket(POS *pos, TX *tx)
- {
- #define NUM_BRAC_TYPES 10
- static u_char bracs[] =
- {
- '{', '}',
- '(', ')',
- '[', ']',
- '`', '\'',
- '<', '>'
- };
-
- LINE *line = tx->tx_Lines + pos->pos_Line;
- if(pos->pos_Col < line->ln_Strlen)
- {
- u_char startc = line->ln_Line[pos->pos_Col];
- long i;
- for(i = 0; i < NUM_BRAC_TYPES; i++)
- {
- if(startc == bracs[i])
- break;
- }
- if(i < NUM_BRAC_TYPES)
- {
- long x = pos->pos_Col;
- long y = pos->pos_Line;
- long braccount = 1;
- bool found = FALSE;
- if(i & 1)
- {
- /* search backwards
- */
- u_char endc = bracs[i - 1];
- while(!found)
- {
- u_char c;
- if(--x < 0)
- {
- if(--y < 0)
- {
- cmd_signal(sym_error, LIST_1(MKSTR("No matching bracket")));
- return(FALSE);
- }
- line--;
- x = line->ln_Strlen - 1;
- }
- c = line->ln_Line[x];
- if(c == startc)
- braccount++;
- else if(c == endc)
- {
- if(!(--braccount))
- found = TRUE;
- }
- }
- }
- else
- {
- /* search forwards
- */
- u_char endc = bracs[i + 1];
- while(!found)
- {
- u_char c;
- if(++x >= line->ln_Strlen)
- {
- if(++y >= tx->tx_NumLines)
- {
- cmd_signal(sym_error, LIST_1(MKSTR("No matching bracket")));
- return(FALSE);
- }
- line++;
- x = 0;
- }
- c = line->ln_Line[x];
- if(c == startc)
- braccount++;
- else if(c == endc)
- {
- if(!(--braccount))
- found = TRUE;
- }
- }
- }
- pos->pos_Col = x;
- pos->pos_Line = y;
- return(TRUE);
- }
- }
- cmd_signal(sym_error, LIST_1(MKSTR("No opening bracket")));
- return(FALSE);
- }
-
- void
- movement_init(void)
- {
- ADD_SUBR(subr_screen_top_line);
- ADD_SUBR(subr_screen_bottom_line);
- ADD_SUBR(subr_screen_first_column);
- ADD_SUBR(subr_screen_last_column);
- ADD_SUBR(subr_goto);
- ADD_SUBR(subr_next_screen);
- ADD_SUBR(subr_prev_screen);
- ADD_SUBR(subr_file_end);
- ADD_SUBR(subr_goto_file_end);
- ADD_SUBR(subr_file_start);
- ADD_SUBR(subr_goto_file_start);
- ADD_SUBR(subr_line_end);
- ADD_SUBR(subr_goto_line_end);
- ADD_SUBR(subr_line_start);
- ADD_SUBR(subr_goto_line_start);
- ADD_SUBR(subr_next_line);
- ADD_SUBR(subr_goto_next_line);
- ADD_SUBR(subr_prev_line);
- ADD_SUBR(subr_goto_prev_line);
- ADD_SUBR(subr_left_char);
- ADD_SUBR(subr_goto_left_char);
- ADD_SUBR(subr_right_char);
- ADD_SUBR(subr_goto_right_char);
- ADD_SUBR(subr_prev_tab);
- ADD_SUBR(subr_goto_prev_tab);
- ADD_SUBR(subr_next_tab);
- ADD_SUBR(subr_goto_next_tab);
- ADD_SUBR(subr_next_char);
- ADD_SUBR(subr_goto_next_char);
- ADD_SUBR(subr_prev_char);
- ADD_SUBR(subr_goto_prev_char);
- ADD_SUBR(subr_match_brackets);
- ADD_SUBR(subr_mouse_pos);
- }
-