I wanted to make Firefox refresh automagically & preserve its scroll
position when I save html files (and CSS) in Vim. That led me to
MozRepl today... and so I created this joyful little hack to reduce
repetitive keystrokes.
Clearly, this integration is no where near as fancy as the Emacs
MozRepl binding, but this one feature alone makes it super useful
to me -- and to you too, I hope. Feel free to improve it & post what
you've done.
Here's the relevant excerpt from my .vimrc
"----------------------------------------------------------------------------------------------------
" Make *.html (and friends) to refresh firefox using MozRepl. on
save
"----------------------------------------------------------------------------------------------------
autocmd BufWriteCmd *.html,*.css,*.gtpl : call Refresh_firefox()
"----------------------------------------------------------------------------------------------------
"
" When editing an .html, .css, or .gtpl template file, make Firefox
" refresh once the buffer is saved, preserving the current scroll
offset.
"
" Requires:
" [2] MozRepl must be installed & running in Firefox
"
" [1] Netcat (nc) must be on your path.
"
" [3] Firefox & vim are both on the same machine (localhost).
" Actually, you can fix that if you want by adjusting
" this script + your MosRepl settings but it's probably
" a bit of a security risk.
"
" Ok, here's how it works:
"
" I use echo to send a dopey little MosRepl script (see below)
" to Firefox. Netcat (nc) has a nice option to disconnect
" after 1 second (-q 1), so I'm using that. All the output
" is tossed away (2>&1 > /dev/null) because MozRepl is chatty.
"
" Global variables are used (vimXo, vimYo) to capture the X and Y
" offset of the web page for vim. Maybe there's a way to not use
" a global, but I don't know that that might be. Anyway, after
saving
" the buffer and reloading the browser, scroll to the proper X,Y
offset.
"
" See also:
"
http://wiki.github.com/bard/mozrepl/tutorial
"
http://forums.whirlpool.net.au/forum-replies-archive.cfm/495300.html
"
" Aside: Line continuation in vimscript is a bit weird;
" it comes at start of the line you want merged,
" rather than at the end of the line being broken.
"----------------------------------------------------------------------------------------------------
function! Refresh_firefox()
if &modified
write
silent !echo 'vimYo = content.window.pageYOffset;
\ vimXo = content.window.pageXOffset;
\ BrowserReload();
\ content.window.scrollTo(vimXo,vimYo);
\ repl.quit();' |
\ nc -q 1 localhost 4242 2>&1 > /dev/null
endif
endfunction
--
You received this message because you are subscribed to the Google Groups "MozLab" group.
To post to this group, send email to
moz...@googlegroups.com.
To unsubscribe from this group, send email to
mozlab+un...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/mozlab?hl=en.