* Add a SaveAs tag that takes an argument for the filename to save as
* Add a GoTo tag for ctags lookup and line number jump
* Use select to check for error strings in exec.c
-* Expand tabs setting should be disabled if opened file contains tabs
* Add a tools dir to namespace utility scripts only useful inside the editor
* shift+click to extend selection
* implement command diffing logic to optimize the undo/redo log
UTF_32LE, /* UTF-32 encoding, little-endian */
};
-int charset(const uint8_t* buf, size_t len, int* crlf);
+void filetype(Buf* buf, FMap file);
void utf8load(Buf* buf, FMap file);
void utf8save(Buf* buf, FILE* file);
void binload(Buf* buf, FMap file);
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,
};
-int charset(const uint8_t* buf, size_t len, int* crlf) {
- size_t crs = 0;
- size_t lfs = 0;
+void filetype(Buf* buf, FMap file) {
+ size_t crs = 0, lfs = 0, tabs = 0;
/* look for a BOM and parse it */
for (size_t i = 0; i < (sizeof(BOMS)/sizeof(BOMS[0])); i++)
if (!strncmp((char*)buf, (char*)BOMS[i].seq, BOMS[i].len))
- return BOMS[i].type;
- /* look for bytes that are invalid in utf-8 */
- int type = UTF_8;
- size_t i = 0;
- for (i = 0; i < len; i++) {
- type &= Utf8Valid[(int)buf[i]];
- switch(buf[i]) {
- case '\r': crs++; break;
- case '\n': lfs++; break;
+ buf->charset = BOMS[i].type;
+ /* look for bytes that are invalid in utf-8 and count tabs, carriage
+ returns, and line feeds */
+ int type = buf->charset;
+ for (size_t i = 0; i < file.len; i++) {
+ if (type == UTF_8)
+ type &= Utf8Valid[(int)file.buf[i]];
+ switch(file.buf[i]) {
+ case '\r': crs++; break;
+ case '\n': lfs++; break;
+ case '\t': tabs++; break;
}
}
- /* report back the linefeed mode */
- *crlf = (crs == lfs);
- return type;
+ /* setup filetype attributes in the buffer */
+ buf->crlf = (crs == lfs);
+ buf->charset = type;
+ buf->expand_tabs = (tabs == 0);
}