1
0
mirror of https://github.com/rfivet/uemacs.git synced 2024-06-09 05:20:42 +00: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

2
eval.c
View File

@ -588,7 +588,7 @@ int svar(struct variable_description *var, char *value)
lastkey = atoi(value); lastkey = atoi(value);
break; break;
case EVCURCHAR: case EVCURCHAR:
ldelete(1L, FALSE); /* delete 1 char */ ldelchar(1, FALSE); /* delete 1 char */
c = atoi(value); c = atoi(value);
if (c == '\n') if (c == '\n')
lnewline(); lnewline();

28
line.c
View File

@ -268,7 +268,7 @@ 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) & tabmask) == tabmask))
ldelete(1L, FALSE); ldelchar(1, FALSE);
return linsert(1, c); return linsert(1, c);
} }
@ -357,6 +357,30 @@ int lnewline(void)
return TRUE; 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 * 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 * 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) if (lnewline() == FALSE)
return FALSE; return FALSE;
} else { } else {
if (linsert(1, c) == FALSE) if (linsert_byte(1, c) == FALSE)
return FALSE; return FALSE;
} }
} }

4
line.h
View File

@ -1,6 +1,8 @@
#ifndef LINE_H_ #ifndef LINE_H_
#define LINE_H_ #define LINE_H_
#include "utf8.h"
/* /*
* All text is kept in circularly linked lists of "struct line" structures. These * All text is kept in circularly linked lists of "struct line" structures. These
* begin at the header line (which is the blank line beyond the end of the * begin at the header line (which is the blank line beyond the end of the
@ -32,6 +34,8 @@ extern int lowrite(int c);
extern int lover(char *ostr); extern int lover(char *ostr);
extern int lnewline(void); extern int lnewline(void);
extern int ldelete(long n, int kflag); extern int ldelete(long n, int kflag);
extern int ldelchar(long n, int kflag);
extern int lgetchar(unicode_t *);
extern char *getctext(void); extern char *getctext(void);
extern int putctext(char *iline); extern int putctext(char *iline);
extern int ldelnewline(void); extern int ldelnewline(void);

2
main.c
View File

@ -521,7 +521,7 @@ int execute(int c, int f, int n)
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) % 8 == 7)) (curwp->w_doto) % 8 == 7))
ldelete(1L, FALSE); ldelchar(1, FALSE);
/* do the appropriate insertion */ /* do the appropriate insertion */
if (c == '}' && (curbp->b_mode & MDCMOD) != 0) if (c == '}' && (curbp->b_mode & MDCMOD) != 0)

View File

@ -278,7 +278,7 @@ int detab(int f, int n)
while (curwp->w_doto < llength(curwp->w_dotp)) { while (curwp->w_doto < llength(curwp->w_dotp)) {
/* 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') {
ldelete(1L, FALSE); ldelchar(1, FALSE);
insspace(TRUE, insspace(TRUE,
(tabmask + 1) - (tabmask + 1) -
(curwp->w_doto & tabmask)); (curwp->w_doto & tabmask));
@ -758,7 +758,7 @@ int forwdel(int f, int n)
kdelete(); kdelete();
thisflag |= CFKILL; thisflag |= CFKILL;
} }
return ldelete((long) n, f); return ldelchar((long) n, f);
} }
/* /*
@ -781,7 +781,7 @@ int backdel(int f, int n)
thisflag |= CFKILL; thisflag |= CFKILL;
} }
if ((s = backchar(f, n)) == TRUE) if ((s = backchar(f, n)) == TRUE)
s = ldelete((long) n, f); s = ldelchar(n, f);
return s; return s;
} }

22
word.c
View File

@ -363,7 +363,7 @@ int delbword(int f, int n)
} }
if (forwchar(FALSE, 1) == FALSE) if (forwchar(FALSE, 1) == FALSE)
return FALSE; return FALSE;
bckdel:return ldelete(size, TRUE); bckdel:return ldelchar(size, TRUE);
} }
/* /*
@ -399,7 +399,8 @@ int inword(void)
*/ */
int fillpara(int f, int n) int fillpara(int f, int n)
{ {
int c; /* current char durring scan */ unicode_t c; /* current char during scan */
unicode_t wbuf[NSTRING];/* buffer for current word */
int wordlen; /* length of current word */ int wordlen; /* length of current word */
int clength; /* position on line during fill */ int clength; /* position on line during fill */
int i; /* index during word copy */ int i; /* index during word copy */
@ -408,7 +409,6 @@ int fillpara(int f, int n)
int firstflag; /* first word? (needs no space) */ int firstflag; /* first word? (needs no space) */
struct line *eopline; /* pointer to line just past EOP */ struct line *eopline; /* pointer to line just past EOP */
int dotflag; /* was the last char a period? */ int dotflag; /* was the last char a period? */
char wbuf[NSTRING]; /* buffer for current word */
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 */
@ -438,16 +438,18 @@ int fillpara(int f, int n)
firstflag = TRUE; firstflag = TRUE;
eopflag = FALSE; eopflag = FALSE;
while (!eopflag) { while (!eopflag) {
int bytes = 1;
/* get the next character in the paragraph */ /* get the next character in the paragraph */
if (curwp->w_doto == llength(curwp->w_dotp)) { if (curwp->w_doto == llength(curwp->w_dotp)) {
c = ' '; c = ' ';
if (lforw(curwp->w_dotp) == eopline) if (lforw(curwp->w_dotp) == eopline)
eopflag = TRUE; eopflag = TRUE;
} else } else
c = lgetc(curwp->w_dotp, curwp->w_doto); bytes = lgetchar(&c);
/* and then delete it */ /* and then delete it */
ldelete(1L, FALSE); ldelete(bytes, FALSE);
/* if not a separator, just add it in */ /* if not a separator, just add it in */
if (c != ' ' && c != '\t') { if (c != ' ' && c != '\t') {
@ -496,7 +498,8 @@ int fillpara(int f, int n)
*/ */
int justpara(int f, int n) int justpara(int f, int n)
{ {
int c; /* current char durring scan */ unicode_t c; /* current char durring scan */
unicode_t wbuf[NSTRING];/* buffer for current word */
int wordlen; /* length of current word */ int wordlen; /* length of current word */
int clength; /* position on line during fill */ int clength; /* position on line during fill */
int i; /* index during word copy */ int i; /* index during word copy */
@ -504,7 +507,6 @@ int justpara(int f, int n)
int eopflag; /* Are we at the End-Of-Paragraph? */ int eopflag; /* Are we at the End-Of-Paragraph? */
int firstflag; /* first word? (needs no space) */ int firstflag; /* first word? (needs no space) */
struct line *eopline; /* pointer to line just past EOP */ struct line *eopline; /* pointer to line just past EOP */
char wbuf[NSTRING]; /* buffer for current word */
int leftmarg; /* left marginal */ int leftmarg; /* left marginal */
if (curbp->b_mode & MDVIEW) /* don't allow this command if */ if (curbp->b_mode & MDVIEW) /* don't allow this command if */
@ -542,16 +544,18 @@ int justpara(int f, int n)
firstflag = TRUE; firstflag = TRUE;
eopflag = FALSE; eopflag = FALSE;
while (!eopflag) { while (!eopflag) {
int bytes = 1;
/* get the next character in the paragraph */ /* get the next character in the paragraph */
if (curwp->w_doto == llength(curwp->w_dotp)) { if (curwp->w_doto == llength(curwp->w_dotp)) {
c = ' '; c = ' ';
if (lforw(curwp->w_dotp) == eopline) if (lforw(curwp->w_dotp) == eopline)
eopflag = TRUE; eopflag = TRUE;
} else } else
c = lgetc(curwp->w_dotp, curwp->w_doto); bytes = lgetchar(&c);
/* and then delete it */ /* and then delete it */
ldelete(1L, FALSE); ldelete(bytes, FALSE);
/* if not a separator, just add it in */ /* if not a separator, just add it in */
if (c != ' ' && c != '\t') { if (c != ' ' && c != '\t') {