Remove tab width constraints, was [2, 4, 8], now [1...

This commit is contained in:
Renaud 2016-02-24 13:22:54 +08:00
parent 3e27fcf19e
commit c390cf2a3e
7 changed files with 77 additions and 62 deletions

View File

@ -51,13 +51,14 @@ static unsigned getgoal( struct line *dlp) {
/* Take tabs, ^X and \xx hex characters into account */ /* Take tabs, ^X and \xx hex characters into account */
if( c == '\t') if( c == '\t')
col |= tabmask ; col += tabwidth - col % tabwidth ;
else if( c < 0x20 || c == 0x7F) else if( c < 0x20 || c == 0x7F)
col += 1 ;
else if( c >= 0x80 && c <= 0xA0)
col += 2 ; col += 2 ;
else if( c >= 0x80 && c <= 0xA0)
col += 3 ;
else
col += 1 ;
col += 1 ;
if( col > curgoal) if( col > curgoal)
break ; break ;

View File

@ -210,8 +210,9 @@ static void vtputc(int c)
if (c == '\t') { if (c == '\t') {
do { do {
vtputc(' '); vtputc(' ');
} while (((vtcol + taboff) & tabmask) != 0); } while( ((vtcol + taboff) % tabwidth) != 0) ;
return;
return ;
} }
if (c < 0x20) { if (c < 0x20) {
@ -580,13 +581,13 @@ void updpos(void)
i += utf8_to_unicode( lp->l_text, i, curwp->w_doto, &c) ; i += utf8_to_unicode( lp->l_text, i, curwp->w_doto, &c) ;
if( c == '\t') if( c == '\t')
curcol |= tabmask ; curcol += tabwidth - curcol % tabwidth ;
else if( c < 0x20 || c == 0x7F) else if( c < 0x20 || c == 0x7F)
curcol += 1 ; /* displayed as ^c */ curcol += 2 ; /* displayed as ^c */
else if( c >= 0x80 && c <= 0xA0) else if( c >= 0x80 && c <= 0xA0)
curcol += 2 ; /* displayed as \xx */ curcol += 3 ; /* displayed as \xx */
else
++curcol; curcol += 1 ;
} }
/* if extended, flag so and update the virtual line image */ /* if extended, flag so and update the virtual line image */

13
eval.c
View File

@ -734,7 +734,7 @@ static char *gtenv( char *vname) {
case EVRVAL: case EVRVAL:
return i_to_a(rval); return i_to_a(rval);
case EVTAB: case EVTAB:
return i_to_a(tabmask + 1); return i_to_a( tabwidth) ;
case EVOVERLAP: case EVOVERLAP:
return i_to_a(overlap); return i_to_a(overlap);
case EVSCROLLCOUNT: case EVSCROLLCOUNT:
@ -1049,10 +1049,13 @@ static int svar(struct variable_description *var, char *value)
case EVRVAL: case EVRVAL:
break; break;
case EVTAB: case EVTAB:
tabmask = atoi(value) - 1; c = atoi( value) ;
if( tabmask != 0x07 && tabmask != 0x03 && tabmask != 1) if( c > 0) {
tabmask = 0x07; tabwidth = c ;
curwp->w_flag |= WFHARD; curwp->w_flag |= WFHARD;
} else
status = FALSE ;
break; break;
case EVOVERLAP: case EVOVERLAP:
overlap = atoi(value); overlap = atoi(value);

View File

@ -70,7 +70,7 @@ int execute(int c, int f, int n)
if (curwp->w_bufp->b_mode & MDOVER && if (curwp->w_bufp->b_mode & MDOVER &&
curwp->w_doto < curwp->w_dotp->l_used && curwp->w_doto < curwp->w_dotp->l_used &&
(lgetc(curwp->w_dotp, curwp->w_doto) != '\t' || (lgetc(curwp->w_dotp, curwp->w_doto) != '\t' ||
((curwp->w_doto) & tabmask) == tabmask)) ((curwp->w_doto) % tabwidth) == (tabwidth - 1)))
ldelchar(1, FALSE); ldelchar(1, FALSE);
/* do the appropriate insertion */ /* do the appropriate insertion */

18
line.c
View File

@ -26,7 +26,7 @@
#include "window.h" #include "window.h"
int tabmask = 0x07 ; /* tabulator mask */ int tabwidth = 8 ; /* column span of a tab */
#define BLOCK_SIZE 16 /* Line block chunk size. */ #define BLOCK_SIZE 16 /* Line block chunk size. */
@ -418,13 +418,15 @@ int linsert( int n, unicode_t c) {
* *
* int c; character to overwrite on current position * int c; character to overwrite on current position
*/ */
static int lowrite(int c) static int lowrite( int c) {
{ if( curwp->w_doto < curwp->w_dotp->l_used
if (curwp->w_doto < curwp->w_dotp->l_used && && (
(lgetc(curwp->w_dotp, curwp->w_doto) != '\t' || lgetc(curwp->w_dotp, curwp->w_doto) != '\t' ||
((curwp->w_doto) & tabmask) == tabmask)) ((curwp->w_doto) % tabwidth) == (tabwidth - 1)
ldelchar(1, FALSE); ))
return linsert(1, c); ldelchar( 1, FALSE) ;
return linsert( 1, c) ;
} }
/* /*

2
line.h
View File

@ -28,7 +28,7 @@ struct line {
#define lputc(lp, n, c) ((lp)->l_text[(n)]=(c)) #define lputc(lp, n, c) ((lp)->l_text[(n)]=(c))
#define llength(lp) ((lp)->l_used) #define llength(lp) ((lp)->l_used)
extern int tabmask ; extern int tabwidth ;
char *getkill( void) ; char *getkill( void) ;

View File

@ -179,12 +179,13 @@ int getccol(int bflg)
if( bflg && c != ' ' && c != '\t') /* Request Stop at first non-blank */ if( bflg && c != ' ' && c != '\t') /* Request Stop at first non-blank */
break; break;
if (c == '\t') if (c == '\t')
col |= tabmask; col += tabwidth - col % tabwidth ;
else if (c < 0x20 || c == 0x7F) /* displayed as ^c */ else if (c < 0x20 || c == 0x7F) /* displayed as ^c */
++col; col += 2 ;
else if (c >= 0x80 && c <= 0xa0) /* displayed as \xx */ else if (c >= 0x80 && c <= 0xa0) /* displayed as \xx */
col += 2; col += 3 ;
++col; else
col += 1 ;
} }
return col; return col;
} }
@ -213,10 +214,11 @@ int setccol(int pos)
/* advance one character */ /* advance one character */
c = lgetc(curwp->w_dotp, i); c = lgetc(curwp->w_dotp, i);
if (c == '\t') if (c == '\t')
col |= tabmask; col += tabwidth - col % tabwidth ;
else if (c < 0x20 || c == 0x7F) else if (c < 0x20 || c == 0x7F)
++col; col += 2 ;
++col; else
col += 1 ;
} }
/* set us at the new position */ /* set us at the new position */
@ -329,10 +331,9 @@ int detab(int f, int n)
/* if we have a tab */ /* if we have a tab */
if (lgetc(curwp->w_dotp, curwp->w_doto) == '\t') { if (lgetc(curwp->w_dotp, curwp->w_doto) == '\t') {
ldelchar(1, FALSE); ldelchar(1, FALSE);
insspace(TRUE, insspace( TRUE, tabwidth - curwp->w_doto % tabwidth);
(tabmask + 1) -
(curwp->w_doto & tabmask));
} }
forwchar(FALSE, 1); forwchar(FALSE, 1);
} }
@ -353,7 +354,7 @@ int detab(int f, int n)
*/ */
int entab(int f, int n) int entab(int f, int n)
{ {
#define nextab(a) (a & ~tabmask) + (tabmask+1) #define nextab(a) (a + tabwidth - a % tabwidth)
int inc; /* increment to next line [sgn(n)] */ int inc; /* increment to next line [sgn(n)] */
int fspace; /* pointer to first space if in a run */ int fspace; /* pointer to first space if in a run */
@ -759,38 +760,45 @@ int deblank(int f, int n)
/* /*
* 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 simple. * of the previous line. Assumes tabs are every tabwidth characters.
* Figure out the indentation of the current line. Insert a newline by calling * Figure out the indentation of the current line. Insert a newline by calling
* the standard routine. Insert the indentation by inserting the right number * the standard routine. Insert the indentation by inserting the right number
* of tabs and spaces. Return TRUE if all ok. Return FALSE if one of the * of tabs and spaces. Return TRUE if all ok. Return FALSE if one of the
* subcomands failed. Normally bound to "C-J". * subcomands failed. Normally bound to "C-J".
*/ */
int indent(int f, int n) int indent( int f, int n) {
{ int nicol ;
int nicol; int i ;
int c;
int i;
if (curbp->b_mode & MDVIEW) /* don't allow this command if */ if( curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly(); /* we are in read only mode */ return rdonly() ; /* we are in read only mode */
if (n < 0)
return FALSE; if( n < 0)
while (n--) { return FALSE ;
nicol = 0;
for (i = 0; i < llength(curwp->w_dotp); ++i) { /* number of columns to indent */
c = lgetc(curwp->w_dotp, i); nicol = 0 ;
if (c != ' ' && c != '\t') for( i = 0 ; i < llength( curwp->w_dotp) ; i += 1) {
break; int c ;
if (c == '\t')
nicol |= tabmask; c = lgetc( curwp->w_dotp, i) ;
++nicol; if( c == '\t')
} nicol += tabwidth - nicol % tabwidth ;
if (lnewline() == FALSE else if( c == ' ')
|| ((i = nicol / 8) != 0 && linsert(i, '\t') == FALSE) nicol += 1 ;
|| ((i = nicol % 8) != 0 && linsert(i, ' ') == FALSE)) else
return FALSE; break ;
} }
return TRUE;
i = nicol / tabwidth ; /* # of tab to insert */
nicol %= tabwidth ; /* # of space to insert */
while( n--)
if( lnewline() == FALSE
|| ( i != 0 && linsert( i, '\t') == FALSE)
|| ( nicol != 0 && linsert( nicol, ' ') == FALSE))
return FALSE ;
return TRUE ;
} }
/* /*