diff --git a/files/.config/vis/plugins/vis-sneak/.gitignore b/files/.config/vis/plugins/vis-sneak/.gitignore new file mode 100644 index 0000000..600d2d3 --- /dev/null +++ b/files/.config/vis/plugins/vis-sneak/.gitignore @@ -0,0 +1 @@ +.vscode \ No newline at end of file diff --git a/files/.config/vis/plugins/vis-sneak/.luarc.json b/files/.config/vis/plugins/vis-sneak/.luarc.json new file mode 100644 index 0000000..5e46e3f --- /dev/null +++ b/files/.config/vis/plugins/vis-sneak/.luarc.json @@ -0,0 +1,7 @@ +{ + "Lua": { + "diagnostics": { + "globals": ["vis"] + } + } +} \ No newline at end of file diff --git a/files/.config/vis/plugins/vis-sneak/LICENSE b/files/.config/vis/plugins/vis-sneak/LICENSE new file mode 100644 index 0000000..d8d78d6 --- /dev/null +++ b/files/.config/vis/plugins/vis-sneak/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2020 Erlend Lind Madsen + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/files/.config/vis/plugins/vis-sneak/README.md b/files/.config/vis/plugins/vis-sneak/README.md new file mode 100644 index 0000000..0a6f2a5 --- /dev/null +++ b/files/.config/vis/plugins/vis-sneak/README.md @@ -0,0 +1,20 @@ +# vis-sneak + +Jump to a location specified by two characters. + +A minimal motion [plugin](https://github.com/martanne/vis/wiki/Plugins) for [vis](https://github.com/martanne/vis) inspired by [vim-sneak](https://github.com/justinmk/vim-sneak). + +## Usage + +Type `s{char}{char}` to move to the next char combo. + +Type `S{char}{char}` to move back. + +Matches are highlighted until you move outside the matches. + +Type `n` or `N` to find the next or prev match, or append a number to the motion. + + +## Install + +Download and require manually, or add `erf/vis-sneak` using [vis-plug](https://github.com/erf/vis-plug). diff --git a/files/.config/vis/plugins/vis-sneak/init.lua b/files/.config/vis/plugins/vis-sneak/init.lua new file mode 100644 index 0000000..839bc4a --- /dev/null +++ b/files/.config/vis/plugins/vis-sneak/init.lua @@ -0,0 +1,83 @@ +local pattern = nil +local matches = {} + +-- iterater for doing find in pattern until nil +local pattern_iterator = function(content, pattern) + local offset = 1 + return function() + local starts, ends = string.find(content, pattern, offset) + if starts == nil then return nil end + offset = ends + 1 + return starts, ends + end +end + +-- is cursor pos is in one of the matches? +local cursor_on_match = function(win) + local pos = win.selection.pos + for _, range in ipairs(matches) do + if pos >= range.start and pos <= range.finish then + return true + end + end + return false +end + +-- check if range is in viewport range +local range_in_viewport = function(viewport, range) + return range.start >= viewport.bytes.start and range.finish <= viewport.bytes.finish +end + +-- highlihght current matches +local highlight = function(win) + + -- clear matches if cursor is not on a match + if not cursor_on_match(win) then + matches = {} + return + end + + -- style matches in viewport + for _, range in ipairs(matches) do + if range_in_viewport(win.viewport, range) then + win:style(win.STYLE_CURSOR, range.start, range.finish) + end + end +end + +-- collect matches (ranges) for pattern in file +local collect_matches = function() + local file = vis.win.file + local content = file:content(0, file.size) + matches = {} + for starts, ends in pattern_iterator(content, pattern) do + table.insert(matches, { start = starts - 1, finish = ends - 1 }) + end +end + +-- highlight matches on WIN_HIGHLIGHT +vis.events.subscribe(vis.events.WIN_HIGHLIGHT, function(win) + highlight(win) +end) + +-- create search for two chars and collect matches for highlighting +local sneak = function(keys, search_char) + if #keys < 2 then + pattern = nil + return -1 + end + vis:feedkeys(search_char .. keys .. '') + pattern = keys + collect_matches() + return 2 +end + +-- sneak forward on 's' +vis:map(vis.modes.NORMAL, 's', function(keys) + return sneak(keys, '/') +end) + +-- sneak backwards on 'S' +vis:map(vis.modes.NORMAL, 'S', function(keys) + return sneak(keys, '?') +end) diff --git a/files/.config/vis/themes b/files/.config/vis/themes new file mode 120000 index 0000000..5398451 --- /dev/null +++ b/files/.config/vis/themes @@ -0,0 +1 @@ +/home/k/dots/files/dots/files/.config/vis/themes \ No newline at end of file diff --git a/files/.config/vis/themes/kento2.lua b/files/.config/vis/themes/kento2.lua deleted file mode 120000 index dec402b..0000000 --- a/files/.config/vis/themes/kento2.lua +++ /dev/null @@ -1 +0,0 @@ -/home/a/dots/files/dots/files/.config/vis/themes/kento2.lua \ No newline at end of file diff --git a/files/.config/vis/themes/wryan.lua b/files/.config/vis/themes/wryan.lua deleted file mode 100644 index 5826e84..0000000 --- a/files/.config/vis/themes/wryan.lua +++ /dev/null @@ -1,80 +0,0 @@ --- wryan.lua - -local lexers = vis.lexers -local colors = { - ['bg'] = '#111111', - ['fg'] = '#999993', - ['blk'] = '#333333', - ['bblk'] = '#3d3d3d', - ['red'] = '#8c4665', - ['bred'] = '#bf4d80', - ['grn'] = '#287373', - ['bgrn'] = '#53a6a6', - ['ylw'] = '#7c7c99', - ['bylw'] = '#9e9ecb', - ['blu'] = '#395573', - ['bblu'] = '#477ab3', - ['mag'] = '#5e468c', - ['bmag'] = '#7e62b3', - ['cyn'] = '#31658c', - ['bcyn'] = '#6096bf', - ['wht'] = '#899ca1', - ['bwht'] = '#c0c0c0', - - -- special colors - ['dim1'] = '#191919', - ['dim2'] = '#262626' -} - --- general styles -lexers.STYLE_DEFAULT = 'fore:'..colors.fg..',back:'..colors.bg -- default fg / bg -lexers.STYLE_NOTHING = lexers.STYLE_DEFAULT -lexers.STYLE_ATTRIBUTE = 'fore:'..colors.bmag -- attribute names, `` -lexers.STYLE_CLASS = 'fore:'..colors.mag -- classes, `class _MyClass_` -lexers.STYLE_COMMENT = 'fore:'..colors.bblk -- comments, `_/* foo */_` -lexers.STYLE_CONSTANT = lexers.STYLE_DEFAULT -- compiler constants &c, `#define _FOO_ 5` -lexers.STYLE_DEFINITION = 'fore:'..colors.bblu -- definitions, overlaps with other tokens -lexers.STYLE_ERROR = 'fore:'..colors.bg..',back:'..colors.red -- syntax errors -lexers.STYLE_FUNCTION = 'fore:'..colors.bblu -- functions, `void _doBar_()` -lexers.STYLE_HEADING = 'fore:'..colors.bmag..',bold' -- headings, like in markdown -lexers.STYLE_KEYWORD = 'fore:'..colors.bred -- keywords, `_for_ (;;)` -lexers.STYLE_LABEL = 'fore:'..colors.red -- goto &c, `_target_:` -lexers.STYLE_NUMBER = 'fore:'..colors.bcyn -- number constants -lexers.STYLE_OPERATOR = lexers.STYLE_DEFAULT -- operators, `int foo _=_ 0` -lexers.STYLE_REGEX = 'fore:'..colors.red -- regular expressions, `"_^\w*$_"` -lexers.STYLE_STRING = 'fore:'..colors.bgrn -- strings, `char* baz = _"hello!"_` -lexers.STYLE_PREPROCESSOR = 'fore:'..colors.cyn -- preprocessor rules, `_#define_ FOO 5` -lexers.STYLE_TAG = 'fore:'..colors.bblk -- tag names, `<_div_ class="foo">` -lexers.STYLE_TYPE = 'fore:'..colors.bgrn -- types, `_int_ foo = 0` -lexers.STYLE_VARIABLE = lexers.STYLE_DEFAULT -- variable names, `int _foo_ = 0` -lexers.STYLE_WHITESPACE = 'fore:'..colors.blk -- whitespaces -lexers.STYLE_EMBEDDED = 'back:'..colors.dim1 -- embedded code -lexers.STYLE_IDENTIFIER = lexers.STYLE_DEFAULT -- unclassified names - --- UI styles -lexers.STYLE_LINENUMBER = 'fore:'..colors.blk -- inactive line numbers -lexers.STYLE_LINENUMBER_CURSOR = 'fore:'..colors.bcyn -- active line numbers -lexers.STYLE_CURSOR = 'fore:'..colors.fg..',reverse' -- cursor color -lexers.STYLE_CURSOR_PRIMARY = lexers.STYLE_CURSOR -lexers.STYLE_CURSOR_LINE = 'back:'..colors.dim1 -- cursor line -lexers.STYLE_COLOR_COLUMN = lexers.STYLE_CURSOR_LINE -- color column -lexers.STYLE_SELECTION = lexers.STYLE_CURSOR_LINE -- visual selection -lexers.STYLE_STATUS = 'fore:'..colors.bblk..',back:'..colors.dim2 -- inactive statusline -lexers.STYLE_STATUS_FOCUSED = 'fore:'..colors.fg..',back:'..colors.dim2 -- active statusline -lexers.STYLE_SEPARATOR = lexers.STYLE_COMMENT -- vertical split color -lexers.STYLE_BRACKETS = 'fore:'..colors.red..',bold' -- matched brackets, e.g [__]__ -lexers.STYLE_INFO = 'bold' -- messages from `vis:info()` -lexers.STYLE_EOF = 'fore:'..colors.dim2 -- the tildes at the end of the buffer - --- lexer-specific --- TODO add more... - --- markdown -lexers.STYLE_HR = lexers.STYLE_COMMENT -for i = 1,6 do lexers['STYLE_HEADING_H'..i] = lexers.STYLE_HEADING end -lexers.STYLE_BOLD = 'bold' -lexers.STYLE_ITALIC = 'italics' -lexers.STYLE_LIST = lexers.STYLE_KEYWORD -lexers.STYLE_LINK = lexers.STYLE_KEYWORD -lexers.STYLE_REFERENCE = lexers.STYLE_KEYWORD -lexers.STYLE_CODE = lexers.STYLE_EMBEDDED