From 2b877871a3d3a26afa643cec06aa85de8b0e422c Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Mon, 5 Dec 2016 09:46:47 -0500 Subject: [PATCH] Added tags for toggling copyindent and expand tabs --- TODO.md | 2 -- xedit.c | 36 +++++++++++++++++++++++++++--------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/TODO.md b/TODO.md index 45b4a3f..771e971 100644 --- a/TODO.md +++ b/TODO.md @@ -1,7 +1,5 @@ # Implementation Tweaks and Bug Fixes -* add tag for toggling expand tabs -* add tag for toggling auto indent * Expand tabs setting should be disabled if opened file contains tabs * Add tag for ctags lookup and line number jump * add a shortcut to autocomplete ctag diff --git a/xedit.c b/xedit.c index 11edeb4..52cc99f 100644 --- a/xedit.c +++ b/xedit.c @@ -51,6 +51,8 @@ static void find(char* arg); static void open_file(void); static void pick_ctag(void); static void goto_ctag(void); +static void tabs(void); +static void indent(void); // Tag/Cmd Execution static Tag* tag_lookup(char* cmd); @@ -86,15 +88,17 @@ static XConfig Config = { }; Tag Builtins[] = { - { .tag = "Quit", .action.noarg = quit }, - { .tag = "Save", .action.noarg = save }, - { .tag = "Cut", .action.noarg = cut }, - { .tag = "Copy", .action.noarg = copy }, - { .tag = "Paste", .action.noarg = paste }, - { .tag = "Undo", .action.noarg = undo }, - { .tag = "Redo", .action.noarg = redo }, - { .tag = "Find", .action.arg = find }, - { .tag = NULL, .action.noarg = NULL } + { .tag = "Quit", .action.noarg = quit }, + { .tag = "Save", .action.noarg = save }, + { .tag = "Cut", .action.noarg = cut }, + { .tag = "Copy", .action.noarg = copy }, + { .tag = "Paste", .action.noarg = paste }, + { .tag = "Undo", .action.noarg = undo }, + { .tag = "Redo", .action.noarg = redo }, + { .tag = "Find", .action.arg = find }, + { .tag = "Tabs", .action.noarg = tabs }, + { .tag = "Indent", .action.noarg = indent }, + { .tag = NULL, .action.noarg = NULL } }; void (*MouseActs[MOUSE_BTN_COUNT])(enum RegionId id, size_t count, size_t row, size_t col) = { @@ -280,6 +284,8 @@ static void draw_status(int fg, size_t ncols) { UGlyph glyphs[ncols], *status = glyphs; (status++)->rune = (buf->charset == BINARY ? 'B' : 'U'); (status++)->rune = (buf->crlf ? 'C' : 'N'); + (status++)->rune = (buf->expand_tabs ? 'S' : 'T'); + (status++)->rune = (buf->copy_indent ? 'I' : 'i'); (status++)->rune = (buf->modified ? '*' : ' '); (status++)->rune = ' '; char* path = (buf->path ? buf->path : "*scratch*"); @@ -546,6 +552,18 @@ static void goto_ctag(void) { free(str); } +static void tabs(void) { + bool enabled = !(getbuf(EDIT)->expand_tabs); + getbuf(EDIT)->expand_tabs = enabled; + getbuf(TAGS)->expand_tabs = enabled; +} + +static void indent(void) { + bool enabled = !(getbuf(EDIT)->copy_indent); + getbuf(EDIT)->copy_indent = enabled; + getbuf(TAGS)->copy_indent = enabled; +} + /* Tag/Cmd Execution *****************************************************************************/ static Tag* tag_lookup(char* cmd) { -- 2.49.0