From 5c1e44840cdf580d730823f8a419bfe5fd5403c9 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Sun, 27 Apr 2014 01:08:11 -0400 Subject: [PATCH] Allow tigrc commands to span multiple lines Lines ending with a backslash will be continued on the next line. --- doc/tigrc.5.adoc | 12 +++++++++--- include/tig/io.h | 1 + src/io.c | 5 +++++ src/options.c | 2 ++ 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/doc/tigrc.5.adoc b/doc/tigrc.5.adoc index 23f8778..cfc8e67 100644 --- a/doc/tigrc.5.adoc +++ b/doc/tigrc.5.adoc @@ -23,7 +23,8 @@ DESCRIPTION You can permanently set an option by putting it in the `~/.tigrc` file. The file consists of a series of 'commands'. Each line of the file may contain -only one command. +only one command. Commands can span multiple lines if each line is +terminated by a backslash ('\') character. The hash mark ('#') is used as a 'comment' character. All text after the comment character to the end of the line is ignored. You can use comments to @@ -91,8 +92,13 @@ set blame-options = -C -C -C # Blame lines from other files # Wrap branch names with () and tags with <> set reference-format = (branch) -# Configure blame view columns -set blame-view = date:default author:abbreviated file-name:auto id:yes,color line-number:yes,interval=5 text +# Configure blame view columns using command spanning multiple lines. +set blame-view = \ + date:default \ + author:abbreviated \ + file-name:auto \ + id:yes,color \ + line-number:yes,interval=5 text -------------------------------------------------------------------------- Or in the Git configuration files: diff --git a/include/tig/io.h b/include/tig/io.h index 0ee47b2..cb27acb 100644 --- a/include/tig/io.h +++ b/include/tig/io.h @@ -59,6 +59,7 @@ struct io { size_t bufsize; /* Buffer content size. */ char *bufpos; /* Current buffer position. */ unsigned int eof:1; /* Has end of file been reached. */ + unsigned int span:1; /* Support commands spanning multiple lines. */ int status:8; /* Status exit code. */ }; diff --git a/src/io.c b/src/io.c index 1138d28..0b1d3c5 100644 --- a/src/io.c +++ b/src/io.c @@ -429,6 +429,11 @@ io_get(struct io *io, int c, bool can_read) while (TRUE) { if (io->bufsize > 0) { eol = memchr(io->bufpos, c, io->bufsize); + + while (io->span && io->bufpos < eol && eol[-1] == '\\') { + eol[-1] = eol[0] = ' '; + eol = memchr(io->bufpos, c, io->bufsize); + } if (eol) { char *line = io->bufpos; diff --git a/src/options.c b/src/options.c index 48c1a75..479f7f2 100644 --- a/src/options.c +++ b/src/options.c @@ -819,6 +819,8 @@ load_option_file(const char *path) return error("Error loading file %s: %s", path, strerror(io_error(&io))); } + io.span = TRUE; + if (io_load(&io, " \t", read_option, &config) == ERR || config.errors == TRUE) warn("Errors while loading %s.", path); -- 2.11.4.GIT