From a9971e1051efd238c7a77f7d7af96eb33cdb6fb9 Mon Sep 17 00:00:00 2001 From: JamshedVesuna Date: Wed, 13 May 2015 07:51:38 -0700 Subject: [PATCH] Moved common variables up; interoperable browsers; Fixed unix background bug --- plugin/vim-markdown-preview.vim | 35 ++++++++++++++------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/plugin/vim-markdown-preview.vim b/plugin/vim-markdown-preview.vim index a26b483..9aa8f98 100644 --- a/plugin/vim-markdown-preview.vim +++ b/plugin/vim-markdown-preview.vim @@ -3,11 +3,12 @@ " git@github.com:JamshedVesuna/vim-markdown-preview.git "============================================================ +let b:REMOVE_TEMP_FILE = 0 "To remove the temp file, set to 1 +let b:vim_markdown_preview_browser = 'Google Chrome' + function! Vim_Markdown_Preview() - let BROWSER = 'google-chrome' let OSNAME = 'Unidentified' - let REMOVE_TEMP_FILE = 0 "To remove the temp file, set to 1 if has('win32') " Not yet used @@ -18,17 +19,15 @@ function! Vim_Markdown_Preview() endif if has('mac') let OSNAME = 'mac' - let BROWSER = 'safari' endif let curr_file = expand('%:p') call system('markdown ' . curr_file . ' > /tmp/vim-markdown-preview.html') - if OSNAME == 'unix' && BROWSER == 'google-chrome' - let chrome_wid = system("xdotool search --name 'vim-markdown-preview.html - Google Chrome'") + if OSNAME == 'unix' + let chrome_wid = system("xdotool search --name 'vim-markdown-preview.html - " . b:vim_markdown_preview_browser . "'") if !chrome_wid - "sleep 300m - call system('see /tmp/vim-markdown-preview.html & > /dev/null &') + call system('see /tmp/vim-markdown-preview.html &> /dev/null &') else let curr_wid = system('xdotool getwindowfocus') call system('xdotool windowmap ' . chrome_wid) @@ -36,14 +35,14 @@ function! Vim_Markdown_Preview() call system("xdotool key 'ctrl+r'") call system('xdotool windowactivate ' . curr_wid) endif - "sleep 700m endif - if OSNAME == 'mac' && BROWSER == 'safari' + if OSNAME == 'mac' call system('open -g /tmp/vim-markdown-preview.html') endif - if REMOVE_TEMP_FILE + if b:REMOVE_TEMP_FILE + sleep 200m call system('rm /tmp/vim-markdown-preview.html') endif endfunction @@ -52,9 +51,7 @@ endfunction "Renders html locally and displays images function! Vim_Markdown_Preview_Local() - let BROWSER = 'google-chrome' let OSNAME = 'Unidentified' - let REMOVE_TEMP_FILE = 0 "To remove the temp file, set to 1 if has('win32') " Not yet used @@ -65,17 +62,15 @@ function! Vim_Markdown_Preview_Local() endif if has('mac') let OSNAME = 'mac' - let BROWSER = 'safari' endif let curr_file = expand('%:p') call system('markdown ' . curr_file . ' > ' . curr_file . '.html') - if OSNAME == 'unix' && BROWSER == 'google-chrome' - let chrome_wid = system("xdotool search --name '". curr_file . ".html - Google Chrome'") + if OSNAME == 'unix' + let chrome_wid = system("xdotool search --name '". curr_file . ".html - " . b:vim_markdown_preview_browser . "'") if !chrome_wid - "sleep 300m - call system('see ' . curr_file . '.html & > /dev/null &') + call system('see ' . curr_file . '.html &> /dev/null &') else let curr_wid = system('xdotool getwindowfocus') call system('xdotool windowmap ' . chrome_wid) @@ -83,14 +78,14 @@ function! Vim_Markdown_Preview_Local() call system("xdotool key 'ctrl+r'") call system('xdotool windowactivate ' . curr_wid) endif - "sleep 700m endif - if OSNAME == 'mac' && BROWSER == 'safari' + if OSNAME == 'mac' call system('open -g ' . curr_file . '.html') endif - if REMOVE_TEMP_FILE + if b:REMOVE_TEMP_FILE + sleep 200m call system('rm ' . curr_file . '.html') endif endfunction -- 2.45.2