From f4b86a2b07de1fc23ccd07948736876182fa419a Mon Sep 17 00:00:00 2001 From: urosm Date: Wed, 31 Jul 2024 12:05:39 +0200 Subject: [PATCH] .config/vis: add vis config --- .config/vis/lexers/markdown.lua | 128 ++++++++++++++++++++++++++++++++ .config/vis/themes/basic.lua | 60 +++++++++++++++ .config/vis/visrc.lua | 79 ++++++++++++++++++++ 3 files changed, 267 insertions(+) create mode 100644 .config/vis/lexers/markdown.lua create mode 100644 .config/vis/themes/basic.lua create mode 100644 .config/vis/visrc.lua diff --git a/.config/vis/lexers/markdown.lua b/.config/vis/lexers/markdown.lua new file mode 100644 index 0000000..fdb6738 --- /dev/null +++ b/.config/vis/lexers/markdown.lua @@ -0,0 +1,128 @@ +-- Adapted from Markdown LPeg lexer by Mitchell. +-- See . + +local lexer = lexer +local P, S, B = lpeg.P, lpeg.S, lpeg.B + +local lex = lexer.new(..., {no_user_word_lists = true}) + +local md = '.markdown' + +local ws = lex:get_rule('whitespace') +local nl = P('\n') +local bl = nl * nl +local nws = lexer.any - lexer.space + +-- Heading. +lex:add_rule('heading_delimiter', + lex:tag('delimiter' .. md, + lexer.starts_line(P('#')^-6 * P(' ')))) + +lex:add_rule('heading', + lex:tag(lexer.HEADING .. md, + ( + B(bl * P('# ')) + + B(bl * P('## ')) + + B(bl * P('### ')) + + B(bl * P('#### ')) + + B(bl * P('##### ')) + + B(bl * P('###### ')) + ) * + lexer.to_eol(nws) * + #bl)) + +-- Blockquote. +lex:add_rule('blockquote_delimiter', + lex:tag('delimiter' .. md, + lexer.starts_line(P('> ')^1))) + +-- Horizontal rule. +lex:add_rule('hr', + lex:tag('hr' .. md, B(bl) * S('*-_')^3 * #bl)) + +-- Native divs. +lex:add_rule("native_div_delimiter", + lex:tag('delimiter' .. md, + lexer.starts_line(lexer.to_eol(':::')))) + +-- Code block. +local code_line = lexer.starts_line( + (B(' ') + B('\t')) * lexer.to_eol(), true) +local code_block = lexer.range(lexer.starts_line('```', true), lexer.starts_line(P('```'))) + lexer.range(lexer.starts_line('~~~', true), lexer.starts_line(P('~~~'))) +local code_inline = lpeg.Cmt( + lpeg.C(P('`')^1), function(input, index, bt) + local _, e = input:find('[^`]' .. bt .. '%f[^`]', index) + return (e or #input) + 1 + end) +lex:add_rule('block_code', lex:tag(lexer.CODE .. md, code_line + code_block)) + +-- Escape. +lex:add_rule('escape', lex:tag(lexer.DEFAULT, P('\\') * 1)) + +-- Bracket. +lex:add_rule('brackets', + lex:tag('delimiter' .. md, S('[]'))) + +-- Footnote. +lex:add_rule('footnote_key', + lex:tag(lexer.REFERENCE .. md, + (P('^') * #P('[')) + + (B('[') * P('^') * (lexer.any - lexer.space - S('^[]'))^1 * #P(']')))) +lex:add_rule('cite_key', + lex:tag(lexer.REFERENCE .. md, + B(lexer.space + P('[')) * P('-')^-1 * P('@') * (lexer.alnum + P('_')) * (lexer.alnum + S(':.#$%&-+?<>~/'))^0 + + B(lexer.space + P('[')) * P('-')^-1 * P('@') * lexer.range('{', '}'))) + +-- Link. +lex:add_rule('link_text', + lex:tag(lexer.LINK .. md, + B('[') * (lexer.any - P(']'))^1 * #P(P(']') * lexer.range('(', ')')))) +lex:add_rule('link_target', + lex:tag('delimiter' .. md, B(']') * lexer.range('(', ')'))) +lex:add_rule('link_ref', + lex:tag('delimiter' .. md, B(']') * P(':') * #lexer.space)) + +-- Image +lex:add_rule('image_bang', lex:tag(lexer.REFERENCE .. md, P('!') * #P('['))) + + +-- Attribute. +lex:add_rule('attribute', + lex:tag('delimiter' .. md, B(S('])')) * lexer.range('{', '}'))) + +local punct_space = lexer.punct + lexer.space + +-- Handles flanking delimiters as described in +-- https://github.github.com/gfm/#emphasis-and-strong-emphasis in the cases +-- where simple delimited ranges are not sufficient. +local function flanked_range(s, not_inword) + local fl_char = lexer.any - s - lexer.space + local left_fl = B(punct_space - s) * s * #fl_char + s * #(fl_char - lexer.punct) + local right_fl = B(lexer.punct) * s * #(punct_space - s) + B(fl_char) * s + return left_fl * (lexer.any - bl - (not_inword and s * #punct_space or s))^0 * right_fl +end + +local asterisk_strong = flanked_range('**') +local underscore_strong = (B(punct_space) + #lexer.starts_line('_')) * flanked_range('__', true) * #(punct_space + -1) +lex:add_rule('strong', lex:tag(lexer.BOLD, asterisk_strong + underscore_strong)) + +local asterisk_em = flanked_range('*') +local underscore_em = (B(punct_space) + #lexer.starts_line('_')) * flanked_range('_', true) * #(punct_space + -1) +lex:add_rule('em', lex:tag(lexer.ITALIC, asterisk_em + underscore_em)) + +-- Embedded HTML. +local html = lexer.load('html') +local html_start_rule = lexer.starts_line(P(' ')^-3) * + #P('<') * + html:get_rule('tag') + + html:get_rule('comment') +local html_end_rule = #bl * ws +lex:embed(html, html_start_rule, html_end_rule) + +-- Embedded YAML. +local yaml = lexer.load('yaml') +local yaml_start_rule = #lexer.starts_line(P('---'), false) * yaml:get_rule('doc_bounds') +local yaml_end_rule = #lexer.starts_line(P('...'), false) * yaml:get_rule('doc_bounds') +lex:embed(yaml, yaml_start_rule, yaml_end_rule) + +return lex diff --git a/.config/vis/themes/basic.lua b/.config/vis/themes/basic.lua new file mode 100644 index 0000000..57be59d --- /dev/null +++ b/.config/vis/themes/basic.lua @@ -0,0 +1,60 @@ +local lexers = vis.lexers +lexers.STYLE_LINENUMBER = 'fore:blue' +lexers.STYLE_LINENUMBER_CURSOR = 'fore:magenta' +lexers.STYLE_CURSOR = 'fore:black,back:blue' +lexers.STYLE_CURSOR_PRIMARY = 'fore:black,back:magenta' +lexers.STYLE_CURSOR_LINE = 'underlined' +lexers.STYLE_COLOR_COLUMN = 'fore:black,back:blue' +lexers.STYLE_SELECTION = 'fore:black,back:white' +lexers.STYLE_STATUS = 'fore:blue' +lexers.STYLE_STATUS_FOCUSED = 'fore:magenta' +lexers.STYLE_SEPARATOR = 'fore:blue' +lexers.STYLE_INFO = 'fore:red' +lexers.STYLE_EOF = 'fore:blue' + +lexers.STYLE_NOTHING = '' +lexers.STYLE_WHITESPACE = '' + +-- programming languages +lexers.STYLE_DEFAULT = '' +lexers.STYLE_COMMENT = 'fore:blue,bold' +lexers.STYLE_STRING = 'fore:red,bold' +lexers.STYLE_NUMBER = 'fore:red,bold' +lexers.STYLE_KEYWORD = 'fore:yellow,bold' +lexers.STYLE_IDENTIFIER = '' +lexers.STYLE_OPERATOR = 'fore:cyan,bold' +lexers.STYLE_ERROR = 'fore:red,italics' +lexers.STYLE_PREPROCESSOR = 'fore:magenta,bold' +lexers.STYLE_CONSTANT = 'fore:cyan,bold' +lexers.STYLE_CONSTANT_BUILTIN = 'fore:cyan,bold' +lexers.STYLE_VARIABLE = 'fore:blue,bold' +lexers.STYLE_VARIABLE_BUILTIN = 'fore:blue,bold' +lexers.STYLE_FUNCTION = 'fore:blue,bold' +lexers.STYLE_FUNCTION_BUILTIN = 'fore:blue,bold' +lexers.STYLE_FUNCTION_METHOD = 'fore:blue,bold' +lexers.STYLE_CLASS = 'fore:yellow,bold' +lexers.STYLE_TYPE = 'fore:green,bold' +lexers.STYLE_LABEL = 'fore:green,bold' +lexers.STYLE_REGEX = 'fore:green,bold' +lexers.STYLE_EMBEDDED = 'back:blue,bold' +lexers.STYLE_ANNOTATION = '' + +-- markup languages +lexers.STYLE_TAG = 'fore:red,bold' +lexers.STYLE_ATTRIBUTE = 'fore:green,bold' +lexers.STYLE_HEADING = 'fore:magenta,bold' +lexers.STYLE_BOLD = 'bold' +lexers.STYLE_ITALIC = 'italics' +lexers.STYLE_UNDERLINE = 'underlined' +lexers.STYLE_CODE = 'fore:yellow' +lexers.STYLE_LINK = lexers.STYLE_KEYWORD +lexers.STYLE_REFERENCE = lexers.STYLE_KEYWORD +lexers.STYLE_LIST = lexers.STYLE_KEYWORD + +-- Markdown +lexers.STYLE_DELIMITER_MARKDOWN = 'fore:blue' +lexers.STYLE_HEADING_MARKDOWN = 'bold' +lexers.STYLE_HR_MARKDOWN = lexers.STYLE_DELIMITER_MARKDOWN +lexers.STYLE_CODE_MARKDOWN = 'fore:yellow' +lexers.STYLE_REFERENCE_MARKDOWN = lexers.STYLE_REFERENCE +lexers.STYLE_LINK_MARKDOWN = lexers.STYLE_REFERENCE diff --git a/.config/vis/visrc.lua b/.config/vis/visrc.lua new file mode 100644 index 0000000..72fb879 --- /dev/null +++ b/.config/vis/visrc.lua @@ -0,0 +1,79 @@ +require('vis') + +vis.events.subscribe(vis.events.INIT, function() + vis.options.theme = require("themes.basic") + + vis:map(vis.modes.NORMAL, 'y', '+') + vis:map(vis.modes.VISUAL, 'y', '+') + vis:map(vis.modes.NORMAL, 'y', '+') + vis:map(vis.modes.VISUAL, 'd', '+') + vis:map(vis.modes.VISUAL_LINE, 'd', '+') + vis:map(vis.modes.VISUAL_LINE, 'd', '+') + vis:map(vis.modes.NORMAL, 'p', '+') + vis:map(vis.modes.VISUAL, 'p', '+') + vis:map(vis.modes.VISUAL_LINE, 'p', '+') + vis:map(vis.modes.NORMAL, 'P', '+') + vis:map(vis.modes.VISUAL, 'P', '+') + vis:map(vis.modes.VISUAL_LINE, 'P', '+') + + vis.options.autoindent = true + vis.options.ignorecase = true +end) + +vis.events.subscribe(vis.events.WIN_OPEN, function(win) + win.options.breakat = " .])}_" + win.options.colorcolumn = 81 + win.options.relativenumbers = true + win.options.tabwidth = 2 + win.options.wrapcolumn = 81 +end) + +local modes = { + [vis.modes.NORMAL] = 'NORMAL', + [vis.modes.OPERATOR_PENDING] = 'OPERATOR-PENDING', + [vis.modes.VISUAL] = 'VISUAL', + [vis.modes.VISUAL_LINE] = 'VISUAL-LINE', + [vis.modes.INSERT] = 'INSERT', + [vis.modes.REPLACE] = 'REPLACE', +} + +vis.events.subscribe(vis.events.WIN_STATUS, function(win) + local left_parts = {} + local right_parts = {} + local file = win.file + local selection = win.selection + + local file_info = (file.name or '[No Name]')..(file.modified and '[+]' or '') + + if vis.win == win then + -- mode + table.insert(left_parts, modes[vis.mode]) + + -- selection + table.insert(left_parts, selection.number..'/'..#win.selections) + + -- file info + file_info = + file_info + ..':' + ..(vis.count or '') + ..(vis.input_queue or '') + ..(vis.recording and '@' or '') + + -- character under cursor + table.insert(right_parts, + '<' + ..(string.byte(file:content(selection.pos, 1)) or '0') + ..'>') + end + + table.insert(left_parts, file_info) + + -- line and column count + table.insert(right_parts, #file.lines..'/'..selection.line) + table.insert(right_parts, selection.col) + + local left = table.concat(left_parts, " ") + local right = table.concat(right_parts, " ") + win:status(left, right); +end)