|
Revision 12318, 0.7 kB
(checked in by ujihisa, 5 years ago)
|
|
lang/vim/misc/quicklook.vim: fix bug
|
| Line | |
|---|
| 1 | command Quicklook :call <SID>QuicklookStart() |
|---|
| 2 | |
|---|
| 3 | function! s:QuicklookStart() |
|---|
| 4 | ruby quicklook_run |
|---|
| 5 | endfunction |
|---|
| 6 | |
|---|
| 7 | ruby << EOF |
|---|
| 8 | # view :: String -> Bool (with qlmanage) |
|---|
| 9 | def view(filename_like) |
|---|
| 10 | filename = filename_like |
|---|
| 11 | filename = File.expand_path(filename) |
|---|
| 12 | unless FileTest.exists? filename |
|---|
| 13 | VIM.message "#{filename} not found" |
|---|
| 14 | return false |
|---|
| 15 | end |
|---|
| 16 | fork { |
|---|
| 17 | pid = fork { |
|---|
| 18 | STDERR.reopen(File.open('/dev/null', 'w')) |
|---|
| 19 | exec ['qlmanage']*2, '-p', filename |
|---|
| 20 | } |
|---|
| 21 | sleep 2 |
|---|
| 22 | Process.kill(:TERM, pid) |
|---|
| 23 | } |
|---|
| 24 | true |
|---|
| 25 | end |
|---|
| 26 | |
|---|
| 27 | def quicklook_run |
|---|
| 28 | VIM::Buffer.current.line.gsub(/^\s+/, '').split(/\s+/).each do |filename_like| |
|---|
| 29 | view(filename_like) || |
|---|
| 30 | view(File.dirname(VIM::Buffer.current.name) + filename_like) |
|---|
| 31 | end |
|---|
| 32 | end |
|---|
| 33 | EOF |
|---|