Compare commits

...

5 Commits

5 changed files with 119 additions and 18 deletions

View File

@@ -263,6 +263,7 @@ fi
exec fzf --query "$3" \
--prompt "$prompt" \
--header-label "$label" \
--multi \
--ansi \
--delimiter : \
--ghost ' (Use alt-? for help)' \

View File

@@ -0,0 +1,31 @@
-- Copyright 2006-2025 Mitchell. See LICENSE.
-- go with SQL LPeg lexer.
local lexer = lexer
local starts_line = lexer.starts_line
local B, P, S = lpeg.B, lpeg.P, lpeg.S
local lex = lexer.new(..., {inherit = lexer.load('go')})
local open_brace = lex:tag(lexer.OPERATOR, P('{'))
local close_brace = lex:tag(lexer.OPERATOR, P('}'))
local backtick = lex:tag(lexer.CODE, P('`'))
local ws = lex:get_rule('whitespace')
local tpl = lexer.new("template")
tpl:add_rule('keyword', lex:tag(lexer.KEYWORD, lexer.word_match('if else end with range break define continue template block')))
tpl:add_rule('constant', lex:get_rule('constant'))
tpl:add_rule('operator', lex:get_rule('operator') + lex:tag(lexer.OPERATOR, S('$')))
local func = lexer.after_set(' \t\n{|', lexer.word)
tpl:add_rule('function', lex:tag(lexer.FUNCTION, func))
tpl:add_rule('identifier', lex:get_rule('identifier'))
tpl:add_rule('string', lex:get_rule('string'))
tpl:add_rule('number', lex:get_rule('number'))
local sql = lexer.load('sql')
local sql_kwd = lexer.word_match('ALTER CREATE DELETE DROP GRANT INSERT SELECT UPDATE WITH')
sql:embed(tpl, open_brace * open_brace, close_brace * close_brace)
lex:embed(sql, backtick * #(ws^0 * sql_kwd), backtick)
return lex

View File

@@ -1,6 +1,6 @@
-- Eight-color scheme
local lexers = vis.lexers
lexers.STYLE_DEFAULT ='back:#dae4f1,fore:#1f212e'
lexers.STYLE_DEFAULT ='back:#f2f2f3,#e0e5eb,fore:#1f212e'
lexers.STYLE_NOTHING = ''
lexers.STYLE_ATTRIBUTE = 'fore:#a1a3aa,bold'
lexers.STYLE_CLASS = 'fore:yellow,bold'
@@ -21,7 +21,7 @@ lexers.STYLE_TAG = 'fore:#705943,bold'
lexers.STYLE_TYPE = 'fore:#7461d1,bold'
lexers.STYLE_VARIABLE = 'fore:#8c5eba,bold'
lexers.STYLE_WHITESPACE = ''
lexers.STYLE_EMBEDDED = 'back:#2d3353,bold'
lexers.STYLE_EMBEDDED = 'back:#e0e5eb,bold'
lexers.STYLE_IDENTIFIER = ''
lexers.STYLE_LINENUMBER = ''

View File

@@ -23,6 +23,10 @@ local plugins = {
plug.init(plugins, true)
vis.ftdetect.filetypes.go_ext = vis.ftdetect.filetypes.go
vis.ftdetect.filetypes.go = nil
plug.plugins.lspc.ls_map.go_ext = plug.plugins.lspc.ls_map.go
vis.ftdetect.filetypes.templ = {
ext = { "%.templ$" },
}
@@ -45,10 +49,16 @@ local function nil_or_tonumber(s)
end
local function open_file_pos(line, open_cmd)
local iter = string.gmatch(line, '[^:]+')
local iter = line:gmatch('[^:]+')
local file = iter()
local line_num = nil_or_tonumber(iter())
local ln = iter()
local col = nil_or_tonumber(iter()) or 1
local i = ln and ln:find(' ')
if i then
ln = ln:sub(0, i)
col = 1
end
local line_num = nil_or_tonumber(ln)
if open_cmd ~= 'e' or vis.win.file ~= file then
open_file(file, open_cmd)
end
@@ -57,10 +67,13 @@ local function open_file_pos(line, open_cmd)
end
end
local function open_file_current_line(open_cmd)
local function open_file_current_line(open_cmd, keys)
local line = vis.win.file.lines[vis.win.selection.line]
vis:info(line)
open_file_pos(line)
if keys then
vis:feedkeys(keys)
end
open_file_pos(line, open_cmd)
end
local function escape_and_quoted(s)
@@ -80,23 +93,33 @@ end
local function fzf_sh(arg)
action = function(out)
if (out:find('\n') or #out) == #out then
open_file_pos(out, vis.win.file.modified and 'o' or 'e')
else
vis:message(out)
end
end
local home = os.getenv('HOME')
local path = vis.win.file.path or ''
local dir = path:match('^.*/') or ''
local reg = ''
if reg ~= '"' then
if vis.register ~= '"' then
reg = string.gsub(vis.registers[vis.register][1], '%z', '')
end
local cmd = home .. '/.config/vis/fzf.sh ' .. escape_and_quoted(arg) .. ' ' .. escape_and_quoted(dir) .. ' ' .. escape_and_quoted(reg)
local cmd = home ..
'/.config/vis/fzf.sh ' ..
escape_and_quoted(arg) .. ' ' .. escape_and_quoted(dir) .. ' ' .. escape_and_quoted(reg)
cmd_action(cmd, action)
end
local function search(cmd, action)
if action == nil then
action = function(out)
if (out:find('\n') or #s) == #s then
open_file_pos(out, 'e')
else
vis:message(out)
end
end
end
if cmd:match('^fzf ') and vis.register ~= '"' then
@@ -181,6 +204,32 @@ end
local ripgrep = 'rg --column --line-number --color=always --smart-case'
local function close_prev_win()
vis:feedkeys('<vis-window-prev>')
if vis.win == win then
vis:info('Last window')
elseif not vis.win:close() then
if vis.win.file.modified then
vis:info('No write since last change')
else
vis:command('q')
end
end
end
local function close_next_win()
vis:feedkeys('<vis-window-next>')
if vis.win == win then
vis:info('Last window')
elseif not vis.win:close() then
if vis.win.file.modified then
vis:info('No write since last change')
else
vis:command('q')
end
end
end
vis.events.subscribe(vis.events.INIT, function()
vis:command('set autoindent')
@@ -190,8 +239,8 @@ vis.events.subscribe(vis.events.INIT, function()
vis:map(vis.modes.NORMAL, '<M-k>', '<vis-window-prev>')
vis:map(vis.modes.NORMAL, '<M-j>', '<vis-window-next>')
vis:map(vis.modes.NORMAL, ' K', '<vis-window-prev>:q<Enter>', 'close previous window')
vis:map(vis.modes.NORMAL, ' J', '<vis-window-next>:q<Enter><vis-window-prev>', 'close next window')
vis:map(vis.modes.NORMAL, ' K', close_prev_win)
vis:map(vis.modes.NORMAL, ' J', close_next_win)
vis:map(vis.modes.NORMAL, ' l[', ':lspc-prev-diagnostic<Enter>')
vis:map(vis.modes.NORMAL, ' l]', ':lspc-next-diagnostic<Enter>')
@@ -246,11 +295,23 @@ vis.events.subscribe(vis.events.INIT, function()
vis:command('fzfmru')
end, 'fzf recent')
vis:map(vis.modes.NORMAL, 'gf', function()
open_file_current_line('o')
end, 'open file from current line (with line and col')
vis:map(vis.modes.NORMAL, ' w', function()
open_file_current_line('e')
end, 'open file from current line in current window (with optional line and col)')
vis:map(vis.modes.NORMAL, ' cd', function()
vis:map(vis.modes.NORMAL, ' o', function()
open_file_current_line('o')
end, 'open file from current line in new window (with optional line and col)')
vis:map(vis.modes.NORMAL, ' k', function()
open_file_current_line('e', '<vis-window-prev>')
end, 'open file from current line in above window (with optional line and col)')
vis:map(vis.modes.NORMAL, ' j', function()
open_file_current_line('e', '<vis-window-next>')
end, 'open file from current line in below window (with optional line and col)')
vis:map(vis.modes.NORMAL, ' c', function()
search('zoxide query -l | fzf', function(path)
vis:command('cd ' .. path)
end)
@@ -296,3 +357,11 @@ end)
vis.events.subscribe(vis.events.WIN_OPEN, function(win)
vis:command('set relativenumber')
end)
vis.events.subscribe(vis.events.FILE_SAVE_PRE, function(file, path)
if path:find('[.]go$') then
-- formatting is async, so when reformated you should write file again
vis:command('lspc-format')
end
return true
end)

View File

@@ -80,7 +80,7 @@ st.color13: #8f248f
st.color14: #509595
st.color15: #dbdff0
#else
st.background: #dae4f1
st.background: #f2f2f3
st.foreground: #1f212e
st.cursorColor: #bf8040
st.reverse-cursor: #1f212e