Skip to content

Commit

Permalink
Moved common variables up; interoperable browsers;
Browse files Browse the repository at this point in the history
Fixed unix background bug
  • Loading branch information
JamshedVesuna committed May 13, 2015
1 parent ae4d034 commit a9971e1
Showing 1 changed file with 15 additions and 20 deletions.
35 changes: 15 additions & 20 deletions plugin/vim-markdown-preview.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,32 +19,30 @@ 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)
call system('xdotool windowactivate ' . chrome_wid)
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
Expand All @@ -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
Expand All @@ -65,32 +62,30 @@ 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)
call system('xdotool windowactivate ' . chrome_wid)
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
Expand Down

0 comments on commit a9971e1

Please sign in to comment.