version 1.24, 2007/02/08 21:40:38 |
version 1.25, 2008/06/11 23:18:33 |
|
|
int |
int |
delwhite(int f, int n) |
delwhite(int f, int n) |
{ |
{ |
int col, c, s; |
int col, s; |
|
|
col = curwp->w_doto; |
col = curwp->w_doto; |
|
|
while (col < llength(curwp->w_dotp) && |
while (col < llength(curwp->w_dotp) && |
((c = lgetc(curwp->w_dotp, col)) == ' ' || c == '\t')) |
(isspace(lgetc(curwp->w_dotp, col)))) |
++col; |
++col; |
do { |
do { |
if (curwp->w_doto == 0) { |
if (curwp->w_doto == 0) { |
|
|
} |
} |
if ((s = backchar(FFRAND, 1)) != TRUE) |
if ((s = backchar(FFRAND, 1)) != TRUE) |
break; |
break; |
} while ((c = lgetc(curwp->w_dotp, curwp->w_doto)) == ' ' || c == '\t'); |
} while (isspace(lgetc(curwp->w_dotp, curwp->w_doto))); |
|
|
if (s == TRUE) |
if (s == TRUE) |
(void)forwchar(FFRAND, 1); |
(void)forwchar(FFRAND, 1); |
|
|
} |
} |
|
|
/* |
/* |
|
* Delete any leading whitespace on the current line |
|
*/ |
|
int |
|
delleadwhite(int f, int n) |
|
{ |
|
int soff, ls; |
|
struct line *slp; |
|
|
|
/* Save current position */ |
|
slp = curwp->w_dotp; |
|
soff = curwp->w_doto; |
|
|
|
for (ls = 0; ls < llength(slp); ls++) |
|
if (!isspace(lgetc(slp, ls))) |
|
break; |
|
gotobol(FFRAND, 1); |
|
forwdel(FFRAND, ls); |
|
soff -= ls; |
|
if (soff < 0) |
|
soff = 0; |
|
forwchar(FFRAND, soff); |
|
|
|
return (TRUE); |
|
} |
|
|
|
/* |
|
* Delete any trailing whitespace on the current line |
|
*/ |
|
int |
|
deltrailwhite(int f, int n) |
|
{ |
|
int soff; |
|
|
|
/* Save current position */ |
|
soff = curwp->w_doto; |
|
|
|
gotoeol(FFRAND, 1); |
|
delwhite(FFRAND, 1); |
|
|
|
/* restore original position, if possible */ |
|
if (soff < curwp->w_doto) |
|
curwp->w_doto = soff; |
|
|
|
return (TRUE); |
|
} |
|
|
|
|
|
|
|
/* |
* Insert a newline, then enough tabs and spaces to duplicate the indentation |
* Insert a newline, then enough tabs and spaces to duplicate the indentation |
* of the previous line. Assumes tabs are every eight characters. Quite |
* of the previous line. Assumes tabs are every eight characters. Quite |
* simple. Figure out the indentation of the current line. Insert a newline |
* simple. Figure out the indentation of the current line. Insert a newline |
|
|
*/ |
*/ |
/* ARGSUSED */ |
/* ARGSUSED */ |
int |
int |
indent(int f, int n) |
lfindent(int f, int n) |
{ |
{ |
int c, i, nicol; |
int c, i, nicol; |
|
|
|
|
} |
} |
return (TRUE); |
return (TRUE); |
} |
} |
|
|
|
/* |
|
* Indent the current line. Delete existing leading whitespace, |
|
* and use tabs/spaces to achieve correct indentation. Try |
|
* to leave dot where it started. |
|
*/ |
|
int |
|
indent(int f, int n) |
|
{ |
|
int soff, i; |
|
|
|
if (n < 0) |
|
return (FALSE); |
|
|
|
delleadwhite(FFRAND, 1); |
|
|
|
/* If not invoked with a numerical argument, done */ |
|
if (!(f & FFARG)) |
|
return (TRUE); |
|
|
|
/* insert appropriate whitespace */ |
|
soff = curwp->w_doto; |
|
(void)gotobol(FFRAND, 1); |
|
if ( |
|
#ifdef NOTAB |
|
curbp->b_flag & BFNOTAB) ? linsert(n, ' ') == FALSE : |
|
#endif /* NOTAB */ |
|
(((i = n / 8) != 0 && linsert(i, '\t') == FALSE) || |
|
((i = n % 8) != 0 && linsert(i, ' ') == FALSE))) |
|
return (FALSE); |
|
|
|
forwchar(FFRAND, soff); |
|
|
|
return (TRUE); |
|
} |
|
|
|
|
/* |
/* |
* Delete forward. This is real easy, because the basic delete routine does |
* Delete forward. This is real easy, because the basic delete routine does |