]> git.mdlowis.com Git - projs/tide.git/commitdiff
Presence of tabs in the opened file turns of expand_tabs. This should do the right...
authorMichael D. Lowis <mike@mdlowis.com>
Sun, 1 Jan 2017 04:22:21 +0000 (23:22 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Sun, 1 Jan 2017 04:22:21 +0000 (23:22 -0500)
TODO.md
inc/edit.h
libedit/buf.c
libedit/charset.c

diff --git a/TODO.md b/TODO.md
index f277b74a9d8711778152b071c491007de22df364..06b3278ea93e9878f7d1e4bce7f06e9eac2f8aa9 100644 (file)
--- a/TODO.md
+++ b/TODO.md
@@ -18,7 +18,6 @@ The Rest:
 * 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
index 60553bbedb4a333dc67dee82ae0cad89d0efd9a7..6fd6517d02ca7f412ea24009cf44f7c454dd1496 100644 (file)
@@ -102,7 +102,7 @@ enum {
     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);
index 56fb288e3c71a049027c5d5948434e82d9970d8d..e36d375f69aab121b5e4711600bfc333b2783319 100644 (file)
@@ -200,7 +200,7 @@ unsigned buf_load(Buf* buf, char* path) {
     
     /* load the file and determine the character set */
     FMap file = mmap_readonly(buf->path);
-    buf->charset = (file.buf ? charset(file.buf, file.len, &buf->crlf) : UTF_8);
+    filetype(buf, file);
     if (buf->charset > UTF_8)
         die("Unsupported character set");
     
@@ -218,8 +218,7 @@ unsigned buf_load(Buf* buf, char* path) {
     
     /* reset buffer state */
     buf->modified = false;
-    free(buf->undo);
-    buf->undo = NULL;
+    buf_logclear(buf);
     return off;
 }
 
index dad2208d4a07a9642993ddd2fbf6c50c9b7d4258..173d12012be7e717e8714d76d54968a89ba7411f 100644 (file)
@@ -25,24 +25,26 @@ static const char Utf8Valid[256] = {
     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);
 }