Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 770 lines (660 sloc) 25.877 kb
f854a38 @dfishburn Version 4.0
dfishburn authored
1 " WhatMissing.vim - Shows what is missing between 2 buffers
2 " ---------------------------------------------------------------
e5e41bc @dfishburn Version 5.0
dfishburn authored
3 " Version: 5.0
f854a38 @dfishburn Version 4.0
dfishburn authored
4 " Authors: David Fishburn <dfishburn dot vim at gmail dot com>
e5e41bc @dfishburn Version 5.0
dfishburn authored
5 " Last Modified: 2012 Oct 17
f854a38 @dfishburn Version 4.0
dfishburn authored
6 " Homepage: http://vim.sourceforge.net/script.php?script_id=1108
7 " GetLatestVimScripts: 1108 1 :AutoInstall: WhatsMissing.vim
8
9 if exists('g:loaded_whatsmissing_auto')
10 finish
11 endif
e5e41bc @dfishburn Version 5.0
dfishburn authored
12 let g:loaded_whatsmissing_auto = 50
f854a38 @dfishburn Version 4.0
dfishburn authored
13
14 " Turn on support for line continuations when creating the script
15 let s:cpo_save = &cpo
16 set cpo&vim
17
18 let s:wm_buffer_lines = 10
19 let s:wm_matching_cnt = 0
20 let s:wm_checked_cnt = 0
21 let s:wm_org_bufnr = 0
22 let s:wm_missing_bufnr = 0
23 let s:wm_debug = 0
24 let s:wm_find_bufnr = 0
25 let s:wm_find_mode = 'word'
26 let s:wm_find_filetype = ''
27 let s:wm_filename = ''
28 let s:wm_ignore_case = ''
29 let s:wm_ignore_whitespace = ''
30 let s:wm_unescaped_findstr = ''
31 let s:wm_missing_buf_name = "WhatsMissing"
32 let s:wm_options = "mode,ignore_case,ignore_whitespace,debug"
33 let s:wm_modes = "word,line"
34
35 function! whatsmissing#WM_GetOption(option)
36 if s:wm_options !~? '\<'.a:option.'\>'
37 call s:WM_WarningMsg(
38 \ "Invalid option, choices are: " .
39 \ s:wm_options
40 \ )
41 return -1
42 endif
43
44 if a:option == 'mode'
45 let value = a:option.'='.s:wm_find_mode
46 elseif a:option == 'ignore_case'
47 let value = a:option.'='.
48 \ (s:wm_ignore_case ==# '' ? ' ' :
49 \ (s:wm_ignore_case ==# '\c' ? '1' : '0' ) )
50 elseif a:option == 'ignore_whitespace'
51 let value = a:option.'='.(s:wm_ignore_whitespace ==# '' ? '0' : '1' )
52 elseif a:option == 'debug'
53 let value = a:option.'='.s:wm_debug
54 else
55 let value = 'Unknown option: a:option'
56 endif
57
58 return value
59 endfunction
60
61 function! whatsmissing#WM_SetOption(option)
62 let opt_name = matchstr(a:option, '^.\{-}\ze=' )
63 let opt_value = matchstr(a:option, '=\zs.\{-}\s*$' )
64
65 if s:wm_options !~? '\<'.opt_name.'\>'
66 call s:WM_WarningMsg(
67 \ "Invalid option, choices are: " .
68 \ s:wm_options
69 \ )
70 return -1
71 endif
72
73 if opt_name == 'mode'
74 if s:wm_modes !~? '\<'.opt_value.'\>'
75 call s:WM_WarningMsg(
76 \ "Invalid mode, choices are: " .
77 \ s:wm_modes
78 \ )
79 return -1
80 else
81 let s:wm_find_mode = opt_value
82 endif
83 elseif opt_name == 'ignore_case'
84 let s:wm_ignore_case = (opt_value ==# '1' ? '\c' : '\C' )
85 elseif opt_name == 'ignore_whitespace'
86 let s:wm_ignore_whitespace = (opt_value ==# '1' ? '\s*' : '' )
87 elseif opt_name == 'debug'
88 let s:wm_debug = opt_value
89 endif
90
91 return 1
92 endfunction
93
94 function! whatsmissing#WhatsNotMissing(...) range
95 let compareTo = '""'
96 if a:0 > 0
97 let compareTo = a:1
98 endif
99
100 let askPrompt = '"1"'
101 if a:0 > 2
102 let askPrompt = a:3
103 endif
104
105 exec a:firstline.','.a:lastline.'WhatsMissing '.compareTo.' 0 '.askPrompt
106 endfunction
107
108 function! whatsmissing#WhatsMissing(...) range
109 if &hidden == 0
110 call s:WM_WarningMsg(
111 \ "Cannot search other buffers with :set nohidden"
112 \ )
113 return -1
114 endif
115
116 let s:wm_org_bufnr = bufnr("%")
117 let rc = -1
118
119 let compareTo = ""
120 if a:0 > 0
121 let compareTo = a:1
122 endif
123
124 if strlen(substitute(compareTo, '"' ,'', 'g')) == 0
125 let response = confirm("SOURCE: Current buffer contains a list of words" .
126 \ " or lines to check if they exist in the TARGET.\nThe " .
127 \ " target is typically a real file (i.e. Vim syntax file)"
128 \ )
129 let response = 1
130 if has("browse")
131 let response = confirm("TARGET: Do you want to specify a file/buffer" .
132 \ " or browse for the file?",
133 \ "&File/Buffer\n&Browse",
134 \ 1
135 \ )
136 endif
137
138 if response == 1
139 let msg = "TARGET: Enter one of the following:" .
140 \ "\n- buffer #" .
141 \ "\n- buffer name" .
142 \ "\n- filename (absolute|relative)\n"
143 let compareTo = inputdialog(msg)
144
145 if strlen(substitute(compareTo, '"' ,'', 'g')) == 0
146 call s:WM_WarningMsg(
147 \ "Invalid entry"
148 \ )
149 return -1
150 endif
151
152 elseif response == 2
153 if has("browse")
154 let compareTo = browse(0,"WhatsMissing Compare To", "", "")
155 endif
156 endif
157 endif
158
159 let compareTo = substitute(compareTo, '^\s*\(.\{-}\)\s*$', '\1', '')
160 if match(compareTo, '\D') == -1
161 let rc = s:WM_SetBufNbr( compareTo )
162 else
163 let rc = s:WM_SetFileName( compareTo )
164 endif
165
166 if rc == -1
167 return -1
168 endif
169
170 call s:WM_GetFindBufferOptions()
171
172 if a:0 > 1
173 let check_for_missing = a:2
174 else
175 let check_for_missing = 1
176 endif
177
178 let ask_prompt = 1
179 if a:0 > 2
180 if a:3 == '0'
181 let ask_prompt = 0
182 endif
183 endif
184
185 if ask_prompt == 1
186 call s:WM_PromptOptions()
187 endif
188
189 " Prevent the alternate buffer (<C-^>) from being set to this
190 " temporary file
191 let l:old_cpoptions = &cpoptions
192 setlocal cpo-=a
193 setlocal cpo-=A
194 let saveReg = @"
195 " save previous search string
196 let saveSearch = @/
197 let saveZ = @z
198
199 " Disable all autocommands and events since we will be
200 " flipping between 3 buffers in rapid succession.
201 " If these events are not disabled, this can take
202 " a very long time
203 let l:old_eventignore = &eventignore
204 set eventignore+=BufNewFile,BufReadPre,BufRead,BufReadPost,BufReadCmd
205 set eventignore+=BufFilePre,BufFilePost,FileReadPre,FileReadPost
206 set eventignore+=FileReadCmd,FilterReadPre,FilterReadPost,FileType,Syntax
207 set eventignore+=StdinReadPre,StdinReadPost,BufWrite,BufWritePre
208 set eventignore+=BufWritePost,BufWriteCmd,FileWritePre,FileWritePost
209 set eventignore+=FileWriteCmd,FileAppendPre,FileAppendPost,FileAppendCmd
210 set eventignore+=FilterWritePre,FilterWritePost,FileChangedShell
211 set eventignore+=FileChangedRO,FocusGained,FocusLost,FuncUndefined
212 set eventignore+=CursorHold,BufEnter,BufLeave,BufWinEnter,BufWinLeave
213 set eventignore+=BufUnload,BufHidden,BufNew,BufAdd,BufCreate,BufDelete
214 set eventignore+=BufWipeout,WinEnter,WinLeave,CmdwinEnter,CmdwinLeave
215 set eventignore+=GUIEnter,VimEnter,VimLeavePre,VimLeave,EncodingChanged
216 set eventignore+=FileEncoding,RemoteReply,TermChanged,TermResponse,User
217 " New to WhatsMissing 4.0
218 set eventignore+=ColorScheme,CursorHoldI,CursorMoved,CursorMovedI
219 set eventignore+=FileChangedShellPost,GUIFailed,InsertChange,InsertCharPre
220 set eventignore+=InsertEnter,InsertLeave,MenuPopup,QuickFixCmdPre,QuickFixCmdPost
221 set eventignore+=SessionLoadPost,ShellCmdPost,ShellFilterPost,SourcePre
222 set eventignore+=SourceCmd,SpellFileMissing,SwapExists,TabEnter,TabLeave
223 set eventignore+=VimResized
224
225 let title = '(!matching! of !checked!) items '
226 if check_for_missing == 1
227 let s:wm_missing_buf_name = "WhatsMissing"
228 let title = title . 'missing from: '
229 else
230 let s:wm_missing_buf_name = "WhatsNotMissing"
231 let title = title . 'found in both buffers: '
232 endif
233 let title = title . bufname(s:wm_find_bufnr) .
234 \ "\n----------"
235
236 call s:WM_AddToResultBuffer( title, "clear" )
237
238 " Put an extra newline at the start of the file
239 " It will be removed (undo) at the end of this, but
240 " this allows us to move through the file more consistently
241 " without having to deal with boundary cases
242 call cursor(a:firstline,1)
243 put! =''
244
245 let s:wm_matching_cnt = 0
246 let s:wm_checked_cnt = 0
247 let findstr = ''
248 while (1==1)
249 let org_curline = line(".")
250 let org_curcol = col(".")
251 let org_strlen = strlen(s:wm_unescaped_findstr)
252
253 let findstr = s:WM_GetNextFindStr(a:firstline)
254
255 " normal! w
256
257 if s:wm_find_mode == 'word'
258 " Check to see if we are on a character
259 " Since a user can specify a range, abort when we have passed it
260 " When hitting w (at the end of the file) the cursor
261 " will simply move to the end of the word, so we must
262 " check to ensure we have moved off of the previous word.
263 if (line(".") > (a:lastline+1)) ||
264 \ (line(".") == org_curline &&
265 \ col(".") < (org_curcol+org_strlen) )
266 " We have reached the end of the file
267 break
268 endif
269 elseif s:wm_find_mode == 'line'
270 " In line mode, just check if we are on the last
271 " line of the file
272 if (line(".") > (a:lastline+1)) ||
273 \ (org_curline == (a:lastline+1))
274 " We have reached the end of the file
275 break
276 endif
277 endif
278
279 if strlen(findstr) > 0
280 let s:wm_checked_cnt = s:wm_checked_cnt + 1
281
282 " Switch to the buffer we want to check this string for
283 silent! exec "buffer " . s:wm_find_bufnr
284
285 " ignore case
286 let srch_str = s:wm_ignore_case
287 if s:wm_find_mode == 'word'
288 if findstr =~? '^\w'
289 let srch_str = srch_str . '\<'
290 endif
291 let srch_str = srch_str . findstr
292 if findstr =~? '\w$'
293 let srch_str = srch_str . '\>'
294 endif
295 else
296 let srch_str = srch_str . '^' .
297 \ s:wm_ignore_whitespace .
298 \ findstr .
299 \ s:wm_ignore_whitespace .
300 \ '$'
301 endif
302
303 " Decho strftime("%X").' '.srch_str
304
305 " Mark the current line to return to
306 let find_curline = line(".")
307 let find_curcol = col(".")
308
309 if s:wm_debug == 1
310 call s:WM_AddToResultBuffer( 'Finding: [' .
311 \ srch_str . ']', "" )
312 endif
313 let found_line = search( srch_str, "w" )
314
315 if check_for_missing == 1 && found_line == 0
316 let s:wm_matching_cnt = s:wm_matching_cnt + 1
317 call s:WM_AddToResultBuffer( s:wm_unescaped_findstr, "" )
318 elseif check_for_missing == 0 && found_line > 0
319 let s:wm_matching_cnt = s:wm_matching_cnt + 1
320 call s:WM_AddToResultBuffer( s:wm_unescaped_findstr, "" )
321 endif
322
323 " Switch back to the original buffer
324 silent! exec "buffer " . s:wm_org_bufnr
325
326 " Return to previous location
327 " call cursor(org_curline, org_curcol)
328
329 endif
330
331 endwhile
332
333 silent! exec "buffer " . s:wm_org_bufnr
334 " Undo the put = we did above
335 undo
336
337 silent! exe 'noh'
338
339 " Restore previous cpoptions
340 let &cpoptions = l:old_cpoptions
341 let &eventignore = l:old_eventignore
342 let @" = saveReg
343 " restore previous search
344 let @/ = saveSearch
345 let @z = saveZ
346
347 call s:WM_SetSummary()
348 if s:wm_debug == 1
349 call s:WM_AddToResultBuffer( 'Start: ' .
350 \ a:firstline .
351 \ ' End: ' .
352 \ a:lastline,
353 \ "" )
354 endif
355
356 " call s:WM_AddToResultBuffer( "EI:".&eventignore, "" )
357 endfunction
358
e5e41bc @dfishburn Version 5.0
dfishburn authored
359 function! whatsmissing#WhatsNotMissingRemoveMatches()
360
361 if s:wm_find_mode != 'word'
362 call s:WM_WarningMsg(
363 \ 'WM Remove Matches only works in "word" mode'
364 \ )
365 return -1
366 endif
367
368 if s:wm_org_bufnr == 0 || bufexists(s:wm_org_bufnr+0) < 1
369 call s:WM_WarningMsg(
370 \ 'WM You must run WhatsNotMissing first.'
371 \ )
372 return -1
373 endif
374
375 if s:wm_missing_bufnr == 0 || bufexists(s:wm_missing_bufnr+0) < 1
376 call s:WM_WarningMsg(
377 \ 'WM You must run WhatsNotMissing first.'
378 \ )
379 return -1
380 endif
381
382 " Do not use bufexists(s:wm_missing_buf_name), since it uses a fully
383 " qualified path name to search for the buffer, which in effect opens
384 " multiple buffers called "result" if the files that you are executing the
385 " commands from are in different directories.
386 let s:wm_missing_bufnr = bufnr(s:wm_missing_buf_name)
387
388 if s:wm_missing_bufnr == -1
389 call s:WM_WarningMsg(
390 \ 'WM You must run WhatsNotMissing first.'
391 \ )
392 return -1
393 endif
394
395 if s:wm_matching_cnt == 0
396 call s:WM_WarningMsg(
397 \ 'WM There are no matches - all done.'
398 \ )
399 return -1
400 endif
401
402 " Switch to the WhatsNotMissing buffer
403 silent! exec "buffer " . s:wm_missing_bufnr
404
405 " Make another quick chck to ensure we are in the correct buffer.
406 if line('$') < 6
407 " (4 of 486) items found in both buffers: keywords_not_missing_test.txt
408 " ----------
409 " ... matches ...
410 " ----------
411 " WMOptions:
412 " mode=word ignore_case= ignore_whitespace=0
413
414 call s:WM_WarningMsg(
415 \ 'WM Could not find appropriate WM buffer, looking at:'.s:wm_find_bufnr
416 \ )
417 return -1
418 endif
419
420
421 " Prevent the alternate buffer (<C-^>) from being set to this
422 " temporary file
423 let l:old_cpoptions = &cpoptions
424 setlocal cpo-=a
425 setlocal cpo-=A
426 let saveReg = @"
427 " save previous search string
428 let saveSearch = @/
429 let saveZ = @z
430
431 " Disable all autocommands and events since we will be
432 " flipping between 3 buffers in rapid succession.
433 " If these events are not disabled, this can take
434 " a very long time
435 let l:old_eventignore = &eventignore
436 set eventignore+=BufNewFile,BufReadPre,BufRead,BufReadPost,BufReadCmd
437 set eventignore+=BufFilePre,BufFilePost,FileReadPre,FileReadPost
438 set eventignore+=FileReadCmd,FilterReadPre,FilterReadPost,FileType,Syntax
439 set eventignore+=StdinReadPre,StdinReadPost,BufWrite,BufWritePre
440 set eventignore+=BufWritePost,BufWriteCmd,FileWritePre,FileWritePost
441 set eventignore+=FileWriteCmd,FileAppendPre,FileAppendPost,FileAppendCmd
442 set eventignore+=FilterWritePre,FilterWritePost,FileChangedShell
443 set eventignore+=FileChangedRO,FocusGained,FocusLost,FuncUndefined
444 set eventignore+=CursorHold,BufEnter,BufLeave,BufWinEnter,BufWinLeave
445 set eventignore+=BufUnload,BufHidden,BufNew,BufAdd,BufCreate,BufDelete
446 set eventignore+=BufWipeout,WinEnter,WinLeave,CmdwinEnter,CmdwinLeave
447 set eventignore+=GUIEnter,VimEnter,VimLeavePre,VimLeave,EncodingChanged
448 set eventignore+=FileEncoding,RemoteReply,TermChanged,TermResponse,User
449 " New to WhatsMissing 4.0
450 set eventignore+=ColorScheme,CursorHoldI,CursorMoved,CursorMovedI
451 set eventignore+=FileChangedShellPost,GUIFailed,InsertChange,InsertCharPre
452 set eventignore+=InsertEnter,InsertLeave,MenuPopup,QuickFixCmdPre,QuickFixCmdPost
453 set eventignore+=SessionLoadPost,ShellCmdPost,ShellFilterPost,SourcePre
454 set eventignore+=SourceCmd,SpellFileMissing,SwapExists,TabEnter,TabLeave
455 set eventignore+=VimResized
456
457 let s:wm_checked_cnt = 0
458 let findstr = ''
459 let org_curline = line(".")
460 let org_curcol = col(".")
461 let org_strlen = strlen(s:wm_unescaped_findstr)
462
463 " Move to the second line of the WhatsNotMissing buffer.
464 " WM_GetNextFindStr does a "w" and will therefore move
465 " to the first word of our matches.
466 call cursor(2,1)
467
468 while (1==1)
469 " Get first matched word
470 let findstr = s:WM_GetNextFindStr(a:firstline)
471 let del_count = strlen(findstr)
472
473 if s:wm_find_mode == 'word'
474 " Check to see if we are on a character
475 " Since a user can specify a range, abort when we have passed it
476 " When hitting w (at the end of the file) the cursor
477 " will simply move to the end of the word, so we must
478 " check to ensure we have moved off of the previous word.
479 "
480 " NOTE: There are 3 footer lines in the WhatsNotMissing buffer.
481 if (line(".") > (line('$')-3)) ||
482 \ (line(".") == org_curline &&
483 \ col(".") < (org_curcol+org_strlen) )
484 " We have reached the end of the file
485 break
486 endif
487 elseif s:wm_find_mode == 'line'
488 " In line mode, just check if we are on the last
489 " line of the file
490 if (line(".") > (line('$')-2)) ||
491 \ (org_curline == (a:lastline+1))
492 " We have reached the end of the file
493 break
494 endif
495 endif
496
497
498 if strlen(findstr) > 0
499 " Switch to the buffer we want to check this string for
500 silent! exec "buffer " . s:wm_org_bufnr
501
502 " ignore case
503 let srch_str = s:wm_ignore_case
504 if s:wm_find_mode == 'word'
505 if findstr =~? '^\w'
506 let srch_str = srch_str . '\<'
507 endif
508 let srch_str = srch_str . findstr
509 if findstr =~? '\w$'
510 let srch_str = srch_str . '\>'
511 endif
512 else
513 let srch_str = srch_str . '^' .
514 \ s:wm_ignore_whitespace .
515 \ findstr .
516 \ s:wm_ignore_whitespace .
517 \ '$'
518 endif
519
520 " Decho strftime("%X").' '.srch_str
521
522 " Mark the current line to return to
523 let find_curline = line(".")
524 let find_curcol = col(".")
525
526 if s:wm_debug == 1
527 call s:WM_AddToResultBuffer( 'Finding: [' .
528 \ srch_str . ']', "" )
529 endif
530 let found_line = search( srch_str, "w" )
531
532 if found_line > 0
533 " Remove this value from the original buffer
534 " Simply delete the appropriate number of characters
535 " from the buffer.
536 exec 'normal! '.del_count.'x'
537 endif
538
539 " Switch back to the WhatsNotMissing buffer
540 silent! exec "buffer " . s:wm_missing_bufnr
541
542 endif
543
544 endwhile
545
546 " Back to the original buffer
547 silent! exec "buffer " . s:wm_org_bufnr
548
549 silent! exe 'noh'
550
551 " Restore previous cpoptions
552 let &cpoptions = l:old_cpoptions
553 let &eventignore = l:old_eventignore
554 let @" = saveReg
555 " restore previous search
556 let @/ = saveSearch
557 let @z = saveZ
558
559 let response = 0
560 let response = confirm("There maybe blank lines after the deletes, remove them?",
561 \ "&Yes\n&No",
562 \ response
563 \ )
564 if response == 1
565 :g/^\s*$/d_
566 endif
567 endfunction
568
f854a38 @dfishburn Version 4.0
dfishburn authored
569 function! s:WM_SetBufNbr( bufnr )
570 if match(a:bufnr, '\d') == -1
571 call s:WM_WarningMsg(
572 \ "WM_SetBufNbr must use numeric parameter: " . a:bufnr
573 \ )
574 return -1
575 endif
576
577 if a:bufnr == s:wm_org_bufnr
578 call s:WM_WarningMsg(
579 \ "Cannot choose the same buffer: " . a:bufnr
580 \ )
581 return -1
582 endif
583
584 if !bufexists(a:bufnr+0)
585 call s:WM_WarningMsg(
586 \ "Cannot find buffer #: " . a:bufnr
587 \ )
588 return -1
589 endif
590
591 let s:wm_find_bufnr = a:bufnr
592
593 return 1
594 endfunction
595
596 function! s:WM_SetFileName( filename )
597 let filename = expand(a:filename)
598 if !bufexists(bufnr(filename))
599 if filereadable(filename)
600 " load the file into a new buffer
601 exec 'view ' . filename
602 if bufexists(bufnr(filename))
603 let s:wm_find_bufnr = bufnr(filename)
604 else
605 call s:WM_WarningMsg(
606 \ "Failed to load: " . filename
607 \ )
608 return -1
609 endif
610 else
611 call s:WM_WarningMsg(
612 \ "Cannot find: " . filename
613 \ )
614 return -1
615 endif
616 else
617 let s:wm_find_bufnr = bufnr(filename)
618 endif
619 let s:wm_filename = filename
620
621 return 1
622 endfunction
623
624 function! s:WM_AddToResultBuffer(output, do_clear)
e5e41bc @dfishburn Version 5.0
dfishburn authored
625 " Store current window number so we can return to it
f854a38 @dfishburn Version 4.0
dfishburn authored
626 let cur_winnr = winnr()
627
e5e41bc @dfishburn Version 5.0
dfishburn authored
628 " Do not use bufexists(s:wm_missing_buf_name), since it uses a fully
f854a38 @dfishburn Version 4.0
dfishburn authored
629 " qualified path name to search for the buffer, which in effect opens
630 " multiple buffers called "result" if the files that you are executing the
631 " commands from are in different directories.
632 let s:wm_missing_bufnr = bufnr(s:wm_missing_buf_name)
633
634 if s:wm_missing_bufnr == -1
e5e41bc @dfishburn Version 5.0
dfishburn authored
635 " Create the new buffer
f854a38 @dfishburn Version 4.0
dfishburn authored
636 silent exec 'belowright ' . s:wm_buffer_lines . 'new ' . s:wm_missing_buf_name
637 let s:wm_missing_bufnr = bufnr("%")
638 else
639 if bufwinnr(s:wm_missing_bufnr) == -1
e5e41bc @dfishburn Version 5.0
dfishburn authored
640 " If the buffer is not visible, wipe it out and recreate it,
f854a38 @dfishburn Version 4.0
dfishburn authored
641 " this will position us in the new buffer
642 exec 'bwipeout! ' . s:wm_missing_bufnr
643 silent exec 'bot ' . s:wm_buffer_lines . 'new ' . s:wm_missing_buf_name
644 else
645 " if the buffer is visible, switch to it
646 exec bufwinnr(s:wm_missing_bufnr) . "wincmd w"
647 endif
648 endif
649 setlocal modified
650 " create a buffer mapping to clo this window
651 nnoremap <buffer> q :clo<cr>
652 " delete all the lines prior to this run
653 if a:do_clear == "clear"
654 %d
655 endif
656
657 if strlen(a:output) > 0
658 " add to end of buffer
659 silent! exec "$put =a:output"
660 endif
661
662 " since this is a small window, remove any blanks lines
663 silent %g/^\s*$/d
664 " fix the ^m characters, if any
665 silent execute "%s/\<c-m>\\+$//e"
666 " dont allow modifications, and do not wrap the text, since
667 " the data may be lined up for columns
668 setlocal nomodified
669 setlocal nowrap
670 " go to top of output
671 norm gg
672 " return to original window
673 exec cur_winnr."wincmd w"
674
675 return
676 endfunction
677
678 function! s:WM_GetNextFindStr(startline)
679 if s:wm_find_mode == 'word'
680 normal! wyiw
681 let s:wm_unescaped_findstr = @"
682 elseif s:wm_find_mode == 'line'
683 normal! j
684 let s:wm_unescaped_findstr = getline(".")
685 endif
686
687 " Escape various special characters
688 let findstr = escape(s:wm_unescaped_findstr, '\\/.*$^~[]' )
689 let findstr = substitute(
690 \ substitute(findstr, "\n$", "", ""),
691 \ "\n", '\\_[[:return:]]', "g")
692 return findstr
693 endfunction
694
695 function! s:WM_GetFindBufferOptions()
696 silent! exec "buffer " . s:wm_find_bufnr
697 let s:wm_find_filetype = &filetype
698 silent! exec "buffer " . s:wm_org_bufnr
699 endfunction
700
701 function! s:WM_PromptOptions()
702 " Mode
703 let response = (s:wm_find_mode == 'word' ? '1' : '2' )
704 let response = confirm("Choose compare method:",
705 \ "&Word\n&Line",
706 \ response
707 \ )
708 let s:wm_find_mode = (response == '1' ? 'word' : 'line' )
709
710 " Ignore Case
711 let response = (s:wm_ignore_case ==# '' ? '1' :
712 \ (s:wm_ignore_case ==# '\c' ? '3' : '2' ) )
713 let response = confirm("Do you want to ignore case?",
714 \ "&Default\n&Yes\n&No",
715 \ response
716 \ )
717 let s:wm_ignore_case = (response ==# '1' ? '' :
718 \ (response ==# '2' ? '\c' : '\C' ) )
719
720 " Ignore whitespace
721 let response = (s:wm_ignore_whitespace == '' ? '1' : '2' )
722 let response = confirm("Do you want to ignore whitespace?",
723 \ "&No\n&Yes",
724 \ response
725 \ )
726 let s:wm_ignore_whitespace = (response ==# '1' ? '' : '\s*' )
727 endfunction
728
729 function! s:WM_SetSummary()
730 let WMOptions = "----------\nWMOptions:\n" .
731 \ whatsmissing#WM_GetOption('mode').' '.
732 \ whatsmissing#WM_GetOption('ignore_case').' '.
733 \ whatsmissing#WM_GetOption('ignore_whitespace')
734 call s:WM_AddToResultBuffer(WMOptions, '')
735
736 silent! exec "buffer " . s:wm_missing_bufnr
737 call cursor(1,1)
738 exec 's/!matching!/'.s:wm_matching_cnt.'/e'
739 exec 's/!checked!/'.s:wm_checked_cnt.'/e'
740 let &filetype = s:wm_find_filetype
741 setlocal nomodified
742 silent! exec "buffer " . s:wm_org_bufnr
743 endfunction
744
745 function! whatsmissing#WM_CompleteOption(ArgLead, CmdLine, CursorPos)
746
747 if a:ArgLead =~? '^mode='
748 let cmd_options = a:ArgLead .
749 \ substitute(s:wm_modes, ',', "\n".a:ArgLead, 'g')
750 elseif a:ArgLead =~? '='
751 let cmd_options = a:ArgLead . "0\n" .
752 \ a:ArgLead . "1"
753 else
754 let cmd_options = substitute(s:wm_options, ',', "\n", 'g')
755 endif
756
757 return cmd_options
758 endfunction
759
760 function! s:WM_WarningMsg(msg)
761 echohl WarningMsg
762 echomsg "WM: " . a:msg
763 echohl None
764 endfunction
765
766 let &cpo = s:cpo_save
767 unlet s:cpo_save
768
769 " vim:fdm=marker:nowrap:ts=4:expandtab:
Something went wrong with that request. Please try again.