1
0
mirror of https://github.com/rfivet/uemacs.git synced 2025-11-23 11:41:15 -05:00

Start doing character removal properly

This makes actual basic editing work.  Including things like
justify-paragraph etc, so lines get justified by number of UTF8
characters rather than bytes.

There are probably tons of broken stuff left, but this actually seems to
get the basics working right.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Linus Torvalds
2012-07-11 10:43:16 -07:00
parent 0e9fc2be15
commit 0a8b429059
6 changed files with 48 additions and 16 deletions

28
line.c
View File

@@ -268,7 +268,7 @@ int lowrite(int c)
if (curwp->w_doto < curwp->w_dotp->l_used &&
(lgetc(curwp->w_dotp, curwp->w_doto) != '\t' ||
((curwp->w_doto) & tabmask) == tabmask))
ldelete(1L, FALSE);
ldelchar(1, FALSE);
return linsert(1, c);
}
@@ -357,6 +357,30 @@ int lnewline(void)
return TRUE;
}
int lgetchar(unicode_t *c)
{
int len = llength(curwp->w_dotp);
char *buf = curwp->w_dotp->l_text;
return utf8_to_unicode(buf, curwp->w_doto, len, c);
}
/*
* ldelete() really fundamentally works on bytes, not characters.
* It is used for things like "scan 5 words forwards, and remove
* the bytes we scanned".
*
* If you want to delete characters, use ldelchar().
*/
int ldelchar(long n, int kflag)
{
while (n-- > 0) {
unicode_t c;
if (!ldelete(lgetchar(&c), kflag))
return FALSE;
}
return TRUE;
}
/*
* This function deletes "n" bytes, starting at dot. It understands how do deal
* with end of lines, etc. It returns TRUE if all of the characters were
@@ -655,7 +679,7 @@ int yank(int f, int n)
if (lnewline() == FALSE)
return FALSE;
} else {
if (linsert(1, c) == FALSE)
if (linsert_byte(1, c) == FALSE)
return FALSE;
}
}