RUNE_ERR = 0xFFFD, /* rune value representing an error */
RUNE_MAX = 0x10FFFF, /* Maximum decodable rune value */
RUNE_EOF = -1, /* rune value representing end of file */
- RUNE_CRLF = -2, /* rune value representing a \r\n sequence */
};
/* Represents a unicode code point */
if (buf->path) {
FMap file = mmap_readwrite(buf->path, buf_end(buf) * UTF_MAX);
if (file.buf) {
- for (size_t i = 0, end = buf_end(buf); i < end; i++) {
- Rune r = buf_get(buf, i);
- if (r == RUNE_CRLF) {
- file.buf[wrlen++] = '\r';
- file.buf[wrlen++] = '\n';
- } else if (buf->charset == BINARY) {
- file.buf[wrlen++] = (char)r;
- } else {
- wrlen += utf8encode((char*)&(file.buf[wrlen]), r);
- }
- }
+ for (size_t i = 0, end = buf_end(buf); i < end; i++)
+ file.buf[wrlen++] = buf_get(buf, i);
mmap_close(file);
truncate(buf->path, wrlen);
buf->modified = false;
}
size_t buf_insert(Buf* buf, bool fmt, size_t off, Rune rune) {
- bool is_eol = (rune == '\n' || rune == RUNE_CRLF);
+ bool is_eol = (rune == '\n');
buf->modified = true;
if (fmt && buf->expand_tabs && rune == '\t') {
size_t tabwidth = TabWidth;
size_t end = buf_end(buf);
if (!end) return;
Rune r = buf_get(buf, end-1);
- if (r == RUNE_CRLF || r == '\n') {
+ if (r == '\n') {
delete(buf, end-1);
if (buf->undo->insert && buf->undo->data.ins.end == end)
buf->undo->data.ins.end--;
bool buf_iseol(Buf* buf, size_t off) {
Rune r = buf_get(buf, off);
- return (r == '\n' || r == RUNE_CRLF);
+ return (r == '\n');
}
size_t buf_bol(Buf* buf, size_t off) {
}
static size_t insert(Buf* buf, size_t off, Rune rune) {
- size_t rcount = 1;
syncgap(buf, off);
- if (buf->crlf && rune == '\n' && buf_get(buf, off-1) == '\r') {
- rcount = 0;
- *(buf->gapstart-1) = RUNE_CRLF;
- } else if (buf->crlf && rune == '\n') {
- *(buf->gapstart++) = RUNE_CRLF;
- } else {
- *(buf->gapstart++) = rune;
- }
- return rcount;
+ *(buf->gapstart++) = rune;
+ return 1;
}
static int rune_match(Buf* buf, size_t mbeg, size_t mend, Rune* runes) {
}
bool risblank(Rune r) {
- return (r == ' ' || r == '\t' || r == '\n' || r == '\r' || r == RUNE_CRLF);
+ return (r == ' ' || r == '\t' || r == '\n' || r == '\r');
}
bool risbigword(Rune r) {
while (nrows < maxrows && pos < buf_end(&(view->buffer))) {
Rune r = buf_get(&(view->buffer), pos++);
col += runewidth(col, r);
- if (col >= ncols || r == RUNE_CRLF || r == '\n')
+ if (col >= ncols || r == '\n')
col = 0, nrows++;
}
return nrows;
char* str = NULL;
for (; sel.beg < sel.end; sel.beg++) {
Rune rune = buf_get(buf, sel.beg);
- if (rune == RUNE_CRLF) {
- str = realloc(str, len + 2);
- str[len + 0] = '\r';
- str[len + 1] = '\n';
- len += 2;
- } else {
- size_t n = utf8encode(utf, rune);
- str = realloc(str, len + n);
- memcpy(str+len, utf, n);
- len += n;
- }
+ size_t n = utf8encode(utf, rune);
+ str = realloc(str, len + n);
+ memcpy(str+len, utf, n);
+ len += n;
}
if (str) {
str = realloc(str, len+1);
buf_getblock(buf, '[', ']', sel);
} else if (r == '{' || r == '}') {
buf_getblock(buf, '{', '}', sel);
- } else if (sel->end == bol || r == '\n' || r == RUNE_CRLF) {
+ } else if (sel->end == bol || r == '\n') {
sel->beg = bol;
sel->end = buf_eol(buf, sel->end);
} else if (risword(r)) {
int ncols = runewidth(col, r);
/* write the rune to the screen buf */
scrrow->cols[col].attr = attr;
- if (r == RUNE_CRLF)
- scrrow->cols[col].rune = '\n';
- else if (r == '\t')
+ if (r == '\t')
scrrow->cols[col].rune = ' ';
else
scrrow->cols[col].rune = r;
}
}
- /* translate to crlf if needed */
- if (key == '\n' && win_view(FOCUSED)->buffer.crlf)
- key = RUNE_CRLF;
-
/* fallback to just inserting the rune if it doesn't fall in the private use area.
* the private use area is used to encode special keys */
if (key < 0xE000 || key > 0xF8FF) {
Rune r = view_getrune(view);
for (; r == '\t' || r == ' '; r = view_getrune(view))
view_byrune(view, RIGHT, true);
- if (r != '\n' && r != RUNE_CRLF)
+ if (r != '\n')
view_insert(view, false, ' ');
}