1
0
Fork 0

Compare commits

...

3 Commits

4 changed files with 72 additions and 77 deletions

View File

@ -1,6 +1,6 @@
[Default Applications]
text/plain=nvim.desktop;
text/markdown=nvim.desktop;
text/plain=vis.desktop;
text/markdown=vis.desktop;
application/pdf=org.pwmt.zathura.desktop;
x-scheme-handler/http=firefox.desktop;
x-scheme-handler/https=firefox.desktop;

View File

@ -1,5 +1,5 @@
-- Adapted from Markdown LPeg lexer by Mitchell.
-- See <https://git.sr.ht/~martanne/vis>.
-- Adapted from Markdown LPeg lexer by Mitchell to simplify and lex some pandoc
-- specifics.
local lexer = lexer
local P, S, B = lpeg.P, lpeg.S, lpeg.B
@ -14,81 +14,69 @@ 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))
lex:tag(lexer.COMMENT, lexer.starts_line(P('#')^-6)) *
P(' ') *
lex:tag(lexer.HEADING, lexer.to_eol(nws) *
#bl))
-- Blockquote.
lex:add_rule('blockquote_delimiter',
lex:tag('delimiter' .. md,
lex:add_rule('blockquote',
lex:tag(lexer.COMMENT,
lexer.starts_line(P('> ')^1)))
-- Horizontal rule.
lex:add_rule('hr',
lex:tag('hr' .. md, B(bl) * S('*-_')^3 * #bl))
lex:tag(lexer.COMMENT, B(bl) * S('*-_')^3 * #bl))
-- Native divs.
lex:add_rule("native_div_delimiter",
lex:tag('delimiter' .. md,
lexer.starts_line(lexer.to_eol(':::'))))
-- Native div.
lex:add_rule("native_div",
lex:tag(lexer.COMMENT, lexer.starts_line(lexer.to_eol(P(':')^3))))
-- 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 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))
lex:add_rule('block_code', lex:tag(lexer.CODE, 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('[]')))
lex:tag(lexer.COMMENT, S('[]')))
-- Native span.
lex:add_rule('native_span',
B(']') * lex:tag(lexer.COMMENT, lexer.range('{', '}')))
-- Footnote.
lex:add_rule('footnote_key',
lex:tag(lexer.REFERENCE .. md,
(P('^') * #P('[')) +
(B('[') * P('^') * (lexer.any - lexer.space - S('^[]'))^1 * #P(']'))))
lex:tag(lexer.REFERENCE, P('^')) * #P('[') +
B('[') * lex:tag(lexer.REFERENCE, P('^') * (lexer.any - lexer.space - S('^[]'))^1) * #P(']'))
-- @todo footnote reference
-- Cite.
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('{', '}')))
B(lexer.space + P('[')) * lex:tag(lexer.REFERENCE,
P('-')^-1 *
(P('@') * (lexer.alnum + P('_')) * (lexer.alnum + S(':.#$%&-+?<>~/'))^0 +
P('@') * lexer.range('{', '}'))))
-- Link.
lex:add_rule('link_text',
lex:tag(lexer.LINK .. md,
B('[') * (lexer.any - P(']'))^1 * #P(P(']') * lexer.range('(', ')'))))
B('[') * lex:tag(lexer.LINK, (lexer.any - P(']'))^1) * #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))
B(']') * lex:tag(lexer.COMMENT, lexer.range('(', ')')))
-- @todo link reference
-- 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('{', '}')))
lex:add_rule('image_bang', lex:tag(lexer.REFERENCE, P('!')) * #P('['))
local punct_space = lexer.punct + lexer.space
@ -121,8 +109,8 @@ 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')
local yaml_start_rule = yaml:get_rule('doc_bounds') - B(bl) * P(P('---') + '...') * #bl
local yaml_end_rule = yaml:get_rule('doc_bounds') - B(bl) * P(P('---') + '...') * #bl
lex:embed(yaml, yaml_start_rule, yaml_end_rule)
return lex

View File

@ -34,12 +34,11 @@ vis.events.subscribe(vis.events.WIN_STATUS, function(win)
end
end)
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 = 'fore:black,back:white'
lexers.STYLE_CURSOR_PRIMARY = 'fore:black,back:blue'
lexers.STYLE_CURSOR_LINE = 'underlined'
lexers.STYLE_COLOR_COLUMN = 'fore:black,back:blue'
lexers.STYLE_SELECTION = 'fore:black,back:white'
@ -64,11 +63,11 @@ 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 = 'fore:white,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_FUNCTION = 'fore:white,bold'
lexers.STYLE_FUNCTION_BUILTIN = 'fore:white,bold'
lexers.STYLE_FUNCTION_METHOD = 'fore:white,bold'
lexers.STYLE_CLASS = 'fore:yellow,bold'
lexers.STYLE_TYPE = 'fore:green,bold'
lexers.STYLE_LABEL = 'fore:green,bold'
@ -77,9 +76,9 @@ lexers.STYLE_EMBEDDED = 'back:blue,bold'
lexers.STYLE_ANNOTATION = ''
-- markup languages
lexers.STYLE_TAG = 'fore:red,bold'
lexers.STYLE_TAG = lexers.STYLE_KEYWORD
lexers.STYLE_ATTRIBUTE = 'fore:green,bold'
lexers.STYLE_HEADING = 'fore:magenta,bold'
lexers.STYLE_HEADING = 'fore:white,bold'
lexers.STYLE_BOLD = 'bold'
lexers.STYLE_ITALIC = 'italics'
lexers.STYLE_UNDERLINE = 'underlined'

View File

@ -1,5 +1,15 @@
require('vis')
local mode_strings = {
[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',
}
-- editor options
vis.events.subscribe(vis.events.INIT, function()
vis.options.theme = require("themes.basic")
@ -20,24 +30,24 @@ vis.events.subscribe(vis.events.INIT, function()
vis.options.ignorecase = true
end)
-- window options
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
if win.syntax == 'markdown' then
win.options.breakat = " .])}_"
win.options.expandtab = true
win.options.tabwidth = 2
win.options.wrapcolumn = 81
end
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)
set_statusline(win, mode_strings[vis.mode])
end)
function set_statusline(win, mode_string)
local left_parts = {}
local right_parts = {}
local file = win.file
@ -47,7 +57,7 @@ vis.events.subscribe(vis.events.WIN_STATUS, function(win)
if vis.win == win then
-- mode
table.insert(left_parts, modes[vis.mode])
table.insert(left_parts, mode_string)
-- selection
table.insert(left_parts, selection.number..'/'..#win.selections)
@ -73,7 +83,5 @@ vis.events.subscribe(vis.events.WIN_STATUS, function(win)
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)
win:status(table.concat(left_parts, " "), table.concat(right_parts, " "));
end