mirror of https://github.com/rfivet/uemacs.git
Improve consistency of tab insertion behaviour while indenting and brace matching.
This commit is contained in:
parent
998559464b
commit
a42c60045d
31
line.c
31
line.c
|
@ -392,24 +392,29 @@ static int linsert_byte(int n, int c)
|
||||||
}
|
}
|
||||||
|
|
||||||
int linsert( int n, unicode_t c) {
|
int linsert( int n, unicode_t c) {
|
||||||
char utf8[6];
|
assert( n >= 0) ;
|
||||||
int bytes, i ;
|
|
||||||
|
|
||||||
assert( n > 0) ;
|
|
||||||
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 */
|
||||||
|
|
||||||
bytes = unicode_to_utf8(c, utf8) ;
|
if( n > 0) {
|
||||||
if (bytes == 1)
|
char utf8[ 6] ;
|
||||||
return linsert_byte(n, (unsigned char) utf8[0]);
|
int bytes, i ;
|
||||||
for (i = 0; i < n; i++) {
|
|
||||||
int j;
|
bytes = unicode_to_utf8(c, utf8) ;
|
||||||
for (j = 0; j < bytes; j++) {
|
if (bytes == 1)
|
||||||
unsigned char c = utf8[j];
|
return linsert_byte(n, (unsigned char) utf8[0]);
|
||||||
if (!linsert_byte(1, c))
|
|
||||||
return FALSE;
|
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;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
14
random.c
14
random.c
|
@ -661,8 +661,9 @@ int insbrace(int n, int c)
|
||||||
while (getccol(FALSE) > target)
|
while (getccol(FALSE) > target)
|
||||||
backdel(FALSE, 1);
|
backdel(FALSE, 1);
|
||||||
else { /* on doit en inserer */
|
else { /* on doit en inserer */
|
||||||
while (target - getccol(FALSE) >= 8)
|
while (target - getccol(FALSE) >= tabwidth)
|
||||||
linsert(1, '\t');
|
insert_tab( FALSE, 1) ;
|
||||||
|
|
||||||
linsert(target - getccol(FALSE), ' ');
|
linsert(target - getccol(FALSE), ' ');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -681,7 +682,6 @@ int insbrace(int n, int c)
|
||||||
*/
|
*/
|
||||||
int insbrace(int n, int c)
|
int insbrace(int n, int c)
|
||||||
{
|
{
|
||||||
int ch; /* last character before input */
|
|
||||||
int i;
|
int i;
|
||||||
int target; /* column brace should go after */
|
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 */
|
/* scan to see if all space before this is white space */
|
||||||
for (i = curwp->w_doto - 1; i >= 0; --i) {
|
for (i = curwp->w_doto - 1; i >= 0; --i) {
|
||||||
|
int ch; /* last character before input */
|
||||||
|
|
||||||
ch = lgetc(curwp->w_dotp, i);
|
ch = lgetc(curwp->w_dotp, i);
|
||||||
if (ch != ' ' && ch != '\t')
|
if (ch != ' ' && ch != '\t')
|
||||||
return linsert(n, c);
|
return linsert(n, c);
|
||||||
|
@ -698,8 +700,8 @@ int insbrace(int n, int c)
|
||||||
|
|
||||||
/* delete back first */
|
/* delete back first */
|
||||||
target = getccol(FALSE); /* calc where we will delete to */
|
target = getccol(FALSE); /* calc where we will delete to */
|
||||||
target -= 1;
|
i = target % tabwidth ;
|
||||||
target -= target % (tabsize == 0 ? 8 : tabsize);
|
target -= ( i != 0) ? i : tabwidth ;
|
||||||
while (getccol(FALSE) > target)
|
while (getccol(FALSE) > target)
|
||||||
backdel(FALSE, 1);
|
backdel(FALSE, 1);
|
||||||
|
|
||||||
|
@ -774,7 +776,7 @@ int indent( int f, int n) {
|
||||||
nicol %= tabwidth ; /* # of space to insert */
|
nicol %= tabwidth ; /* # of space to insert */
|
||||||
while( n--)
|
while( n--)
|
||||||
if( lnewline() == FALSE
|
if( lnewline() == FALSE
|
||||||
|| ( i != 0 && linsert( i, '\t') == FALSE)
|
|| ( i != 0 && insert_tab( FALSE, i) == FALSE)
|
||||||
|| ( nicol != 0 && linsert( nicol, ' ') == FALSE))
|
|| ( nicol != 0 && linsert( nicol, ' ') == FALSE))
|
||||||
return FALSE ;
|
return FALSE ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue