Browse Source

closer to basic functionality

main
Noah Hall 1 year ago
parent
commit
10618972c5
2 changed files with 45 additions and 20 deletions
  1. +24
    -7
      plugin/vim-checkmark.vim
  2. +21
    -13
      python/vim_checkmark.py

+ 24
- 7
plugin/vim-checkmark.vim View File

@ -13,30 +13,47 @@ let g:loaded_VimCheckmark = 1
let s:keepcpo = &cpo
set cpo&vim
if !exists("g:checkmark_vertical_split")
let g:checkmark_vertical_split = 1
endif
if !exists("g:VimCheckmark_DebugMode")
let g:VimCheckmark_DebugMode = 0
endif
" let's try stuff!!
" setup python
let s:plugin_root = fnamemodify(resolve(expand('<sfile>:p')), ':h')
python << EOF
python3 << EOF
import sys
from os.path import normpath, join
import vim
plugin_root = vim.eval('s:plugin_root')
python_root = normpath(join(plugin_root, '..', 'python'))
sys.path.insert(0, python_root)
import vim_checkmark
EOF
" probably doesn't even load lol
function! checkmark
:terminal python vim_checkmark @%
function! s:Checkmark()
let s:python_pluginpath = s:plugin_root . "/../python/vim_checkmark.py"
echo s:python_pluginpath
term_start("python3 /home/noah/projects/vim-checkmark/python/vim_checkmark.py /home/noah/wiki/Drafts.md", {
\ "term_name": %
\ "vertical": g:checkmark_vertical_split
\ "in_io:" "buffer",
\ "in_buf": bufnr()
\})
endfunction
" commands
nmap <unique> <Leader>C <Plug>Checkmark
nnoremap <unique> <script> <Plug>Checkmark <SID>Checkmark
nnoremap <SID>Checkmark :call <SID>Checkmark()<CR>
command Checkmark <Plug>Checkmark
let &cpo = s:keepcpo
unlet s:keepcpo

+ 21
- 13
python/vim_checkmark.py View File

@ -1,6 +1,15 @@
#!/usr/bin/python3
import sys
import fileinput
try:
import vim
DEBUG = vim.eval("g:VimCheckmark_DebugMode")
except ModuleNotFoundError:
import os
DEBUG = os.environ.get("CHECKMARK_DEBUG")
if not DEBUG:
raise NotImplementedError("this library only works inside vim!")
from rich.markdown import Markdown
from textual import events
@ -13,25 +22,24 @@ class VimCheckmark(App):
async def on_load(self) -> None:
"""set up"""
try:
self.path = sys.argv[-1]
except IndexError:
raise()
# self.path = "STDIN"
#
# if self.path == "STDIN":
# for line in fileinput.input():
await self.bind("q", "quit", "Quit")
async def on_mount(self, event: events.Mount) -> None:
"""handle rendering"""
body = ScrollView(gutter=1)
await self.view.dock(body)
with open(self.path, 'rb') as fh:
output = Markdown(fh.read(), hyperlinks=True)
text = ''
with fileinput.input() as fh:
for line in fh:
text = text + line + "\n"
output = Markdown(text, hyperlinks=True)
await body.update(output)
def main() -> None:
"""simple container func"""
def checkmark() -> None:
VimCheckmark.run()
if __name__ == "__main__":
VimCheckmark.run()

Loading…
Cancel
Save