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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
# File 'lib/zoom/editor.rb', line 85
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|
if (result.grep_like?)
if (result.filename.start_with?("/"))
filename = result.filename
else
filename = result.pwd + "/" + result.filename
end
else
if (result.contents.start_with?("/"))
filename = result.contents
else
filename = result.pwd + "/" + result.contents
end
end
lineno = result.lineno
match = result.match
if (!files.include?(filename))
files.push(filename)
zs.write("#{lineno}\nbnext\n") if (result.grep_like?)
end
if (result.grep_like?)
zq.write("#{filename}:#{lineno}: #{match}\n")
end
end
zs.write("silent cfile #{quickfix}\n")
zq.close
zs.close
system(
"#{@editor} #{@flags} -S #{source} '#{files.join("' '")}'"
)
FileUtils.rm_f(quickfix)
FileUtils.rm_f(source)
end
|