Compare commits

...

2 Commits

View File

@@ -192,17 +192,10 @@ local function add_global_mark()
end
end
local lfs = require('lfs')
local theme_modification = 0
local last_theme = 'default'
function set_current_theme()
local function set_current_theme()
local path = os.getenv('HOME') .. '/.config/xsettingsd/xsettingsd.conf'
local m = lfs.attributes(path, 'modification')
if m == theme_modification then
return
end
theme_modification = m
local f = io.open(path)
if f then
local s = f:read('*all')
@@ -248,6 +241,39 @@ local function close_next_win()
end
end
local function ensure_last_line_empty()
local size = vis.win.file.size
if size > 0 then
if vis.win.file:content(size - 1, size) ~= '\n' then
vis.win.file:insert(size, '\n')
end
local lines = vis.win.file.lines
if string.find(lines[#lines], '%S') then
lines[#lines + 1] = ''
end
end
end
local function add_note()
local path = vis.win.file.path
local line = path and path .. ':' .. vis.win.selection.line .. ':' .. vis.win.selection.col .. ': ' .. vis.win.file.lines[vis.win.selection.line]
vis:command('o ~/notes/notes.md')
ensure_last_line_empty()
local lines = vis.win.file.lines
lines[#lines + 1] = '## '
local pos = vis.win.file.size - 1
local code, date, err = vis:pipe("date '+%F %T'")
if code ~= 0 then
vis:message(err)
else
lines[#lines + 1] = '* time: ' .. date:gsub('%s+$', '')
end
if line then
lines[#lines + 1] = '* line: ' .. line
end
vis.win.selection.pos = pos
end
vis.events.subscribe(vis.events.INIT, function()
vis:command('set autoindent')
@@ -353,9 +379,7 @@ vis.events.subscribe(vis.events.INIT, function()
vis:command('o ~/.config/vis/global-marks.txt')
end, 'global marks: edit')
vis:map(vis.modes.NORMAL, ' n', function()
vis:command('o ~/notes/notes.md')
end, 'add note')
vis:map(vis.modes.NORMAL, ' n', add_note)
vis:map(vis.modes.NORMAL, ' N', function()
search(fzf_reload(ripgrep .. ' --with-filename {q} ~/notes'))