From 790c872983dbb96b8be896d1a2778a0e5bbc9b85 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Mon, 26 Mar 2018 16:20:15 -0400 Subject: [PATCH] moved from settings from buffer to config module --- inc/edit.h | 6 +----- lib/buf.c | 9 ++------- lib/config.c | 3 ++- lib/view.c | 2 +- tide.c | 14 ++++---------- 5 files changed, 10 insertions(+), 24 deletions(-) diff --git a/inc/edit.h b/inc/edit.h index 329b9ee..37c2854 100644 --- a/inc/edit.h +++ b/inc/edit.h @@ -46,8 +46,6 @@ typedef struct Log { typedef struct { char* path; /* the path to the open file */ uint64_t modtime; /* modification time of the opened file */ - int charset; /* the character set of the buffer */ - int crlf; /* tracks whether the file uses dos style line endings */ size_t bufsize; /* size of the buffer in runes */ char* bufstart; /* start of the data buffer */ char* bufend; /* end of the data buffer */ @@ -56,8 +54,6 @@ typedef struct { Log* undo; /* undo list */ Log* redo; /* redo list */ bool modified; /* tracks whether the buffer has been modified */ - bool expand_tabs; /* tracks current mode */ - bool copy_indent; /* copy the indent level from the previous line on new lines */ uint transid; /* tracks the last used transaction id for log entries */ void (*errfn)(char*); /* callback for error messages */ } Buf; @@ -222,7 +218,7 @@ typedef struct { int fg, bg; } CPair; extern char TagString[], FontString[]; extern int Palette[16]; extern int WinWidth, WinHeight, LineSpacing, RulerPos, Timeout, TabWidth, ScrollBy, - ClickTime, MaxScanDist, Syntax, CopyIndent, TrimOnSave, ExpandTabs; + ClickTime, MaxScanDist, Syntax, CopyIndent, TrimOnSave, ExpandTabs, DosLineFeed; extern CPair Colors[28]; enum { /* Color Variables */ diff --git a/lib/buf.c b/lib/buf.c index 1de1f3e..9841950 100644 --- a/lib/buf.c +++ b/lib/buf.c @@ -27,13 +27,8 @@ void buf_init(Buf* buf, void (*errfn)(char*)) { buf->bufstart = NULL; buf_logclear(buf); } - /* reset the state to defaults */ buf->modified = false; - buf->expand_tabs = ExpandTabs; - buf->copy_indent = CopyIndent; - buf->charset = BINARY; - buf->crlf = 0; buf->bufsize = 8192; buf->bufstart = (char*)malloc(buf->bufsize); buf->bufend = buf->bufstart + buf->bufsize; @@ -122,7 +117,7 @@ size_t buf_end(Buf* buf) { size_t buf_insert(Buf* buf, bool fmt, size_t off, Rune rune) { bool is_eol = (rune == '\n'); buf->modified = true; - if (fmt && buf->expand_tabs && rune == '\t') { + if (fmt && ExpandTabs && rune == '\t') { size_t tabwidth = TabWidth; size_t n = (tabwidth - ((off - buf_bol(buf, off)) % tabwidth)); log_insert(buf, &(buf->undo), off, off+n); @@ -134,7 +129,7 @@ size_t buf_insert(Buf* buf, bool fmt, size_t off, Rune rune) { off += n; } } - if (fmt && buf->copy_indent && is_eol) { + if (fmt && CopyIndent && is_eol) { size_t beg = buf_bol(buf, off-1), end = beg; for (; end < buf_end(buf) && (' ' == buf_get(buf, end) || '\t' == buf_get(buf, end)); end++); for (; beg < end; beg++) diff --git a/lib/config.c b/lib/config.c index 9cf651e..8cc764e 100644 --- a/lib/config.c +++ b/lib/config.c @@ -30,7 +30,8 @@ int /* Integer config options */ Syntax = ON, CopyIndent = ON, TrimOnSave = ON, - ExpandTabs = ON; + ExpandTabs = ON, + DosLineFeed = OFF; int Palette[16] = { 0xFF1d2021, diff --git a/lib/view.c b/lib/view.c index 3dc6f00..7449a58 100644 --- a/lib/view.c +++ b/lib/view.c @@ -354,7 +354,7 @@ void view_scrollpage(View* view, int move) { void view_indent(View* view, int dir) { Buf* buf = &(view->buffer); - unsigned indoff = (buf->expand_tabs ? TabWidth : 1); + unsigned indoff = (ExpandTabs ? TabWidth : 1); selswap(&(view->selection)); view->selection.beg = buf_bol(buf, view->selection.beg); view->selection.end = buf_eol(buf, view->selection.end); diff --git a/tide.c b/tide.c index 39751c7..3291eab 100644 --- a/tide.c +++ b/tide.c @@ -479,15 +479,11 @@ static void goto_ctag(void) { } static void tabs(void) { - bool enabled = !(win_buf(EDIT)->expand_tabs); - win_buf(EDIT)->expand_tabs = enabled; - win_buf(TAGS)->expand_tabs = enabled; + ExpandTabs = !ExpandTabs; } static void indent(void) { - bool enabled = !(win_buf(EDIT)->copy_indent); - win_buf(EDIT)->copy_indent = enabled; - win_buf(TAGS)->copy_indent = enabled; + CopyIndent = !CopyIndent; } static void del_indent(void) { @@ -499,10 +495,8 @@ static void add_indent(void) { } static void eol_mode(void) { - int crlf = win_buf(EDIT)->crlf; - win_buf(EDIT)->crlf = !crlf; - win_buf(TAGS)->crlf = !crlf; - cmd_exec(crlf ? CMD_TO_UNIX : CMD_TO_DOS); + DosLineFeed = !DosLineFeed; + cmd_exec(DosLineFeed ? CMD_TO_DOS : CMD_TO_UNIX); } static void new_win(void) { -- 2.54.0