mirror of
https://github.com/Ascyii/typstar.git
synced 2026-03-02 09:32:42 +01:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| eb6c219122 | |||
|
|
57e62d11aa | ||
|
|
e0a82ef957 | ||
|
|
459ced0c2b | ||
|
|
eda6de26bb | ||
|
|
dc7fa65a80 | ||
|
|
b49e0262a1 |
@@ -104,10 +104,64 @@ local open_drawing = function(prov)
|
||||
end
|
||||
end
|
||||
|
||||
local function delete_drawing(provider)
|
||||
local cfg = provider[1]
|
||||
local line_num = vim.api.nvim_win_get_cursor(0)[1] - 1
|
||||
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
|
||||
|
||||
-- Find the start and end of the #figure() block containing the filename
|
||||
local start_line, end_line
|
||||
for i = line_num, 0, -1 do
|
||||
if lines[i + 1]:match("^#figure%(") then
|
||||
start_line = i
|
||||
break
|
||||
end
|
||||
end
|
||||
for i = line_num, #lines - 1 do
|
||||
if lines[i + 1]:match("%)$") then
|
||||
end_line = i
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if not start_line or not end_line then
|
||||
print("No #figure() block found on current line")
|
||||
return
|
||||
end
|
||||
|
||||
-- Extract filename from the block
|
||||
local block_text = table.concat(vim.api.nvim_buf_get_lines(0, start_line, end_line + 1, false), "\n")
|
||||
local filename = block_text:match('image%("%s*(.-)%s*"%)')
|
||||
if not filename then
|
||||
print("No image filename found in #figure() block")
|
||||
return
|
||||
end
|
||||
|
||||
local path = vim.fn.expand('%:p:h') .. '/' .. filename
|
||||
local path_export = vim.fn.expand('%:p:h') .. '/' .. filename:match("^(.*)%.")
|
||||
|
||||
-- Delete files if they exist
|
||||
if vim.fn.filereadable(path) == 1 then os.remove(path) end
|
||||
if vim.fn.filereadable(path_export) == 1 then os.remove(path_export) end
|
||||
|
||||
-- Delete the lines of the #figure() block
|
||||
vim.api.nvim_buf_set_lines(0, start_line, end_line + 1, false, {})
|
||||
|
||||
print("Deleted drawing: " .. filename)
|
||||
end
|
||||
|
||||
function M.delete_obsidian_excalidraw() delete_drawing(excalidraw) end
|
||||
|
||||
function M.delete_rnote() delete_drawing(rnote) end
|
||||
|
||||
function M.insert_obsidian_excalidraw() insert_drawing(excalidraw) end
|
||||
|
||||
function M.insert_rnote() insert_drawing(rnote) end
|
||||
|
||||
function M.open_obsidian_excalidraw() open_drawing({ excalidraw }) end
|
||||
|
||||
function M.open_rnote() open_drawing({ rnote }) end
|
||||
|
||||
function M.open_drawing() open_drawing(providers) end
|
||||
|
||||
return M
|
||||
|
||||
@@ -14,7 +14,9 @@ M.setup = function(args)
|
||||
vim.api.nvim_create_user_command('TypstarSmartJumpBack', function() M.smart_jump(-1) end, {})
|
||||
|
||||
vim.api.nvim_create_user_command('TypstarInsertExcalidraw', drawings.insert_obsidian_excalidraw, {})
|
||||
vim.api.nvim_create_user_command('TypstarDeleteExcalidraw', drawings.delete_obsidian_excalidraw, {})
|
||||
vim.api.nvim_create_user_command('TypstarInsertRnote', drawings.insert_rnote, {})
|
||||
vim.api.nvim_create_user_command('TypstarDeleteRnote', drawings.delete_rnote, {})
|
||||
vim.api.nvim_create_user_command('TypstarOpenExcalidraw', drawings.open_obsidian_excalidraw, {})
|
||||
vim.api.nvim_create_user_command('TypstarOpenRnote', drawings.open_rnote, {})
|
||||
vim.api.nvim_create_user_command('TypstarOpenDrawing', drawings.open_drawing, {})
|
||||
|
||||
@@ -19,14 +19,16 @@ local ctheorems = {
|
||||
{ 'def', 'definition' },
|
||||
{ 'exa', 'example' },
|
||||
{ 'rem', 'remark' },
|
||||
{ 'nte', 'note' },
|
||||
{ 'eri', 'experiment' },
|
||||
}
|
||||
|
||||
local wrappings = {
|
||||
{ 'll', '$', '$', '1+1' },
|
||||
{ 'BLD', '*', '*', 'abc' },
|
||||
{ 'ITL', '_', '_', 'abc' },
|
||||
{ 'HIG', '#highlight[', ']', 'abc' },
|
||||
{ 'UND', '#underline[', ']', 'abc' },
|
||||
{ 'll', '$', '$', '' },
|
||||
{ 'BLD', '*', '*', '' },
|
||||
{ 'ITL', '_', '_', '' },
|
||||
{ 'HIG', '#highlight[', ']', '' },
|
||||
{ 'UND', '#underline[', ']', '' },
|
||||
}
|
||||
|
||||
local document_snippets = {}
|
||||
@@ -49,6 +51,7 @@ return {
|
||||
helper.list_snip('dm', '\n$\n\t<>\n$ <>', { helper.visual(1), i(2) }, markup, 1100, { prepend = '\t' }),
|
||||
start('fla', '#flashcard(0)[<>][\n<>\n<>]', { i(1, 'flashcard'), indent_visual(2), cap(1) }, markup),
|
||||
start('flA', '#flashcard(0, "<>")[\n<>\n<>]', { i(1, 'flashcard'), indent_visual(2), cap(1) }, markup),
|
||||
start('TAB', '#table(columns: <>,\n[<>], [<>], <>\n)', { i(1), i(2), i(3), i(4) }, markup),
|
||||
snip('IMP', '$==>>$ ', {}, markup),
|
||||
snip('IFF', '$<<==>>$ ', {}, markup),
|
||||
unpack(document_snippets),
|
||||
|
||||
@@ -32,8 +32,23 @@ return {
|
||||
snip('gt', '>> ', {}, math),
|
||||
snip('le', '<<= ', {}, math),
|
||||
snip('ne', '!= ', {}, math),
|
||||
snip('eel', '&= ', {}, math),
|
||||
snip('ge', '>>= ', {}, math),
|
||||
|
||||
-- custom
|
||||
snip('mm', '- ', {}, math),
|
||||
snip('pl', '+ ', {}, math),
|
||||
snip('nl', '\\ \n<>', {i(1)}, math),
|
||||
snip('pm', '+- ', {}, math),
|
||||
snip('nx', '\\, space ', {}, math),
|
||||
snip('nbx', '\\, quad ', {}, math),
|
||||
snip('deg', 'degree ', {}, math),
|
||||
snip('ta', 'star ', {}, math),
|
||||
snip('del', 'Delta ', {}, math),
|
||||
snip('apr', 'approx ', {}, math),
|
||||
snip('pal', 'parallel ', {}, math),
|
||||
snip('sa', 'space ', {}, math),
|
||||
|
||||
-- operators
|
||||
snip('mak', 'plus.minus ', {}, math),
|
||||
snip('oak', 'plus.o ', {}, math),
|
||||
@@ -43,7 +58,8 @@ return {
|
||||
snip('xx', 'times ', {}, math),
|
||||
snip('oxx', 'times.o ', {}, math),
|
||||
snip('bxx', 'times.square ', {}, math),
|
||||
snip('ff', '(<>) / (<>) <>', { i(1, 'a'), i(2, 'b'), i(3) }, math),
|
||||
snip('ff', '(<>) / (<>) <>', { i(1), i(2), i(3) }, math),
|
||||
snip('nab', 'arrow(nabla) ', {}, math),
|
||||
|
||||
-- subscript/superscript
|
||||
snip('iv', '^(-1) ', {}, math, 500, { wordTrig = false, blacklist = { 'equiv' } }),
|
||||
@@ -76,9 +92,7 @@ return {
|
||||
snip('mt', '|->> ', {}, math),
|
||||
snip('cp', 'compose ', {}, math),
|
||||
snip('iso', 'tilde.equiv ', {}, math),
|
||||
snip('nab', 'nabla ', {}, math),
|
||||
snip('ep', 'exp(<>) ', { i(1, '1') }, math),
|
||||
snip('ccs', 'cases(\n\t<>,\n)', { i(1, '1') }, math),
|
||||
snip('cc', 'cases(\n\t<>\n)\\', { i(1) }, math),
|
||||
snip('([A-Za-z])o([A-Za-z0-9]) ', '<>(<>) ', { cap(1), cap(2) }, math, 100, {
|
||||
maxTrigLength = 4,
|
||||
blacklist = { 'bot ', 'cos ', 'cot ', 'dot ', 'log ', 'mod ', 'not ', 'top ', 'won ', 'xor ' },
|
||||
@@ -94,6 +108,8 @@ return {
|
||||
|
||||
-- integrals
|
||||
snip('it', 'integral ', {}, math),
|
||||
snip('iot', 'integral.vol ', {}, math),
|
||||
snip('ift', 'integral.surf ', {}, math),
|
||||
snip('int', 'integral_(<>)^(<>) ', { i(1, 'a'), i(2, 'b') }, math),
|
||||
snip('oit', 'integral.cont_(<>) ', { i(1, 'C') }, math),
|
||||
snip('dit', 'integral_(<>) ', { i(1, 'Omega') }, math),
|
||||
|
||||
@@ -35,8 +35,10 @@ local operations = { -- first boolean: existing brackets should be kept; second
|
||||
{ 'ub', 'underbrace', '', true, true },
|
||||
{ 'ob', 'overbrace', '', true, true },
|
||||
{ 'ht', 'hat', '', true, true },
|
||||
{ 'ar', 'arrow', '', true, true },
|
||||
{ 'br', 'macron', '', true, true },
|
||||
{ 'dt', 'dot', '', true, true },
|
||||
{ 'dou', 'dot.double', '', true, true },
|
||||
{ 'dia', 'diaer', '', true, true },
|
||||
{ 'ci', 'circle', '', true, true },
|
||||
{ 'td', 'tilde', '', true, true },
|
||||
@@ -98,7 +100,7 @@ local smart_wrap = function(args, parent, old_state, expand)
|
||||
|
||||
-- normal snippet
|
||||
if not visual_disable_normal[trigger] then
|
||||
return s(nil, { t(expand1), i(1, '1+1'), t(expand2) })
|
||||
return s(nil, { t(expand1), i(1), t(expand2) })
|
||||
else
|
||||
return s(nil, t(trigger))
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user