summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--.vim/after/ftplugin/markdown.lua40
-rw-r--r--.vim/lua/lsp.lua6
-rw-r--r--.vim/lua/zk.lua41
3 files changed, 87 insertions, 0 deletions
diff --git a/.vim/after/ftplugin/markdown.lua b/.vim/after/ftplugin/markdown.lua
new file mode 100644
index 0000000..c0796b8
--- /dev/null
+++ b/.vim/after/ftplugin/markdown.lua
@@ -0,0 +1,40 @@
+local nnoremap = require('astronauta.keymap').nnoremap
+
+vim.opt.foldlevel = 1
+vim.opt.spell = true
+
+vim.fn.matchadd('Conceal', '\\[ \\]', 0, -1, { conceal = '☐' })
+vim.fn.matchadd('Conceal', '\\[x\\]', 0, -1, { conceal = '☑' })
+vim.fn.matchadd('Conceal', '\\[-\\]', 0, -1, { conceal = '☒' })
+vim.fn.matchadd('Conceal', '\\[\\]', 0, -1, { conceal = '🞕' })
+
+nnoremap {
+  '<Plug>Markdown_OpenUrlUnderCursor',
+  function() require('misc').open_under_cursor('url-launcher') end,
+}
+
+nnoremap { '<leader>zn', function() require('zk').new() end }
+nnoremap { '<leader>zi', function() require('zk').index() end }
+vim.cmd [[ command! -nargs=* ZettelkastenNew lua require('zk').new(nil, <f-args>) ]]
+
+-- markdown list folding
+local function calc_lvl(line)
+  local i, k = string.find(line, "^[ ]*[*-]")
+  if i and k then return ((k-i) / vim.fn.shiftwidth()) + 1 end
+  return 0
+end
+function _G.markdown_lst_foldexpr(lnum)
+  local lines = vim.api.nvim_buf_get_lines(0, lnum-1, lnum+1, false)
+  if not #lines == 2 then
+    return '='
+  end
+  local lvl_c = calc_lvl(lines[1])
+  local lvl_n = calc_lvl(lines[2])
+  if lvl_c > 0 then
+    if lvl_c < lvl_n then return '>'..lvl_c end -- starts
+    if lvl_c > lvl_n then return '<'..lvl_c end -- ends
+  end
+  return '='
+end
+vim.opt.foldlevel = 0
+vim.opt.foldexpr = 'v:lua.markdown_lst_foldexpr(v:lnum)'
diff --git a/.vim/lua/lsp.lua b/.vim/lua/lsp.lua
index f5fe263..9822e2c 100644
--- a/.vim/lua/lsp.lua
+++ b/.vim/lua/lsp.lua
@@ -191,6 +191,12 @@ local setup = function()
     capabilities = caps,
   }
 
+  lsp.zk.setup {
+    on_attach = my_attach,
+    capabilities = caps,
+    root_dir = lsp.util.root_pattern('.zk/'),
+  }
+
 end
 
 return {
diff --git a/.vim/lua/zk.lua b/.vim/lua/zk.lua
new file mode 100644
index 0000000..4cd8389
--- /dev/null
+++ b/.vim/lua/zk.lua
@@ -0,0 +1,41 @@
+
+local function zk_new(path, title_dir)
+  path = path or vim.loop.cwd()
+  if not (path and #path > 0) then return end
+
+  title_dir = title_dir or vim.fn.input('New Zettel: ')
+  local o = {}
+  local parts = vim.split(title_dir, '/')
+  if not parts[2] then
+    o.title = vim.trim(parts[1])
+  else
+    o.title = vim.trim(parts[2])
+    o.dir = vim.trim(parts[1])
+  end
+
+  vim.lsp.buf_request(0, 'workspace/executeCommand',
+    {
+      command = 'zk.new',
+      arguments = { path, o },
+    },
+    function(_, _, result)
+      vim.lsp.util.jump_to_location{
+        uri = vim.uri_from_fname(result.path),
+        range = {start={line=2, character=0}},
+      }
+      vim.cmd('startinsert')
+    end,
+  )
+end
+
+local function zk_index(path)
+  path = path or vim.loop.cwd()
+  vim.lsp.buf.execute_command {
+    command = 'zk.index', arguments = {path, nil},
+  }
+end
+
+return {
+  new = zk_new,
+  index = zk_index,
+}