From 353a05e29dacb8c7f8c2d9ce31336d96dd65918a Mon Sep 17 00:00:00 2001 From: ryanss Date: Tue, 10 Feb 2015 10:14:09 -0500 Subject: Wait for :HackerNews command to load python code Fixes #22 Once you import a python module into an instance of vim it does not get reloaded when a plugin manager updates the plugin. This can cause errors when, for example, a new function is added to the python module and updated vim code is trying to call it. This commit does two things: 1) Does not load the python code until the :HackerNews command is called. There is no need to load the python code during vim startup if the plugin will not be used. 2) Each time the :HackerNews command is issued and a .hackernews buffer is opened the python code is reloaded to avoid the errors previously mentioned. --- ftplugin/hackernews.vim | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'ftplugin/hackernews.vim') 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 o :python hacker_news_link() -noremap O :python hacker_news_link(external=True) -noremap u u:python recall_pos() -noremap :python recall_pos() +" Import Python code +execute "python import sys" +execute "python sys.path.append(r'" . expand(":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 o :python hackernews.link() +noremap O :python hackernews.link(external=True) +noremap u u:python hackernews.recall_pos() +noremap :python hackernews.recall_pos() -- cgit v1.2.3