Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Version 1.0: Documentation and GetLastestVimScripts support

  • Loading branch information...
commit 082d620124dde819918f3fa13fe72464dc3ce80f 0 parents
authored October 17, 2004 vim-scripts committed October 17, 2010
129  README
... ...
@@ -0,0 +1,129 @@
  1
+This is a mirror of http://www.vim.org/scripts/script.php?script_id=1108
  2
+
  3
+This plugin contains functions/commands that will cycle through one 
  4
+buffer (the source) and compare the its contents against the contents of
  5
+another buffer (the target).
  6
+
  7
+NOTE:  This is not a poor man's 'diff', since the source and target must be 
  8
+              similar in appearance.  See example below for a better understanding.
  9
+                                                                              
  10
+Depending on the options specified and command chosen, it will open a split
  11
+window (the result) and display either the entries that are:
  12
+   - missing from the target buffer
  13
+   or
  14
+   - contained in both buffers
  15
+   
  16
+The plugin has created a menu, Plugin->WhatMissing.  There are two entries: 
  17
+    WhatsMissing
  18
+    WhatsNotMissing
  19
+
  20
+These menu items are also available in visual mode.  These menu items simply call the commands: 
  21
+    :WhatsMissing
  22
+    :WhatsNotMissing
  23
+
  24
+The behavior of whatsmissing.vim are governed by several options. Options can be specified using the WMSetOption command.  As mentioned above, the <Tab> button can be used for both option name and option value completion.
  25
+                                                                            
  26
+You can check the value of a specific option by: 
  27
+    :WMGetOption option_name
  28
+ 
  29
+Here are the various options: 
  30
+   mode  
  31
+       - Values: "word" or "line".  
  32
+       - WhatsMissing will move through the source buffer one |word| at a
  33
+         time, and checks this value against the target buffer.  It will 
  34
+         also automatically escape the following characters: 
  35
+               '\\/.*$^~[]'
  36
+         If the "line" mode is chosen the comparison between the source 
  37
+         and target buffer is performed a line at a time. 
  38
+                                                                            
  39
+   ignore_case 
  40
+       - Values: "0" or "1".  
  41
+       - The "default" for WhatsMissing is to use the |'ignorecase'| option
  42
+         of the target buffer.  Otherwise the user is allowed to override
  43
+         it. 
  44
+                                                                            
  45
+   ignore_whitespace
  46
+       - Values: "0" or "1".  
  47
+       - If in "line" mode, you can choose to ignore leading and trailing
  48
+         whitespace for the comparison. 
  49
+
  50
+
  51
+Example
  52
+------------
  53
+Consider the case where you are maintaining a Vim syntax file.  It has entries like this:
  54
+*************
  55
+syn keyword sqlFunction	count sum avg min max debug_eng isnull
  56
+syn keyword sqlFunction	greater lesser argn string ymd todate
  57
+syn keyword sqlFunction sp_addalias
  58
+syn keyword sqlFunction sp_addauditrecord
  59
+syn keyword sqlKeyword	replicate rereceive resend reset
  60
+syn keyword sqlKeyword	resolve resource respect
  61
+syn keyword sqlKeyword	restrict result retain
  62
+syn keyword sqlStatement allocate alter backup begin call case
  63
+syn keyword sqlStatement checkpoint clear close commit configure connect
  64
+syn keyword sqlStatement create deallocate declare delete describe
  65
+syn keyword sqlType	char long varchar text
  66
+syn keyword sqlType	bigint decimal double float int integer numeric 
  67
+*************
  68
+
  69
+In order to create the syntax file in the first place you had to find the above words from somewhere.  In this case, I simply used grep against the source code to find various API method names, keywords, functions and so on.
  70
+
  71
+So in the end after running grep repeatedly and massaging the output, I end up with a file like this:
  72
+**************
  73
+abs
  74
+absolute
  75
+action
  76
+activ
  77
+expanded
  78
+experience_estimate
  79
+explanation
  80
+explicit
  81
+express
  82
+exprtype
  83
+remainder
  84
+remote
  85
+remove
  86
+rename
  87
+reorganize
  88
+replicate 
  89
+rereceive 
  90
+resend 
  91
+reset
  92
+value
  93
+values
  94
+varbinary
  95
+varchar
  96
+varexists
  97
+**************
  98
+
  99
+At this point you want to update your Vim syntax file to include all the new method names, keywords, functions and so on that are missing from the existing syntax file.
  100
+
  101
+You cannot run Diff against this, since the lines are completely different, you need to compare the words.
  102
+
  103
+After running :WhatsMissing, you end up with a split buffer showing:
  104
+***************
  105
+(19 of 24) items missing from: syntax.vim
  106
+----------
  107
+abs
  108
+absolute
  109
+action
  110
+activ
  111
+expanded
  112
+experience_estimate
  113
+explanation
  114
+explicit
  115
+express
  116
+exprtype
  117
+remainder
  118
+remote
  119
+remove
  120
+rename
  121
+reorganize
  122
+value
  123
+values
  124
+varbinary
  125
+varexists
  126
+----------
  127
+WMOptions:
  128
+mode=word ignore_case=  ignore_whitespace=0
  129
+***************
203  doc/WhatsMissing.txt
... ...
@@ -0,0 +1,203 @@
  1
+*whatsmissing.txt*	For Vim version 6.0.  
  2
+
  3
+
  4
+                	  VIM REFERENCE MANUAL 
  5
+                                by 
  6
+                     David Fishburn <fishburn@ianywhere.com>
  7
+
  8
+	  	Whatsmissing plugin (WhatsMissing.vim) Manual
  9
+	  	    WhatsMissing.vim version 1.00
  10
+
  11
+For instructions on installing this file, type
  12
+	:help add-local-help
  13
+|add-local-help| inside Vim.
  14
+
  15
+Homepage: http://vim.sourceforge.net/script.php?script_id=1108
  16
+
  17
+*WhatsMissing.vim* *whatsmissing* *whatsnotmissing* 
  18
+
  19
+1.  Overview					|whatsmissing-overview|
  20
+2.  Installation				|whatsmissing-install|
  21
+3.  Commands    				|whatsmissing-commands|
  22
+4.  Functions     				|whatsmissing-functions|
  23
+5.  Options     				|whatsmissing-options|
  24
+
  25
+{Vi does not have any of this}
  26
+
  27
+------------------------------------------------------------------------------
  28
+What's New					*whatsmissing-new*
  29
+
  30
+Version 1.00
  31
+    - Initial Release
  32
+ 
  33
+------------------------------------------------------------------------------
  34
+1. Overview					*whatsmissing-overview*
  35
+
  36
+ This plugin contains functions/commands that will cycle through one 
  37
+ buffer (the source) and compare the its contents against the contents of
  38
+ another buffer (the target).
  39
+
  40
+ Depending on the options specified and command chosen, it will open a split
  41
+ window (the result) and display either the entries that are:
  42
+    - missing from the target buffer
  43
+    or
  44
+    - contained in both buffers
  45
+    
  46
+ The plugin has created a menu, Plugin->WhatMissing.  There are two entries: >
  47
+     WhatsMissing
  48
+     WhatsNotMissing
  49
+<
  50
+ These menu items are also available in visual mode.  These menu items simply
  51
+ call the commands: >
  52
+     :WhatsMissing
  53
+     :WhatsNotMissing
  54
+<
  55
+ The commands will prompt the user for various options, see below in
  56
+ the |whatsmissing-commands| section.
  57
+
  58
+
  59
+------------------------------------------------------------------------------
  60
+2. Installation         			*whatsmissing-install*
  61
+
  62
+ You can use this script as a plugin by copying it to your plugin directory. 
  63
+ See |add-global-plugin| for instructions.
  64
+ 
  65
+ You can also |:source| it from your |.vimrc|.
  66
+
  67
+ To install this help file |add-local-help| inside Vim.
  68
+ 	:help add-local-help
  69
+	:helptags $VIM/vimfiles/doc (Windows)
  70
+	:helptags $VIM/.vim/doc     (Unix)
  71
+
  72
+
  73
+------------------------------------------------------------------------------
  74
+3. Commands             			*whatsmissing-commands*
  75
+
  76
+ If no parameters are supplied to the WhatsMissing and WhatsNotMissing 
  77
+ commands, you will be prompted for all parameters.  This makes it very 
  78
+ easy to use the plugin.  If you wish to call these commands from scripts
  79
+ you can use the |call| syntax and supply all parameters (this will
  80
+ suppress the prompting). >
  81
+ 
  82
+ WhatsMissing
  83
+<    Moves through the source buffer and checks to see if the entry exists 
  84
+     in the target buffer.  If it does *not*, then it is considered missing
  85
+     and the entry is added to the third buffer. >
  86
+
  87
+
  88
+ WhatsNotMissing
  89
+<    Moves through the source buffer and checks to see if the entry exists 
  90
+     in the target buffer.  If it *does *, then it is considered *not* missing
  91
+     and the entry is added to the third buffer.
  92
+
  93
+>
  94
+ WMSetOption
  95
+<    There are several options which can control the behaviour of the plugin.
  96
+     WMSetOption supports command completion, so you can do the following: >
  97
+         :WMSetOption <Tab> 
  98
+<    
  99
+     If you repeatedly press the <Tab> button, it will cycle through the
  100
+     various options available.  Once an option is available, if you add
  101
+     and "=" sign, then you can also complete the values for the option: >
  102
+         :WMSetOption mode=<Tab>
  103
+<    
  104
+     Pressing <Tab> repeatedly will cycle through the values for this
  105
+     option.  >
  106
+
  107
+
  108
+ WMGetOption
  109
+<    This command will display the value of the option supplied.  Similar
  110
+     to WMSetOption, this command also supports the <Tab> completion. >
  111
+         :WMGetOption <Tab> 
  112
+         :WMGetOption mode
  113
+< 
  114
+     This command will display the value of the option: >
  115
+         :mode=word
  116
+<
  117
+
  118
+
  119
+
  120
+------------------------------------------------------------------------------
  121
+4. Functions             			*whatsmissing-functions*
  122
+
  123
+ There are four public functions available. >
  124
+ 
  125
+ WhatsMissing
  126
+<    - Optionally takes 3 parameters. >
  127
+        - 1st parameter - target buffer
  128
+<         Can be any of the following:
  129
+            - buffer #
  130
+            - buffer name
  131
+            - absolute / relative filename >
  132
+        - 2nd parameter - Missing or NOT
  133
+<         Can be: 
  134
+            - 1 = Check for items missing from the target buffer
  135
+            - 0 = Check for items NOT missing from the target buffer >
  136
+        - 3rd parameter - No Prompt
  137
+<         Can be: 
  138
+            - 1 = Prompt for all options
  139
+            - 0 = No prompting for options >
  140
+<    - Example calls: >
  141
+        :%call WhatsMissing('syntax.sql', 1, 1)
  142
+        :10,20call WhatsMissing('syntax.sql', 1, 0)
  143
+       
  144
+
  145
+ WhatsNotMissing
  146
+<    Takes the same parameters as WhatsMissing, but sets the 2nd 
  147
+     parameter to 0.
  148
+
  149
+>
  150
+ WM_SetOption
  151
+<    - Takes 1 parameter of the form: >
  152
+        option_name=option_value
  153
+<    - See |whatsmissing-options| for parameters.  
  154
+     - Example call: >
  155
+        :call WM_SetOption('ignore_case=1')
  156
+       
  157
+
  158
+ WM_GetOption
  159
+<    - Takes 1 parameter of the form: >
  160
+        option_name
  161
+<    - See |whatsmissing-options| for parameters.  
  162
+     - Example call, note the use of echo, not call: >
  163
+        :echo WM_GetOption('ignore_case')
  164
+<
  165
+
  166
+------------------------------------------------------------------------------
  167
+5. Options					*whatsmissing-options*
  168
+
  169
+ The behavior of WhatsMissing.vim are governed by several options. Options
  170
+ can be specified using the WMSetOption command.  As mentioned above, the
  171
+ <Tab> button can be used for both option name and option value completion.
  172
+
  173
+ You can check the value of a specific option by: >
  174
+     :WMGetOption option_name
  175
+< 
  176
+ Here are the various options: >
  177
+    mode  
  178
+<       - Values: "word" or "line".  
  179
+        - WhatsMissing will move through the source buffer one |word| at a
  180
+          time, and checks this value against the target buffer.  It will 
  181
+          also automatically escape the following characters: >
  182
+                '\\/.*$^~[]'
  183
+<         If the "line" mode is chosen the comparison between the source 
  184
+          and target buffer is performed a line at a time. >
  185
+
  186
+    ignore_case 
  187
+<       - Values: "0" or "1".  
  188
+        - The "default" for WhatsMissing is to use the |'ignorecase'| option
  189
+          of the target buffer.  Otherwise the user is allowed to override
  190
+          it. >
  191
+
  192
+    ignore_whitespace
  193
+<       - Values: "0" or "1".  
  194
+        - If in "line" mode, you can choose to ignore leading and trailing
  195
+          whitespace for the comparison. >
  196
+
  197
+    debug
  198
+<       - Values: "0" or "1".  
  199
+        - Used internally to show search strings.
  200
+
  201
+
  202
+------------------------------------------------------------------------------
  203
+  vim:tw=78:fo=tcq2:ts=8:ft=help:norl:
544  plugin/WhatsMissing.vim
... ...
@@ -0,0 +1,544 @@
  1
+" WhatMissing.vim - Shows what is missing between 2 buffers
  2
+" ---------------------------------------------------------------
  3
+" Version:  1.00
  4
+" Authors:  David Fishburn <fishburn@ianywhere.com>
  5
+" Last Modified: Sun Oct 17 2004 10:25:19 PM
  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') || &cp
  10
+    finish
  11
+endif
  12
+let g:loaded_whatsmissing = 100
  13
+
  14
+let s:wm_buffer_lines      = 10
  15
+let s:wm_matching_cnt      = 0
  16
+let s:wm_checked_cnt       = 0
  17
+let s:wm_org_bufnr         = 0
  18
+let s:wm_missing_bufnr     = 0
  19
+let s:wm_debug             = 0
  20
+let s:wm_find_bufnr        = 0
  21
+let s:wm_find_mode         = 'word'
  22
+let s:wm_find_filetype     = ''
  23
+let s:wm_filename          = ''
  24
+let s:wm_ignore_case       = ''
  25
+let s:wm_ignore_whitespace = ''
  26
+let s:wm_unescaped_findstr = ''
  27
+let s:wm_missing_buf_name  = "WhatsMissing"
  28
+let s:wm_options           = "mode,ignore_case,ignore_whitespace,debug"
  29
+let s:wm_modes             = "word,line"
  30
+
  31
+function! WM_GetOption(option)
  32
+    if s:wm_options !~? '\<'.a:option.'\>'
  33
+        call s:WM_WarningMsg(
  34
+                    \ "Invalid option, choices are: " .
  35
+                    \ s:wm_options
  36
+                    \ )
  37
+        return -1
  38
+    endif
  39
+
  40
+    if a:option == 'mode'
  41
+        let value = a:option.'='.s:wm_find_mode
  42
+    elseif a:option == 'ignore_case'
  43
+        let value = a:option.'='.
  44
+                    \ (s:wm_ignore_case ==# '' ? ' ' : 
  45
+                    \ (s:wm_ignore_case ==# '\c' ? '1' : '0' ) )
  46
+    elseif a:option == 'ignore_whitespace'
  47
+        let value = a:option.'='.(s:wm_ignore_whitespace ==# '' ? '0' : '1' )
  48
+    elseif a:option == 'debug'
  49
+        let value = a:option.'='.s:wm_debug
  50
+    else
  51
+        let value = 'Unknown option: a:option'
  52
+    endif
  53
+
  54
+    return value
  55
+endfunction
  56
+
  57
+function! WM_SetOption(option)
  58
+    let opt_name  = matchstr(a:option, '^.\{-}\ze=' )
  59
+    let opt_value = matchstr(a:option, '=\zs.\{-}\s*$' )
  60
+    
  61
+    if s:wm_options !~? '\<'.opt_name.'\>'
  62
+        call s:WM_WarningMsg(
  63
+                    \ "Invalid option, choices are: " .
  64
+                    \ s:wm_options
  65
+                    \ )
  66
+        return -1
  67
+    endif
  68
+
  69
+    if opt_name == 'mode'
  70
+        if s:wm_modes !~? '\<'.opt_value.'\>'
  71
+            call s:WM_WarningMsg(
  72
+                        \ "Invalid mode, choices are: " .
  73
+                        \ s:wm_modes
  74
+                        \ )
  75
+            return -1
  76
+        else
  77
+            let s:wm_find_mode = opt_value
  78
+        endif
  79
+    elseif opt_name == 'ignore_case'
  80
+        let s:wm_ignore_case = (opt_value ==# '1' ? '\c' : '\C' )
  81
+    elseif opt_name == 'ignore_whitespace'
  82
+        let s:wm_ignore_whitespace = (opt_value ==# '1' ? '\s*' : '' )
  83
+    elseif opt_name == 'debug'
  84
+        let s:wm_debug = opt_value
  85
+    endif
  86
+    
  87
+    return 1
  88
+endfunction
  89
+
  90
+function! WhatsNotMissing(...) range
  91
+    let compareTo = '""'
  92
+    if a:0 > 0
  93
+        let compareTo = a:1
  94
+    endif
  95
+
  96
+    let askPrompt = '"1"'
  97
+    if a:0 > 2
  98
+        let askPrompt = a:3
  99
+    endif
  100
+
  101
+    exec a:firstline.','.a:lastline.'WhatsMissing '.compareTo.' 0 '.askPrompt
  102
+endfunction
  103
+
  104
+function! WhatsMissing(...) range
  105
+    if &hidden == 0
  106
+        call s:WM_WarningMsg(
  107
+                    \ "Cannot search other buffers with :set nohidden"
  108
+                    \ )
  109
+        return -1
  110
+    endif
  111
+
  112
+    let s:wm_org_bufnr = bufnr("%")
  113
+    let rc = -1
  114
+
  115
+    let compareTo = ""
  116
+    if a:0 > 0
  117
+        let compareTo = a:1
  118
+    endif
  119
+
  120
+    if strlen(substitute(compareTo, '"' ,'', 'g')) == 0
  121
+        let response = 1
  122
+        if has("browse")
  123
+            let response = confirm("Do you want to use specify a file/buffer" .
  124
+                        \ " or browse for the file?", 
  125
+                        \ "&File/Buffer\n&Browse",
  126
+                        \ 1
  127
+                        \ )
  128
+        endif
  129
+
  130
+        if response == 1
  131
+            let msg = "Enter one of the following:" .
  132
+                        \ "\n- buffer #" .
  133
+                        \ "\n- buffer name" .
  134
+                        \ "\n- filename (absolute|relative)\n"
  135
+            let compareTo = inputdialog(msg)
  136
+
  137
+            if strlen(substitute(compareTo, '"' ,'', 'g')) == 0
  138
+                call s:WM_WarningMsg(
  139
+                            \ "Invalid entry"
  140
+                            \ )
  141
+                return -1
  142
+            endif
  143
+        
  144
+        elseif response == 2
  145
+            if has("browse")
  146
+                let compareTo = browse(0,"WhatsMissing Compare To", "", "")
  147
+            endif
  148
+        endif
  149
+    endif
  150
+
  151
+    let compareTo = substitute(compareTo, '^\s*\(.\{-}\)\s*$', '\1', '')
  152
+    if match(compareTo, '\D') == -1
  153
+        let rc = s:WM_SetBufNbr( compareTo )
  154
+    else
  155
+        let rc = s:WM_SetFileName( compareTo )
  156
+    endif
  157
+        
  158
+    if rc == -1
  159
+        return -1
  160
+    endif
  161
+
  162
+    call s:WM_GetFindBufferOptions()
  163
+
  164
+    if a:0 > 1
  165
+        let check_for_missing = a:2
  166
+    else 
  167
+        let check_for_missing = 1
  168
+    endif
  169
+
  170
+    let ask_prompt = 1
  171
+    if a:0 > 2
  172
+        if a:3 == '0'
  173
+            let ask_prompt = 0
  174
+        endif
  175
+    endif
  176
+
  177
+    if ask_prompt == 1
  178
+        call s:WM_PromptOptions()
  179
+    endif
  180
+
  181
+    " Prevent the alternate buffer (<C-^>) from being set to this
  182
+    " temporary file
  183
+    let l:old_cpoptions = &cpoptions
  184
+    setlocal cpo-=Aa
  185
+    let saveReg = @"
  186
+    " save previous search string
  187
+    let saveSearch = @/
  188
+    let saveZ      = @z
  189
+
  190
+
  191
+    " Disable all autocommands and events since we will be
  192
+    " flipping between 3 buffers in rapid succession.
  193
+    " If these events are not disabled, this can take
  194
+    " a very long time
  195
+    let l:old_eventignore = &eventignore
  196
+    set eventignore+=BufNewFile,BufReadPre,BufRead,BufReadPost,BufReadCmd
  197
+    set eventignore+=BufFilePre,BufFilePost,FileReadPre,FileReadPost
  198
+    set eventignore+=FileReadCmd,FilterReadPre,FilterReadPost,FileType,Syntax
  199
+    set eventignore+=StdinReadPre,StdinReadPost,BufWrite,BufWritePre
  200
+    set eventignore+=BufWritePost,BufWriteCmd,FileWritePre,FileWritePost
  201
+    set eventignore+=FileWriteCmd,FileAppendPre,FileAppendPost,FileAppendCmd
  202
+    set eventignore+=FilterWritePre,FilterWritePost,FileChangedShell
  203
+    set eventignore+=FileChangedRO,FocusGained,FocusLost,FuncUndefined
  204
+    set eventignore+=CursorHold,BufEnter,BufLeave,BufWinEnter,BufWinLeave
  205
+    set eventignore+=BufUnload,BufHidden,BufNew,BufAdd,BufCreate,BufDelete
  206
+    set eventignore+=BufWipeout,WinEnter,WinLeave,CmdwinEnter,CmdwinLeave
  207
+    set eventignore+=GUIEnter,VimEnter,VimLeavePre,VimLeave,EncodingChanged
  208
+    set eventignore+=FileEncoding,RemoteReply,TermChanged,TermResponse,User
  209
+
  210
+    let title = '(!matching! of !checked!) items '
  211
+    if check_for_missing == 1 
  212
+        let s:wm_missing_buf_name = "WhatsMissing"
  213
+        let title = title . 'missing from: '
  214
+    else
  215
+        let s:wm_missing_buf_name = "WhatsNotMissing"
  216
+        let title = title . 'found in both buffers: '
  217
+    endif
  218
+    let title = title . bufname(s:wm_find_bufnr) .
  219
+                \ "\n----------" 
  220
+
  221
+    call s:WM_AddToResultBuffer( title, "clear" )
  222
+
  223
+    " Put an extra newline at the start of the file
  224
+    " It will be removed (undo) at the end of this, but
  225
+    " this allows us to move through the file more consistently
  226
+    " without having to deal with boundary cases
  227
+    call cursor(a:firstline,1)
  228
+    put! ='' 
  229
+
  230
+    let s:wm_matching_cnt     = 0
  231
+    let s:wm_checked_cnt      = 0
  232
+    let findstr               = ''
  233
+    while (1==1)
  234
+        let org_curline = line(".")
  235
+        let org_curcol  = col(".")
  236
+        let org_strlen  = strlen(s:wm_unescaped_findstr)
  237
+        
  238
+        let findstr = s:WM_GetNextFindStr(a:firstline)
  239
+
  240
+        " normal! w
  241
+
  242
+        if s:wm_find_mode == 'word'
  243
+            " Check to see if we are on a character
  244
+            " Since a user can specify a range, abort when we have passed it
  245
+            " When hitting w (at the end of the file) the cursor
  246
+            " will simply move to the end of the word, so we must
  247
+            " check to ensure we have moved off of the previous word.
  248
+            if (line(".") > (a:lastline+1)) ||
  249
+                        \ (line(".") == org_curline && 
  250
+                        \   col(".") < (org_curcol+org_strlen) )
  251
+                " We have reached the end of the file
  252
+                break
  253
+            endif
  254
+        elseif s:wm_find_mode == 'line'
  255
+            " In line mode, just check if we are on the last
  256
+            " line of the file
  257
+            if (line(".") > (a:lastline+1)) ||
  258
+                        \ (org_curline == (a:lastline+1))
  259
+                " We have reached the end of the file
  260
+                break
  261
+            endif
  262
+        endif
  263
+        
  264
+        if strlen(findstr) > 0
  265
+            let s:wm_checked_cnt = s:wm_checked_cnt + 1
  266
+
  267
+            " Switch to the buffer we want to check this string for
  268
+            silent! exec "buffer " . s:wm_find_bufnr
  269
+
  270
+            " ignore case
  271
+            let srch_str = s:wm_ignore_case
  272
+            if s:wm_find_mode == 'word'
  273
+                if findstr =~? '^\w'
  274
+                    let srch_str = srch_str . '\<'
  275
+                endif
  276
+                let srch_str = srch_str . findstr
  277
+                if findstr =~? '\w$'
  278
+                    let srch_str = srch_str . '\>'
  279
+                endif
  280
+            else
  281
+                let srch_str = srch_str . '^' . 
  282
+                            \ s:wm_ignore_whitespace .
  283
+                            \ findstr . 
  284
+                            \ s:wm_ignore_whitespace .
  285
+                            \ '$'
  286
+            endif
  287
+
  288
+            " Decho strftime("%X").' '.srch_str
  289
+
  290
+            " Mark the current line to return to
  291
+            let find_curline     = line(".")
  292
+            let find_curcol      = col(".")
  293
+
  294
+            if s:wm_debug == 1
  295
+                call s:WM_AddToResultBuffer( 'Finding: [' .
  296
+                            \ srch_str . ']', "" )
  297
+            endif
  298
+            let found_line = search( srch_str, "w" )
  299
+
  300
+            if check_for_missing == 1 && found_line == 0
  301
+                let s:wm_matching_cnt = s:wm_matching_cnt + 1
  302
+                call s:WM_AddToResultBuffer( s:wm_unescaped_findstr, "" )
  303
+            elseif check_for_missing == 0 && found_line > 0
  304
+                let s:wm_matching_cnt = s:wm_matching_cnt + 1
  305
+                call s:WM_AddToResultBuffer( s:wm_unescaped_findstr, "" )
  306
+            endif
  307
+
  308
+            " Switch back to the original buffer
  309
+            silent! exec "buffer " . s:wm_org_bufnr
  310
+
  311
+            " Return to previous location
  312
+            " call cursor(org_curline, org_curcol)
  313
+
  314
+        endif
  315
+
  316
+    endwhile
  317
+
  318
+    silent! exec "buffer " . s:wm_org_bufnr
  319
+    " Undo the put = we did above
  320
+    undo
  321
+
  322
+    silent! exe 'noh'
  323
+
  324
+    " Restore previous cpoptions
  325
+    let &cpoptions   = l:old_cpoptions
  326
+    let &eventignore = l:old_eventignore
  327
+    let @" = saveReg
  328
+    " restore previous search
  329
+    let @/ = saveSearch
  330
+    let @z = saveZ
  331
+
  332
+    call s:WM_SetSummary()
  333
+    if s:wm_debug == 1
  334
+        call s:WM_AddToResultBuffer( 'Start: ' .
  335
+                    \ a:firstline .
  336
+                    \ '  End: ' .
  337
+                    \ a:lastline, 
  338
+                    \ "" )
  339
+    endif
  340
+
  341
+    " call s:WM_AddToResultBuffer( "EI:".&eventignore, "" )
  342
+endfunction
  343
+
  344
+function! s:WM_SetBufNbr( bufnr )
  345
+    if a:bufnr == s:wm_org_bufnr
  346
+        call s:WM_WarningMsg(
  347
+                    \ "Cannot choose the same buffer: " . a:bufnr
  348
+                    \ )
  349
+        return -1 
  350
+    endif
  351
+
  352
+    if !bufexists(a:bufnr)
  353
+        call s:WM_WarningMsg(
  354
+                    \ "Cannot find buffer #: " . a:bufnr
  355
+                    \ )
  356
+        return -1 
  357
+    endif
  358
+    let s:wm_find_bufnr = a:bufnr
  359
+    return 1
  360
+endfunction
  361
+
  362
+function! s:WM_SetFileName( filename )
  363
+    if !bufexists(bufnr(a:filename))
  364
+        if filereadable(a:filename)
  365
+            " load the file into a new buffer
  366
+            exec 'view ' .  a:filename
  367
+            if bufexists(bufnr(a:filename))
  368
+                let s:wm_find_bufnr = bufnr(a:filename)
  369
+            else
  370
+                call s:WM_WarningMsg(
  371
+                            \ "Failed to load: " . a:filename
  372
+                            \ )
  373
+                return -1
  374
+            endif
  375
+        else
  376
+            call s:WM_WarningMsg(
  377
+                        \ "Cannot find: " . a:filename
  378
+                        \ )
  379
+            return -1
  380
+        endif
  381
+    else
  382
+        let s:wm_find_bufnr = bufnr(a:filename)
  383
+    endif
  384
+    let s:wm_filename = a:filename
  385
+
  386
+    return 1
  387
+endfunction
  388
+
  389
+function! s:WM_AddToResultBuffer(output, do_clear)
  390
+    " store current window number so we can return to it
  391
+    let cur_winnr = winnr()
  392
+
  393
+    " do not use bufexists(s:wm_missing_buf_name), since it uses a fully
  394
+    " qualified path name to search for the buffer, which in effect opens
  395
+    " multiple buffers called "result" if the files that you are executing the
  396
+    " commands from are in different directories.
  397
+    let s:wm_missing_bufnr = bufnr(s:wm_missing_buf_name)
  398
+
  399
+    if s:wm_missing_bufnr == -1
  400
+        " create the new buffer
  401
+        silent exec 'belowright ' . s:wm_buffer_lines . 'new ' . s:wm_missing_buf_name
  402
+        let s:wm_missing_bufnr = bufnr("%")
  403
+    else
  404
+        if bufwinnr(s:wm_missing_bufnr) == -1
  405
+            " if the buffer is not visible, wipe it out and recreate it,
  406
+            " this will position us in the new buffer
  407
+            exec 'bwipeout! ' . s:wm_missing_bufnr
  408
+            silent exec 'bot ' . s:wm_buffer_lines . 'new ' . s:wm_missing_buf_name
  409
+        else
  410
+          " if the buffer is visible, switch to it
  411
+          exec bufwinnr(s:wm_missing_bufnr) . "wincmd w"
  412
+        endif
  413
+    endif
  414
+    setlocal modified
  415
+    " create a buffer mapping to clo this window
  416
+    nnoremap <buffer> q :clo<cr>
  417
+    " delete all the lines prior to this run
  418
+    if a:do_clear == "clear" 
  419
+        %d
  420
+    endif
  421
+
  422
+    if strlen(a:output) > 0
  423
+        " add to end of buffer
  424
+        silent! exec "$put =a:output"
  425
+    endif
  426
+
  427
+    " since this is a small window, remove any blanks lines
  428
+    silent %g/^\s*$/d
  429
+    " fix the ^m characters, if any
  430
+    silent execute "%s/\<c-m>\\+$//e"
  431
+    " dont allow modifications, and do not wrap the text, since
  432
+    " the data may be lined up for columns
  433
+    setlocal nomodified
  434
+    setlocal nowrap
  435
+    " go to top of output
  436
+    norm gg
  437
+    " return to original window
  438
+    exec cur_winnr."wincmd w"
  439
+
  440
+    return
  441
+endfunction 
  442
+
  443
+function! s:WM_GetNextFindStr(startline)
  444
+    if s:wm_find_mode == 'word'
  445
+        normal! wyiw
  446
+        let s:wm_unescaped_findstr = @"
  447
+    elseif s:wm_find_mode == 'line'
  448
+        normal! j
  449
+        let s:wm_unescaped_findstr = getline(".")
  450
+    endif
  451
+
  452
+    " Escape various special characters
  453
+    let findstr = escape(s:wm_unescaped_findstr, '\\/.*$^~[]' )
  454
+    let findstr = substitute(
  455
+                \ substitute(findstr, "\n$", "", ""),
  456
+                \ "\n", '\\_[[:return:]]', "g")
  457
+    return findstr
  458
+endfunction
  459
+
  460
+function! s:WM_GetFindBufferOptions()
  461
+    silent! exec "buffer " . s:wm_find_bufnr
  462
+    let s:wm_find_filetype = &filetype
  463
+    silent! exec "buffer " . s:wm_org_bufnr
  464
+endfunction
  465
+
  466
+function! s:WM_PromptOptions()
  467
+    " Mode
  468
+    let response = (s:wm_find_mode == 'word' ? '1' : '2' ) 
  469
+    let response = confirm("Choose compare method:",
  470
+                \ "&Word\n&Line",
  471
+                \ response
  472
+                \ )
  473
+    let s:wm_find_mode = (response == '1' ? 'word' : 'line' )
  474
+    
  475
+    " Ignore Case
  476
+    let response = (s:wm_ignore_case ==# '' ? '1' : 
  477
+                \ (s:wm_ignore_case ==# '\c' ? '3' : '2' ) )
  478
+    let response = confirm("Do you want to ignore case?",
  479
+                \ "&Default\n&Yes\n&No",
  480
+                \ response
  481
+                \ )
  482
+    let s:wm_ignore_case = (response ==# '1' ? '' : 
  483
+                \ (response ==# '2' ? '\C' : '\c' ) )
  484
+    
  485
+    " Ignore whitespace
  486
+    let response = (s:wm_ignore_whitespace == '' ? '1' : '2' )
  487
+    let response = confirm("Do you want to ignore whitespace?",
  488
+                \ "&No\n&Yes",
  489
+                \ response
  490
+                \ )
  491
+    let s:wm_ignore_whitespace = (response ==# '1' ? '' : '\s*' )
  492
+endfunction
  493
+
  494
+function! s:WM_SetSummary()
  495
+    let WMOptions = "----------\nWMOptions:\n" .
  496
+                \ WM_GetOption('mode').' '.
  497
+                \ WM_GetOption('ignore_case').' '.
  498
+                \ WM_GetOption('ignore_whitespace')
  499
+    call s:WM_AddToResultBuffer(WMOptions, '')
  500
+
  501
+    silent! exec "buffer " . s:wm_missing_bufnr
  502
+    call cursor(1,1)
  503
+    exec 's/!matching!/'.s:wm_matching_cnt.'/e'
  504
+    exec 's/!checked!/'.s:wm_checked_cnt.'/e'
  505
+    let &filetype = s:wm_find_filetype
  506
+    setlocal nomodified
  507
+    silent! exec "buffer " . s:wm_org_bufnr
  508
+endfunction
  509
+
  510
+function! s:WM_CompleteOption(ArgLead, CmdLine, CursorPos)
  511
+
  512
+    if a:ArgLead =~? '^mode='
  513
+        let cmd_options = a:ArgLead .
  514
+                    \ substitute(s:wm_modes, ',', "\n".a:ArgLead, 'g')
  515
+    elseif a:ArgLead =~? '='
  516
+        let cmd_options = a:ArgLead . "0\n" .
  517
+                    \ a:ArgLead . "1"
  518
+    else
  519
+        let cmd_options = substitute(s:wm_options, ',', "\n", 'g')
  520
+    endif
  521
+
  522
+    return cmd_options
  523
+endfunction
  524
+
  525
+function! s:WM_WarningMsg(msg) 
  526
+    echohl WarningMsg
  527
+    echomsg "WM: " . a:msg
  528
+    echohl None
  529
+endfunction 
  530
+
  531
+command! -range=% -nargs=* WhatsMissing    <line1>,<line2>call WhatsMissing(<f-args>)
  532
+command! -range=% -nargs=* WhatsNotMissing <line1>,<line2>call WhatsNotMissing(<f-args>)
  533
+command! -nargs=1 -complete=custom,<SID>WM_CompleteOption WMGetOption :echo WM_GetOption(<q-args>)
  534
+command! -nargs=1 -complete=custom,<SID>WM_CompleteOption WMSetOption :call WM_SetOption(<q-args>)
  535
+
  536
+if has("gui_running") && has("menu")
  537
+    vnoremenu <script> Plugin.WhatsMissing.WhatsMissing :WhatsMissing<cr>
  538
+    nnoremenu <script> Plugin.WhatsMissing.WhatsMissing :WhatsMissing<cr>
  539
+    vnoremenu <script> Plugin.WhatsMissing.WhatsNotMissing :WhatsNotMissing<cr>
  540
+    nnoremenu <script> Plugin.WhatsMissing.WhatsNotMissing :WhatsNotMissing<cr>
  541
+endif
  542
+
  543
+
  544
+" vim:fdm=marker:nowrap:ts=4:expandtab:

0 notes on commit 082d620

Please sign in to comment.
Something went wrong with that request. Please try again.