aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Schultheisz <kdsch@protonmail.com>2020-01-21 21:27:11 -0500
committerKarl Schultheisz <kdsch@protonmail.com>2020-01-21 21:27:11 -0500
commit2d6150426fe825cd7b179c5c3ed648ae607be122 (patch)
tree72d0d8be0c235900736ef0b89fe4770d98c5e1c9
parentcb03746137bc23f3c1b485088fefb9d4feffa368 (diff)
parent30cd60cc2b2babda36ab752396df58697e9f26fd (diff)
downloadvis-2d6150426fe825cd7b179c5c3ed648ae607be122.tar.gz
vis-2d6150426fe825cd7b179c5c3ed648ae607be122.tar.xz
Merge branch 'master' into add-layout-option
-rw-r--r--.travis.yml3
-rw-r--r--Dockerfile6
-rw-r--r--GNUmakefile8
-rw-r--r--Makefile2
-rw-r--r--lua/lexers/bash.lua2
-rw-r--r--lua/lexers/fennel.lua88
-rw-r--r--lua/lexers/text.lua9
-rw-r--r--lua/plugins/filetype.lua19
-rw-r--r--lua/themes/solarized.lua4
-rw-r--r--text-motions.c3
-rw-r--r--vis-menu.c26
11 files changed, 144 insertions, 26 deletions
diff --git a/.travis.yml b/.travis.yml
index 803ad6b..ab0dd7d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -48,6 +48,7 @@ addons:
- 9base
- libacl1-dev
- libtre-dev
+ - libtool-bin
cache:
directories:
@@ -59,7 +60,7 @@ before_install:
install:
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then
brew update &&
- brew install libtermkey lua luarocks tre plan9port &&
+ brew install libtermkey lua luarocks tre &&
luarocks install lpeg &&
luarocks install busted;
fi
diff --git a/Dockerfile b/Dockerfile
index 037556a..fe246bb 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -6,17 +6,17 @@
# docker cp vis:/tmp/vis/vis .
# make vis-single
# docker cp vis:/tmp/vis/vis-single .
-FROM i386/alpine:3.9
+FROM i386/alpine:3.11
ENV DIR /tmp/vis
WORKDIR $DIR
RUN apk update && apk add musl-dev fortify-headers gcc make libtermkey-dev \
ncurses-dev ncurses-static lua5.3-dev lua5.3-lpeg lua-lpeg-dev \
- acl-dev xz-dev tar xz wget ca-certificates
+ acl-static acl-dev xz-dev tar xz wget ca-certificates
RUN sed -i 's/Libs: /Libs: -L${INSTALL_CMOD} /' /usr/lib/pkgconfig/lua5.3.pc
RUN mv /usr/lib/lua/5.3/lpeg.a /usr/lib/lua/5.3/liblpeg.a
RUN sed -i 's/-ltermkey/-ltermkey -lunibilium/' /usr/lib/pkgconfig/termkey.pc
# TODO contribute a proper libuntar package to Alpine
-RUN wget https://github.com/martanne/libuntar/tarball/3f5e915ad8e6c5faa8dc6b34532e32b519f278f3 -O libuntar.tar.gz && \
+RUN wget https://github.com/martanne/libuntar/tarball/7c7247b442b021588f6deba78b60ef3b05ab1e0c -O libuntar.tar.gz && \
tar xf libuntar.tar.gz && cd *-libuntar-* && \
make && \
mkdir -p /usr/local/include && \
diff --git a/GNUmakefile b/GNUmakefile
index 0669a94..76821ad 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -1,7 +1,7 @@
include Makefile
-LIBTERMKEY = libtermkey-0.20
-LIBTERMKEY_SHA256 = 6c0d87c94ab9915e76ecd313baec08dedf3bd56de83743d9aa923a081935d2f5
+LIBTERMKEY = libtermkey-0.22
+LIBTERMKEY_SHA256 = 6945bd3c4aaa83da83d80a045c5563da4edd7d0374c62c0d35aec09eb3014600
LIBLUA = lua-5.3.4
LIBLUA_SHA256 = f681aa518233bc407e23acf0f5887c884f17436f000d453b2491a9f11a52400c
@@ -10,8 +10,8 @@ LIBLUA_SHA256 = f681aa518233bc407e23acf0f5887c884f17436f000d453b2491a9f11a52400c
#LIBLUA = lua-5.1.5
#LIBLUA_SHA256 = 2640fc56a795f29d28ef15e13c34a47e223960b0240e8cb0a82d9b0738695333
-LIBLPEG = lpeg-1.0.1
-LIBLPEG_SHA256 = 62d9f7a9ea3c1f215c77e0cadd8534c6ad9af0fb711c3f89188a8891c72f026b
+LIBLPEG = lpeg-1.0.2
+LIBLPEG_SHA256 = 48d66576051b6c78388faad09b70493093264588fcd0f258ddaab1cdd4a15ffe
SRCDIR = $(realpath $(dir $(firstword $(MAKEFILE_LIST))))
diff --git a/Makefile b/Makefile
index 0ee47a0..5cdb53b 100644
--- a/Makefile
+++ b/Makefile
@@ -90,7 +90,7 @@ docker: clean
docker exec vis apk upgrade
docker cp . vis:/tmp/vis
docker exec vis sed -i '/^VERSION/c VERSION = $(VERSION)' Makefile
- docker exec vis ./configure CC='cc --static'
+ docker exec vis ./configure CC='cc --static' --enable-acl
docker exec vis make clean vis-single
docker cp vis:/tmp/vis/vis-single vis
docker kill vis
diff --git a/lua/lexers/bash.lua b/lua/lexers/bash.lua
index 2fa72f2..207cb22 100644
--- a/lua/lexers/bash.lua
+++ b/lua/lexers/bash.lua
@@ -21,7 +21,7 @@ local heredoc = '<<' * P(function(input, index)
local s, e, _, delimiter =
input:find('%-?(["\']?)([%a_][%w_]*)%1[\n\r\f;]+', index)
if s == index and delimiter then
- local _, e = input:find('[\n\r\f]+'..delimiter, e)
+ local _, e = input:find('[\n\r\f]+'..delimiter..'\n', e)
return e and e + 1 or #input + 1
end
end)
diff --git a/lua/lexers/fennel.lua b/lua/lexers/fennel.lua
new file mode 100644
index 0000000..ee8127c
--- /dev/null
+++ b/lua/lexers/fennel.lua
@@ -0,0 +1,88 @@
+-- Copyright 2006-2017 Mitchell mitchell.att.foicica.com. See LICENSE.
+-- Lua LPeg lexer.
+-- Original written by Peter Odding, 2007/04/04.
+
+local l = require('lexer')
+local token, word_match = l.token, l.word_match
+local P, R, S = lpeg.P, lpeg.R, lpeg.S
+
+local M = {_NAME = 'fennel'}
+
+-- Whitespace.
+local ws = token(l.WHITESPACE, l.space^1)
+
+-- Comments.
+local line_comment = ';' * l.nonnewline^0
+local comment = token(l.COMMENT, line_comment)
+
+-- Strings.
+local dq_str = l.delimited_range('"')
+local string = token(l.STRING, dq_str)
+
+-- Numbers.
+local lua_integer = P('-')^-1 * (l.hex_num + l.dec_num)
+local number = token(l.NUMBER, l.float + lua_integer)
+
+-- Keywords.
+local keyword = token(l.KEYWORD, word_match({
+ '%', '*', '+', '-', '->', '->>', '-?>', '-?>>', '.', '..', '/', '//', ':', '<', '<=', '=', '>', '>=', '^', '~=', 'λ',
+ 'and', 'comment', 'do', 'doc', 'doto', 'each', 'eval-compiler', 'fn', 'for', 'global', 'hashfn', 'if', 'include', 'lambda',
+ 'length', 'let', 'local', 'lua', 'macro', 'macros', 'match', 'not', 'not=', 'or', 'partial', 'quote', 'require-macros',
+ 'set', 'set-forcibly!', 'tset', 'values', 'var', 'when', 'while'
+}, "%*+-./:<=>?~^λ!"))
+
+-- Libraries.
+local library = token('library', word_match({
+ -- Coroutine.
+ 'coroutine', 'coroutine.create', 'coroutine.resume', 'coroutine.running',
+ 'coroutine.status', 'coroutine.wrap', 'coroutine.yield',
+ -- Module.
+ 'package', 'package.cpath', 'package.loaded', 'package.loadlib',
+ 'package.path', 'package.preload',
+ -- String.
+ 'string', 'string.byte', 'string.char', 'string.dump', 'string.find',
+ 'string.format', 'string.gmatch', 'string.gsub', 'string.len', 'string.lower',
+ 'string.match', 'string.rep', 'string.reverse', 'string.sub', 'string.upper',
+ -- Table.
+ 'table', 'table.concat', 'table.insert', 'table.remove', 'table.sort',
+ -- Math.
+ 'math', 'math.abs', 'math.acos', 'math.asin', 'math.atan', 'math.ceil',
+ 'math.cos', 'math.deg', 'math.exp', 'math.floor', 'math.fmod', 'math.huge',
+ 'math.log', 'math.max', 'math.min', 'math.modf', 'math.pi', 'math.rad',
+ 'math.random', 'math.randomseed', 'math.sin', 'math.sqrt', 'math.tan',
+ -- IO.
+ 'io', 'io.close', 'io.flush', 'io.input', 'io.lines', 'io.open', 'io.output',
+ 'io.popen', 'io.read', 'io.stderr', 'io.stdin', 'io.stdout', 'io.tmpfile',
+ 'io.type', 'io.write',
+ -- OS.
+ 'os', 'os.clock', 'os.date', 'os.difftime', 'os.execute', 'os.exit',
+ 'os.getenv', 'os.remove', 'os.rename', 'os.setlocale', 'os.time',
+ 'os.tmpname',
+ -- Debug.
+ 'debug', 'debug.debug', 'debug.gethook', 'debug.getinfo', 'debug.getlocal',
+ 'debug.getmetatable', 'debug.getregistry', 'debug.getupvalue',
+ 'debug.sethook', 'debug.setlocal', 'debug.setmetatable', 'debug.setupvalue',
+ 'debug.traceback',
+}, '.'))
+
+local initial = l.alpha + S"|$%&#*+-./:<=>?~^_λ!"
+local subsequent = initial + l.digit
+
+-- Identifiers.
+local identifier = token(l.IDENTIFIER, initial * subsequent^0)
+
+M._rules = {
+ {'whitespace', ws},
+ {'keyword', keyword},
+ {'library', library},
+ {'identifier', identifier},
+ {'string', string},
+ {'comment', comment},
+ {'number', number}
+}
+
+M._tokenstyles = {
+ library = l.STYLE_TYPE,
+}
+
+return M
diff --git a/lua/lexers/text.lua b/lua/lexers/text.lua
index 4988d95..cc41bfa 100644
--- a/lua/lexers/text.lua
+++ b/lua/lexers/text.lua
@@ -1,6 +1,15 @@
-- Copyright 2006-2017 Mitchell mitchell.att.foicica.com. See LICENSE.
-- Text LPeg lexer.
+local l = require('lexer')
+
local M = {_NAME = 'text'}
+-- Whitespace.
+local ws = l.token(l.WHITESPACE, l.space^1)
+
+M._rules = {
+ {'whitespace', ws},
+}
+
return M
diff --git a/lua/plugins/filetype.lua b/lua/plugins/filetype.lua
index 6c574bc..cff073a 100644
--- a/lua/plugins/filetype.lua
+++ b/lua/plugins/filetype.lua
@@ -102,13 +102,13 @@ vis.ftdetect.filetypes = {
ext = { "%.d$", "%.di$" },
},
dockerfile = {
- ext = { "Dockerfile" },
+ ext = { "^Dockerfile$", "%.Dockerfile$" },
},
dot = {
ext = { "%.dot$" },
},
dsv = {
- ext = { "group", "gshadow", "passwd", "shadow" },
+ ext = { "^group$", "^gshadow$", "^passwd$", "^shadow$" },
},
eiffel = {
ext = { "%.e$", "%.eif$" },
@@ -125,6 +125,9 @@ vis.ftdetect.filetypes = {
faust = {
ext = { "%.dsp$" },
},
+ fennel = {
+ ext = { "%.fnl$" },
+ },
fish = {
ext = { "%.fish$" },
},
@@ -282,7 +285,7 @@ vis.ftdetect.filetypes = {
ext = { "%.pike$", "%.pmod$" },
},
pkgbuild = {
- ext = { "PKGBUILD" },
+ ext = { "^PKGBUILD$" },
},
pony = {
ext = { "%.pony$" },
@@ -385,6 +388,10 @@ vis.ftdetect.filetypes = {
texinfo = {
ext = { "%.texi$" },
},
+ text = {
+ ext = { "%.txt$" },
+ mime = { "text/plain" },
+ },
toml = {
ext = { "%.toml$" },
},
@@ -497,6 +504,12 @@ vis.events.subscribe(vis.events.WIN_OPEN, function(win)
end
end
+ -- try text lexer as a last resort
+ if (mime or 'text/plain'):match('^text/.+$') then
+ set_filetype('text', vis.ftdetect.filetypes.text)
+ return
+ end
+
win:set_syntax(nil)
end)
diff --git a/lua/themes/solarized.lua b/lua/themes/solarized.lua
index a5d4c4d..7f40858 100644
--- a/lua/themes/solarized.lua
+++ b/lua/themes/solarized.lua
@@ -27,6 +27,10 @@ local bg = ',back:'..colors.base03..','
-- light
-- local fg = ',fore:'..colors.base03..','
-- local bg = ',back:'..colors.base3..','
+-- solarized term
+-- local fg = ',fore:default,'
+-- local bg = ',back:default,'
+
lexers.STYLE_DEFAULT = bg..fg
lexers.STYLE_NOTHING = bg
diff --git a/text-motions.c b/text-motions.c
index 689bb1f..533d896 100644
--- a/text-motions.c
+++ b/text-motions.c
@@ -622,8 +622,7 @@ size_t text_search_forward(Text *txt, size_t pos, Regex *regex) {
if (!found) {
start = 0;
- end = pos;
- found = !text_search_range_forward(txt, start, end, regex, 1, match, 0);
+ found = !text_search_range_forward(txt, start, end - start, regex, 1, match, 0);
}
return found ? match[0].start : pos;
diff --git a/vis-menu.c b/vis-menu.c
index 1682ed2..3a2d487 100644
--- a/vis-menu.c
+++ b/vis-menu.c
@@ -41,6 +41,7 @@
#include <sys/types.h>
#include <termios.h>
#include <unistd.h>
+#include <errno.h>
#define CONTROL(ch) (ch ^ 0x40)
#define MIN(a,b) ((a) < (b) ? (a) : (b))
@@ -59,9 +60,9 @@ struct Item {
static char text[BUFSIZ] = "";
static int barpos = 0;
-static int mw, mh;
-static int lines = 0;
-static int inputw, promptw;
+static size_t mw, mh;
+static size_t lines = 0;
+static size_t inputw, promptw;
static size_t cursor;
static char *prompt = NULL;
static Item *items = NULL;
@@ -96,7 +97,7 @@ textw(const char *s) {
static void
calcoffsets(void) {
- int i, n;
+ size_t i, n;
if (lines > 0)
n = lines;
@@ -128,7 +129,7 @@ die(const char *s) {
static void
drawtext(const char *t, size_t w, Color col) {
const char *prestr, *poststr;
- int i, tw;
+ size_t i, tw;
char *buf;
if (w<5) return; /* This is the minimum size needed to write a label: 1 char + 4 padding spaces */
@@ -156,14 +157,14 @@ drawtext(const char *t, size_t w, Color col) {
static void
resetline(void) {
- if (barpos != 0) fprintf(stderr, "\033[%iH", barpos > 0 ? 0 : (mh-lines));
- else fprintf(stderr, "\033[%iF", lines);
+ if (barpos != 0) fprintf(stderr, "\033[%ldH", (long)(barpos > 0 ? 0 : (mh-lines)));
+ else fprintf(stderr, "\033[%zuF", lines);
}
static void
drawmenu(void) {
Item *item;
- int rw;
+ size_t rw;
/* use default colors */
fprintf(stderr, "\033[0m");
@@ -195,12 +196,12 @@ drawmenu(void) {
if ((rw -= textw(item->text)) <= 0) break;
}
if (next) {
- fprintf(stderr, "\033[%iG", mw-5);
+ fprintf(stderr, "\033[%zuG", mw-5);
drawtext(">", 5 /*textw(">")*/, C_Normal);
}
}
- fprintf(stderr, "\033[%iG", (int)(promptw+textwn(text, cursor)-1));
+ fprintf(stderr, "\033[%ldG", (long)(promptw+textwn(text, cursor)-1));
fflush(stderr);
}
@@ -591,7 +592,10 @@ main(int argc, char **argv) {
if (prompt && !prompt[0])
prompt = NULL;
} else if (!strcmp(argv[i], "-l")) {
- lines = atoi(argv[++i]);
+ errno = 0;
+ lines = strtoul(argv[++i], NULL, 10);
+ if (errno)
+ usage();
} else {
usage();
}