mirror of
https://github.com/rfivet/uemacs.git
synced 2025-09-26 23:14:02 -04:00
Review cursor move commands in basic.
This commit is contained in:
309
basic.c
309
basic.c
@@ -2,8 +2,6 @@
|
||||
|
||||
#include "basic.h"
|
||||
|
||||
#define CVMVAS 1 /* arguments to page forward/back in pages */
|
||||
|
||||
/* basic.c
|
||||
*
|
||||
* The routines in this file move the cursor around on the screen. They
|
||||
@@ -18,19 +16,18 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "buffer.h"
|
||||
#include "estruct.h"
|
||||
#include "input.h"
|
||||
#include "line.h"
|
||||
#include "mlout.h"
|
||||
#include "random.h"
|
||||
#include "terminal.h"
|
||||
#include "utf8.h"
|
||||
#include "window.h"
|
||||
|
||||
|
||||
int overlap = 0 ; /* line overlap in forw/back page */
|
||||
int curgoal ; /* Goal for C-P, C-N */
|
||||
#define CVMVAS 1 /* arguments to page forward/back in pages */
|
||||
|
||||
|
||||
int overlap = DEFAULT_OVERLAP ; /* line overlap in forw/back page */
|
||||
int curgoal ; /* Goal for C-P, C-N */
|
||||
|
||||
|
||||
/*
|
||||
@@ -38,7 +35,7 @@ int curgoal ; /* Goal for C-P, C-N */
|
||||
* column, return the best choice for the offset. The offset is returned.
|
||||
* Used by "C-N" and "C-P".
|
||||
*/
|
||||
static unsigned getgoal( struct line *dlp) {
|
||||
static unsigned getgoal( line_p dlp) {
|
||||
int col ;
|
||||
unsigned idx ;
|
||||
const unsigned len = llength( dlp) ;
|
||||
@@ -69,21 +66,117 @@ static unsigned getgoal( struct line *dlp) {
|
||||
}
|
||||
|
||||
/*
|
||||
* Move the cursor to the beginning of the current line.
|
||||
* Move the cursor to the beginning of the current line of active window.
|
||||
*/
|
||||
int gotobol(int f, int n)
|
||||
{
|
||||
curwp->w_doto = 0;
|
||||
return TRUE;
|
||||
boolean gotobol( int f, int n) {
|
||||
curwp->w_doto = 0 ;
|
||||
return TRUE ;
|
||||
}
|
||||
|
||||
/*
|
||||
* Move the cursor to the end of the current line. Trivial. No errors.
|
||||
* Move the cursor to the end of the current line of active window.
|
||||
*/
|
||||
int gotoeol(int f, int n)
|
||||
{
|
||||
curwp->w_doto = llength(curwp->w_dotp);
|
||||
return TRUE;
|
||||
boolean gotoeol( int f, int n) {
|
||||
curwp->w_doto = llength( curwp->w_dotp) ;
|
||||
return TRUE ;
|
||||
}
|
||||
|
||||
/*
|
||||
* Goto the beginning of the buffer. Massive adjustment of dot. This is
|
||||
* considered to be hard motion; it really isn't if the original value of dot
|
||||
* is the same as the new value of dot. Normally bound to "M-<".
|
||||
*/
|
||||
boolean gotobob( int f, int n) {
|
||||
curwp->w_dotp = lforw( curbp->b_linep) ;
|
||||
curwp->w_doto = 0 ;
|
||||
curwp->w_flag |= WFHARD ;
|
||||
return TRUE ;
|
||||
}
|
||||
|
||||
/*
|
||||
* Move to the end of the buffer. Dot is always put at the end of the file
|
||||
* (ZJ). The standard screen code does most of the hard parts of update.
|
||||
* Bound to "M->".
|
||||
*/
|
||||
boolean gotoeob( int f, int n) {
|
||||
curwp->w_dotp = curbp->b_linep ;
|
||||
curwp->w_doto = 0 ;
|
||||
curwp->w_flag |= WFHARD ;
|
||||
return TRUE ;
|
||||
}
|
||||
|
||||
/*
|
||||
* Move forward by full lines. If the number of lines to move is less than
|
||||
* zero, call the backward line function to actually do it. The last command
|
||||
* controls how the goal column is set. Bound to "C-N". No errors are
|
||||
* possible.
|
||||
*/
|
||||
boolean forwline( int f, int n) {
|
||||
line_p dlp ;
|
||||
|
||||
if (n < 0)
|
||||
return backline(f, -n);
|
||||
|
||||
/* if we are on the last line as we start....fail the command */
|
||||
if (curwp->w_dotp == curbp->b_linep)
|
||||
return FALSE;
|
||||
|
||||
/* if the last command was not a line move, reset the goal column */
|
||||
if ((lastflag & CFCPCN) == 0)
|
||||
curgoal = getccol(FALSE);
|
||||
|
||||
/* flag this command as a line move */
|
||||
thisflag |= CFCPCN;
|
||||
|
||||
/* and move the point down */
|
||||
dlp = curwp->w_dotp;
|
||||
while( n && dlp != curbp->b_linep) {
|
||||
dlp = lforw( dlp) ;
|
||||
n -= 1 ;
|
||||
}
|
||||
|
||||
/* reseting the current position */
|
||||
curwp->w_dotp = dlp;
|
||||
curwp->w_doto = getgoal(dlp);
|
||||
curwp->w_flag |= WFMOVE;
|
||||
return (n == 0) ? TRUE : FALSE ;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function is like "forwline", but goes backwards. The scheme is exactly
|
||||
* the same. Check for arguments that are less than zero and call your
|
||||
* alternate. Figure out the new line and call "movedot" to perform the
|
||||
* motion. No errors are possible. Bound to "C-P".
|
||||
*/
|
||||
boolean backline( int f, int n) {
|
||||
line_p dlp ;
|
||||
|
||||
if (n < 0)
|
||||
return forwline(f, -n);
|
||||
|
||||
/* if we are on the first line as we start....fail the command */
|
||||
if (lback(curwp->w_dotp) == curbp->b_linep)
|
||||
return FALSE;
|
||||
|
||||
/* if the last command was not a line move, reset the goal column */
|
||||
if ((lastflag & CFCPCN) == 0)
|
||||
curgoal = getccol(FALSE);
|
||||
|
||||
/* flag this command as a line move */
|
||||
thisflag |= CFCPCN;
|
||||
|
||||
/* and move the point up */
|
||||
dlp = curwp->w_dotp;
|
||||
while( n && lback( dlp) != curbp->b_linep) {
|
||||
dlp = lback( dlp) ;
|
||||
n -= 1 ;
|
||||
}
|
||||
|
||||
/* reseting the current position */
|
||||
curwp->w_dotp = dlp;
|
||||
curwp->w_doto = getgoal(dlp);
|
||||
curwp->w_flag |= WFMOVE;
|
||||
return (n == 0) ? TRUE : FALSE ;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -120,107 +213,7 @@ int gotoline( int f, int n) {
|
||||
|
||||
/* First, we go to the begin of the buffer. */
|
||||
gotobob(f, n);
|
||||
return forwline(f, n - 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Goto the beginning of the buffer. Massive adjustment of dot. This is
|
||||
* considered to be hard motion; it really isn't if the original value of dot
|
||||
* is the same as the new value of dot. Normally bound to "M-<".
|
||||
*/
|
||||
int gotobob(int f, int n)
|
||||
{
|
||||
curwp->w_dotp = lforw(curbp->b_linep);
|
||||
curwp->w_doto = 0;
|
||||
curwp->w_flag |= WFHARD;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Move to the end of the buffer. Dot is always put at the end of the file
|
||||
* (ZJ). The standard screen code does most of the hard parts of update.
|
||||
* Bound to "M->".
|
||||
*/
|
||||
int gotoeob(int f, int n)
|
||||
{
|
||||
curwp->w_dotp = curbp->b_linep;
|
||||
curwp->w_doto = 0;
|
||||
curwp->w_flag |= WFHARD;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Move forward by full lines. If the number of lines to move is less than
|
||||
* zero, call the backward line function to actually do it. The last command
|
||||
* controls how the goal column is set. Bound to "C-N". No errors are
|
||||
* possible.
|
||||
*/
|
||||
int forwline(int f, int n)
|
||||
{
|
||||
struct line *dlp;
|
||||
|
||||
if (n < 0)
|
||||
return backline(f, -n);
|
||||
|
||||
/* if we are on the last line as we start....fail the command */
|
||||
if (curwp->w_dotp == curbp->b_linep)
|
||||
return FALSE;
|
||||
|
||||
/* if the last command was not note a line move,
|
||||
reset the goal column */
|
||||
if ((lastflag & CFCPCN) == 0)
|
||||
curgoal = getccol(FALSE);
|
||||
|
||||
/* flag this command as a line move */
|
||||
thisflag |= CFCPCN;
|
||||
|
||||
/* and move the point down */
|
||||
dlp = curwp->w_dotp;
|
||||
while (n-- && dlp != curbp->b_linep)
|
||||
dlp = lforw(dlp);
|
||||
|
||||
/* reseting the current position */
|
||||
curwp->w_dotp = dlp;
|
||||
curwp->w_doto = getgoal(dlp);
|
||||
curwp->w_flag |= WFMOVE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function is like "forwline", but goes backwards. The scheme is exactly
|
||||
* the same. Check for arguments that are less than zero and call your
|
||||
* alternate. Figure out the new line and call "movedot" to perform the
|
||||
* motion. No errors are possible. Bound to "C-P".
|
||||
*/
|
||||
int backline(int f, int n)
|
||||
{
|
||||
struct line *dlp;
|
||||
|
||||
if (n < 0)
|
||||
return forwline(f, -n);
|
||||
|
||||
/* if we are on the last line as we start....fail the command */
|
||||
if (lback(curwp->w_dotp) == curbp->b_linep)
|
||||
return FALSE;
|
||||
|
||||
/* if the last command was not note a line move,
|
||||
reset the goal column */
|
||||
if ((lastflag & CFCPCN) == 0)
|
||||
curgoal = getccol(FALSE);
|
||||
|
||||
/* flag this command as a line move */
|
||||
thisflag |= CFCPCN;
|
||||
|
||||
/* and move the point up */
|
||||
dlp = curwp->w_dotp;
|
||||
while (n-- && lback(dlp) != curbp->b_linep)
|
||||
dlp = lback(dlp);
|
||||
|
||||
/* reseting the current position */
|
||||
curwp->w_dotp = dlp;
|
||||
curwp->w_doto = getgoal(dlp);
|
||||
curwp->w_flag |= WFMOVE;
|
||||
return TRUE;
|
||||
return (n == 1) ? TRUE : forwline( f, n - 1) ;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -229,20 +222,20 @@ int backline(int f, int n)
|
||||
* the overlap; this value is the default overlap value in ITS EMACS. Because
|
||||
* this zaps the top line in the display window, we have to do a hard update.
|
||||
*/
|
||||
int forwpage(int f, int n)
|
||||
{
|
||||
struct line *lp;
|
||||
boolean forwpage( int f, int n) {
|
||||
line_p lp ;
|
||||
|
||||
if (f == FALSE) {
|
||||
#if SCROLLCODE
|
||||
if (term.t_scroll != NULL)
|
||||
if (overlap == 0)
|
||||
n = curwp->w_ntrows / 3 * 2;
|
||||
if (term.t_scroll != NULL) /* $scroll == FALSE */
|
||||
if (overlap == 0) /* $overlap == 0 */
|
||||
n = curwp->w_ntrows * 2 / 3 ;
|
||||
else
|
||||
n = curwp->w_ntrows - overlap;
|
||||
else
|
||||
#endif
|
||||
n = curwp->w_ntrows - 2; /* Default scroll. */
|
||||
|
||||
if (n <= 0) /* Forget the overlap. */
|
||||
n = 1; /* If tiny window. */
|
||||
} else if (n < 0)
|
||||
@@ -251,12 +244,19 @@ int forwpage(int f, int n)
|
||||
else /* Convert from pages. */
|
||||
n *= curwp->w_ntrows; /* To lines. */
|
||||
#endif
|
||||
lp = curwp->w_linep;
|
||||
while (n-- && lp != curbp->b_linep)
|
||||
lp = lforw(lp);
|
||||
curwp->w_linep = lp;
|
||||
|
||||
/* lp = curwp->w_linep; */
|
||||
lp = curwp->w_dotp ;
|
||||
while( n && lp != curbp->b_linep) {
|
||||
lp = lforw( lp) ;
|
||||
n -= 1 ;
|
||||
}
|
||||
|
||||
/* curwp->w_linep = lp; */
|
||||
curwp->w_dotp = lp;
|
||||
curwp->w_doto = 0;
|
||||
reposition( TRUE, 0) ;
|
||||
|
||||
#if SCROLLCODE
|
||||
curwp->w_flag |= WFHARD | WFKILLS;
|
||||
#else
|
||||
@@ -271,20 +271,28 @@ int forwpage(int f, int n)
|
||||
* EMACS manual. Bound to "M-V". We do a hard update for exactly the same
|
||||
* reason.
|
||||
*/
|
||||
int backpage(int f, int n)
|
||||
{
|
||||
struct line *lp;
|
||||
boolean backpage( int f, int n) {
|
||||
line_p lp ;
|
||||
|
||||
if (f == FALSE) { /* interactive, default n = 1 supplied */
|
||||
/* in interactive mode, first move dot to top of window */
|
||||
if( curwp->w_dotp != curwp->w_linep) {
|
||||
curwp->w_dotp = curwp->w_linep ;
|
||||
curwp->w_doto = 0 ;
|
||||
/* curwp->w_flag |= WFMOVE ; */
|
||||
return TRUE ;
|
||||
}
|
||||
|
||||
if (f == FALSE) {
|
||||
#if SCROLLCODE
|
||||
if (term.t_scroll != NULL)
|
||||
if (overlap == 0)
|
||||
n = curwp->w_ntrows / 3 * 2;
|
||||
if (term.t_scroll != NULL) /* $scroll != FALSE */
|
||||
if (overlap == 0) /* $overlap == 0 */
|
||||
n = curwp->w_ntrows * 2 / 3 ;
|
||||
else
|
||||
n = curwp->w_ntrows - overlap;
|
||||
else
|
||||
#endif
|
||||
n = curwp->w_ntrows - 2; /* Default scroll. */
|
||||
|
||||
if (n <= 0) /* Don't blow up if the. */
|
||||
n = 1; /* Window is tiny. */
|
||||
} else if (n < 0)
|
||||
@@ -293,12 +301,19 @@ int backpage(int f, int n)
|
||||
else /* Convert from pages. */
|
||||
n *= curwp->w_ntrows; /* To lines. */
|
||||
#endif
|
||||
lp = curwp->w_linep;
|
||||
while (n-- && lback(lp) != curbp->b_linep)
|
||||
lp = lback(lp);
|
||||
curwp->w_linep = lp;
|
||||
|
||||
/* lp = curwp->w_linep; */
|
||||
lp = curwp->w_dotp ;
|
||||
while( n && lback( lp) != curbp->b_linep) {
|
||||
lp = lback( lp) ;
|
||||
n -= 1 ;
|
||||
}
|
||||
|
||||
/* curwp->w_linep = lp; */
|
||||
curwp->w_dotp = lp;
|
||||
curwp->w_doto = 0;
|
||||
reposition( TRUE, (f == FALSE) ? 1 : 0) ;
|
||||
|
||||
#if SCROLLCODE
|
||||
curwp->w_flag |= WFHARD | WFINS;
|
||||
#else
|
||||
@@ -311,8 +326,7 @@ int backpage(int f, int n)
|
||||
* Set the mark in the current window to the value of "." in the window. No
|
||||
* errors are possible. Bound to "M-.".
|
||||
*/
|
||||
int setmark(int f, int n)
|
||||
{
|
||||
boolean setmark( int f, int n) {
|
||||
curwp->w_markp = curwp->w_dotp;
|
||||
curwp->w_marko = curwp->w_doto;
|
||||
mloutstr( "(Mark set)") ;
|
||||
@@ -321,13 +335,12 @@ int setmark(int f, int n)
|
||||
|
||||
/*
|
||||
* Swap the values of "." and "mark" in the current window. This is pretty
|
||||
* easy, bacause all of the hard work gets done by the standard routine
|
||||
* easy, because all of the hard work gets done by the standard routine
|
||||
* that moves the mark about. The only possible error is "no mark". Bound to
|
||||
* "C-X C-X".
|
||||
*/
|
||||
int swapmark(int f, int n)
|
||||
{
|
||||
struct line *odotp;
|
||||
boolean swapmark( int f, int n) {
|
||||
line_p odotp ;
|
||||
int odoto;
|
||||
|
||||
if( curwp->w_markp == NULL) {
|
||||
@@ -344,3 +357,5 @@ int swapmark(int f, int n)
|
||||
curwp->w_flag |= WFMOVE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* end of basic.c */
|
||||
|
Reference in New Issue
Block a user