Skip to content

Commit

Permalink
Move all lua related files to lua/ subfolder
Browse files Browse the repository at this point in the history
Also remove the lexers sub directory from the Lua search path.
As a result we attempt to open fewer files during startup:

 $ strace -e open -o log ./vis +q config.h && wc -l log

In order to avoid having to modifiy all lexers which `require('lexer')`
we instead place a symlink in the top level directory.

 $ ./configure --disable-lua
 $ rm -rf lua

Should result in a source tree with most lua specifc functionality
removed.
  • Loading branch information
martanne committed Dec 7, 2016
1 parent 098504f commit 3570869
Show file tree
Hide file tree
Showing 141 changed files with 46 additions and 32 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ man:
done

luadoc:
@cd luadoc && ldoc . && sed -e "s/RELEASE/${VERSION}/" -i index.html
@cd lua/doc && ldoc . && sed -e "s/RELEASE/${VERSION}/" -i index.html

luadoc-all:
@cd luadoc && ldoc -a . && sed -e "s/RELEASE/${VERSION}/" -i index.html
@cd lua/doc && ldoc -a . && sed -e "s/RELEASE/${VERSION}/" -i index.html

install: vis vis-menu
@echo stripping executable
Expand All @@ -109,7 +109,7 @@ install: vis vis-menu
@test ${CONFIG_LUA} -eq 0 || { \
echo installing support files to ${DESTDIR}${SHAREPREFIX}/vis; \
mkdir -p ${DESTDIR}${SHAREPREFIX}/vis; \
cp -r visrc.lua vis.lua lexers ${DESTDIR}${SHAREPREFIX}/vis; \
cp -r lua/* ${DESTDIR}${SHAREPREFIX}/vis; \
}
@echo installing manual pages to ${DESTDIR}${MANPREFIX}/man1
@mkdir -p ${DESTDIR}${MANPREFIX}/man1
Expand Down
20 changes: 0 additions & 20 deletions lexers/template.txt

This file was deleted.

File renamed without changes.
2 changes: 1 addition & 1 deletion luadoc/config.ld → lua/doc/config.ld
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ sort=true
merge=true
no_space_before_args=true
file={
"../vis-lua.c",
"../../vis-lua.c",
"../vis.lua",
}

1 change: 1 addition & 0 deletions lua/lexer.lua
File renamed without changes.
29 changes: 27 additions & 2 deletions lexers/README.md → lua/lexers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ based lexers from the [Scintillua](http://foicica.com/scintillua/) project.
Vis searches the lexers in the following locations:

* `$VIS_PATH/lexers`
* `./lexers` relative to the binary location (using `/proc/self/exe`)
* `./lua/lexers` relative to the binary location (using `/proc/self/exe`)
* `$XDG_CONFIG_HOME/vis/lexers`
* `/usr/local/share/vis/lexers`
* `/usr/share/vis/lexers`
Expand All @@ -36,9 +36,34 @@ the table found at the end of the [vis.lua](/vis.lua) file.

Changes to existing lexers should also be sent upstream for consideration.

A template for new lexers:

```
-- ? LPeg lexer.
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 = '?'}
-- Whitespace.
local ws = token(l.WHITESPACE, l.space^1)
M._rules = {
{'whitespace', ws},
}
M._tokenstyles = {
}
return M
```

# Color Themes

The `themes` sub directory contains the color schemes. At startup the
The `../themes` directory contains the color schemes. At startup the
`default.lua` theme which should be a symlink to your prefered style is
used. Themes can be changed at runtime via the `:set theme <name>`
command where `<name>` does not include the `.lua` file extension.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion lexers/lexer.lua → lua/lexers/lexer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,7 @@ function M.load(name, alt_name)

-- Load the language lexer with its rules, styles, etc.
M.WHITESPACE = (alt_name or name)..'_whitespace'
local lexer_file, error = package.searchpath(name, M.LEXERPATH)
local lexer_file, error = package.searchpath('lexers/'..name, M.LEXERPATH)
local ok, lexer = pcall(dofile, lexer_file or '')
if not ok then
return nil
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 13 additions & 5 deletions vis-lua.c
Original file line number Diff line number Diff line change
Expand Up @@ -1804,10 +1804,8 @@ bool vis_lua_path_add(Vis *vis, const char *path) {
lua_getglobal(L, "package");
lua_pushstring(L, path);
lua_pushstring(L, "/?.lua;");
lua_pushstring(L, path);
lua_pushstring(L, "/lexers/?.lua;");
lua_getfield(L, -5, "path");
lua_concat(L, 5);
lua_getfield(L, -3, "path");
lua_concat(L, 3);
lua_setfield(L, -2, "path");
lua_pop(L, 1); /* package */
return true;
Expand Down Expand Up @@ -1888,7 +1886,17 @@ void vis_lua_init(Vis *vis) {
ssize_t len = readlink("/proc/self/exe", path, sizeof(path)-1);
if (len > 0) {
path[len] = '\0';
vis_lua_path_add(vis, dirname(path));
/* some idotic dirname(3) implementations return pointers to statically
* allocated memory, hence we use memmove to copy it back */
char *dir = dirname(path);
if (dir) {
size_t len = strlen(dir)+1;
if (len < sizeof(path) - sizeof("/lua")) {
memmove(path, dir, len);
strcat(path, "/lua");
vis_lua_path_add(vis, path);
}
}
}

vis_lua_path_add(vis, getenv("VIS_PATH"));
Expand Down

0 comments on commit 3570869

Please sign in to comment.