Improve consistency of tab insertion behaviour while indenting and brace matching.

This commit is contained in:
Renaud 2016-02-25 17:08:27 +08:00
parent 998559464b
commit a42c60045d
2 changed files with 26 additions and 19 deletions

31
line.c
View File

@ -392,24 +392,29 @@ static int linsert_byte(int n, int c)
}
int linsert( int n, unicode_t c) {
char utf8[6];
int bytes, i ;
assert( n > 0) ;
assert( n >= 0) ;
if (curbp->b_mode & MDVIEW) /* don't allow this command if */
return rdonly(); /* we are in read only mode */
bytes = unicode_to_utf8(c, utf8) ;
if (bytes == 1)
return linsert_byte(n, (unsigned char) utf8[0]);
for (i = 0; i < n; i++) {
int j;
for (j = 0; j < bytes; j++) {
unsigned char c = utf8[j];
if (!linsert_byte(1, c))
return FALSE;
if( n > 0) {
char utf8[ 6] ;
int bytes, i ;
bytes = unicode_to_utf8(c, utf8) ;
if (bytes == 1)
return linsert_byte(n, (unsigned char) utf8[0]);
for (i = 0; i < n; i++) {
int j;
for (j = 0; j < bytes; j++) {
unsigned char c = utf8[j];
if (!linsert_byte(1, c))
return FALSE;
}
}
}
return TRUE;
}

View File

@ -661,8 +661,9 @@ int insbrace(int n, int c)
while (getccol(FALSE) > target)
backdel(FALSE, 1);
else { /* on doit en inserer */
while (target - getccol(FALSE) >= 8)
linsert(1, '\t');
while (target - getccol(FALSE) >= tabwidth)
insert_tab( FALSE, 1) ;
linsert(target - getccol(FALSE), ' ');
}
}
@ -681,7 +682,6 @@ int insbrace(int n, int c)
*/
int insbrace(int n, int c)
{
int ch; /* last character before input */
int i;
int target; /* column brace should go after */
@ -691,6 +691,8 @@ int insbrace(int n, int c)
/* scan to see if all space before this is white space */
for (i = curwp->w_doto - 1; i >= 0; --i) {
int ch; /* last character before input */
ch = lgetc(curwp->w_dotp, i);
if (ch != ' ' && ch != '\t')
return linsert(n, c);
@ -698,8 +700,8 @@ int insbrace(int n, int c)
/* delete back first */
target = getccol(FALSE); /* calc where we will delete to */
target -= 1;
target -= target % (tabsize == 0 ? 8 : tabsize);
i = target % tabwidth ;
target -= ( i != 0) ? i : tabwidth ;
while (getccol(FALSE) > target)
backdel(FALSE, 1);
@ -774,7 +776,7 @@ int indent( int f, int n) {
nicol %= tabwidth ; /* # of space to insert */
while( n--)
if( lnewline() == FALSE
|| ( i != 0 && linsert( i, '\t') == FALSE)
|| ( i != 0 && insert_tab( FALSE, i) == FALSE)
|| ( nicol != 0 && linsert( nicol, ' ') == FALSE))
return FALSE ;