73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/zoom/editor.rb', line 73
def vim(results)
quickfix = Pathname.new("~/.cache/zoom/quickfix").expand_path
source = Pathname.new("~/.cache/zoom/source").expand_path
FileUtils.mkdir_p(quickfix.dirname)
zq = File.open(quickfix, "w")
zs = File.open(source, "w")
vimscript = [
"augroup Zoom",
" autocmd!",
" autocmd FileType qf nnoremap <cr> :.cc<cr>:cclose<cr>",
"augroup END",
"",
"nnoremap <leader>z :copen<cr>",
"nnoremap zn :cn<cr>",
"nnoremap zp :cp<cr>",
""
].join("\n")
zs.write(vimscript)
files = Array.new
results.each do |result|
filename = result.filename if (result.grep_like?)
filename ||= result.contents
lineno = result.lineno
match = result.match
pwd = result.pwd
if (!files.include?("#{pwd}/#{filename}"))
files.push("#{pwd}/#{filename}")
zs.write("#{lineno}\nbnext\n") if (result.grep_like?)
end
if (result.grep_like?)
zq.write("#{pwd}/#{filename}|#{lineno}| #{match}\n")
end
end
zs.write("silent cfile #{quickfix}\n")
zq.close
zs.close
system("#{@editor} -S #{source} #{files.join(" ")}")
FileUtils.rm_f(quickfix)
FileUtils.rm_f(source)
end
|