summaryrefslogtreecommitdiff
path: root/ftplugin/hackernews.vim
diff options
context:
space:
mode:
Diffstat (limited to 'ftplugin/hackernews.vim')
-rw-r--r--ftplugin/hackernews.vim30
1 files changed, 26 insertions, 4 deletions
diff --git a/ftplugin/hackernews.vim b/ftplugin/hackernews.vim
index b5d9372..023ac99 100644
--- a/ftplugin/hackernews.vim
+++ b/ftplugin/hackernews.vim
@@ -8,12 +8,34 @@
" Version: 0.1.1
+if !has('python')
+ echo "HackerNews.vim Error: Requires Vim compiled with +python"
+ finish
+endif
+
if !exists("g:hackernews_marks")
let g:hackernews_marks = {}
endif
-noremap <buffer> o :python hacker_news_link()<cr>
-noremap <buffer> O :python hacker_news_link(external=True)<cr>
-noremap <buffer> u u:python recall_pos()<cr>
-noremap <buffer> <C-r> <C-r>:python recall_pos()<cr>
+" Import Python code
+execute "python import sys"
+execute "python sys.path.append(r'" . expand("<sfile>:p:h") . "')"
+
+python << EOF
+if 'hackernews' not in sys.modules:
+ import hackernews
+else:
+ # Reload python module to avoid errors when updating plugin
+ hackernews = reload(hackernews)
+EOF
+
+
+" Load front page
+execute "python hackernews.main()"
+
+
+noremap <buffer> o :python hackernews.link()<cr>
+noremap <buffer> O :python hackernews.link(external=True)<cr>
+noremap <buffer> u u:python hackernews.recall_pos()<cr>
+noremap <buffer> <C-r> <C-r>:python hackernews.recall_pos()<cr>