27
27
" warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
28
28
" PURPOSE.
29
29
" See the GNU General Public License version 2 for more details.
30
- " Revision: $Id: c.vim,v 1.156 2011/12/27 21:05:07 mehner Exp $
30
+ " Revision: $Id: c.vim,v 1.162 2012/02/25 15:15:30 mehner Exp $
31
31
"
32
32
" ------------------------------------------------------------------------------
33
33
"
@@ -55,6 +55,8 @@ let s:MSWIN = has("win16") || has("win32") || has("win64") || has("win95")
55
55
let s: UNIX = has (" unix" ) || has (" macunix" ) || has (" win32unix" )
56
56
"
57
57
let s: installation = ' *undefined*'
58
+ let s: plugin_dir = ' '
59
+ "
58
60
let s: C_GlobalTemplateFile = ' '
59
61
let s: C_GlobalTemplateDir = ' '
60
62
let s: C_LocalTemplateFile = ' '
@@ -85,20 +87,17 @@ if s:MSWIN
85
87
endif
86
88
"
87
89
let s: C_FilenameEscChar = ' '
88
- let s: C_Display = ' '
89
90
"
90
91
else
91
92
" ========== Linux/Unix ======================================================
92
93
"
93
94
if match ( expand (" <sfile>" ), expand (" $HOME" ) ) == 0
94
- "
95
95
" USER INSTALLATION ASSUMED
96
96
let s: installation = ' local'
97
97
let s: plugin_dir = expand (' <sfile>:p:h:h' )
98
98
let s: C_LocalTemplateFile = s: plugin_dir .' /c-support/templates/Templates'
99
99
let s: C_LocalTemplateDir = fnamemodify ( s: C_LocalTemplateFile , " :p:h" ).' /'
100
100
else
101
- "
102
101
" SYSTEM WIDE INSTALLATION
103
102
let s: installation = ' system'
104
103
let s: plugin_dir = $VIM .' /vimfiles'
109
108
endif
110
109
"
111
110
let s: C_FilenameEscChar = ' \%#[]'
112
- let s: C_Display = $DISPLAY
113
111
"
114
112
endif
115
113
"
@@ -187,6 +185,7 @@ call C_CheckGlobal('C_CodeCheckExeName ')
187
185
call C_CheckGlobal (' C_CodeCheckOptions ' )
188
186
call C_CheckGlobal (' C_CodeSnippets ' )
189
187
call C_CheckGlobal (' C_CplusCompiler ' )
188
+ call C_CheckGlobal (' C_CreateMenusDelayed ' )
190
189
call C_CheckGlobal (' C_Ctrl_j ' )
191
190
call C_CheckGlobal (' C_ExeExtension ' )
192
191
call C_CheckGlobal (' C_FormatDate ' )
@@ -200,7 +199,6 @@ call C_CheckGlobal('C_LFlags ')
200
199
call C_CheckGlobal (' C_Libs ' )
201
200
call C_CheckGlobal (' C_LineEndCommColDefault' )
202
201
call C_CheckGlobal (' C_LoadMenus ' )
203
- call C_CheckGlobal (' C_CreateMenusDelayed ' )
204
202
call C_CheckGlobal (' C_LocalTemplateFile ' )
205
203
call C_CheckGlobal (' C_Man ' )
206
204
call C_CheckGlobal (' C_MenuHeader ' )
@@ -1739,14 +1737,14 @@ function! C_ProtoPick( type ) range
1739
1737
"
1740
1738
let prototyp = substitute ( prototyp, ' ^template\s*<\s*class \w\+\s*>\s*' , " " , " " )
1741
1739
"
1742
- let idx = stridx ( prototyp, ' (' ) " start of the parameter list
1743
- let head = strpart ( prototyp, 0 , idx )
1740
+ let idx = stridx ( prototyp, ' (' ) " start of the parameter list
1741
+ let head = strpart ( prototyp, 0 , idx )
1744
1742
let parlist = strpart ( prototyp, idx )
1745
1743
"
1746
1744
" remove the scope resolution operator
1747
1745
"
1748
- let template_id = ' \h\w*\s*<[^>]\+>'
1749
- let rgx2 = ' \(' .template_id.' \s*::\s*\)*\([~A-Za-z] \w*\|operator.\+\)\s*$'
1746
+ let template_id = ' \h\w*\s*\( <[^>]\+>\)\? '
1747
+ let rgx2 = ' \(' .template_id.' \s*::\s*\)*\([~]\?\h \w*\|operator.\+\)\s*$'
1750
1748
let idx = match ( head, rgx2 ) " start of the function name
1751
1749
let returntype = strpart ( head, 0 , idx )
1752
1750
let fctname = strpart ( head, idx )
@@ -2193,7 +2191,7 @@ function! C_Toggle_Gvim_Xterm ()
2193
2191
exe " amenu <silent> " .s: MenuRun .' .&output:\ VIM->buffer->xterm<Tab>\\ro :call C_Toggle_Gvim_Xterm()<CR><CR>'
2194
2192
exe " imenu <silent> " .s: MenuRun .' .&output:\ VIM->buffer->xterm<Tab>\\ro <C-C>:call C_Toggle_Gvim_Xterm()<CR><CR>'
2195
2193
endif
2196
- if (! s: MSWIN ) && (! empty (s: C_Display ))
2194
+ if (! s: MSWIN ) && (! empty ($Display ))
2197
2195
let s: C_OutputGvim = " xterm"
2198
2196
else
2199
2197
let s: C_OutputGvim = " vim"
@@ -2851,6 +2849,14 @@ endfunction " ---------- end of function C_BrowseTemplateFiles ----------
2851
2849
"
2852
2850
" ------------------------------------------------------------------------------
2853
2851
let s: style = ' default'
2852
+
2853
+ function ! C_CheckAndRereadTemplates ()
2854
+ if s: C_TemplatesLoaded == ' no'
2855
+ call C_RereadTemplates (' no' )
2856
+ let s: C_TemplatesLoaded = ' yes'
2857
+ endif
2858
+ endfunction " ---------- end of function C_CheckAndRereadTemplates ----------
2859
+
2854
2860
function ! C_ReadTemplates ( templatefile )
2855
2861
2856
2862
if ! filereadable ( a: templatefile )
@@ -2956,6 +2962,7 @@ endfunction " ---------- end of function C_ReadTemplates ----------
2956
2962
" ex-command CStyle : callback function
2957
2963
" ------------------------------------------------------------------------------
2958
2964
function ! C_Style ( style )
2965
+ call C_CheckAndRereadTemplates ()
2959
2966
let lstyle = substitute ( a: style , ' ^\s\+' , " " , " " ) " remove leading whitespaces
2960
2967
let lstyle = substitute ( lstyle, ' \s\+$' , " " , " " ) " remove trailing whitespaces
2961
2968
if has_key ( s: C_Template , lstyle )
@@ -3139,7 +3146,9 @@ function! C_InsertTemplate ( key, ... )
3139
3146
if mode == ' insert'
3140
3147
let pos1 = line (" ." )
3141
3148
let pos2 = pos1
3142
- let string = @*
3149
+ " windows: recover area of the visual mode and yank, puts the selected area in the buffer
3150
+ normal gvy
3151
+ let string = eval (' @"' )
3143
3152
let replacement = part[0 ].string .part[1 ]
3144
3153
" remove trailing '\n'
3145
3154
let replacement = substitute ( replacement, ' \n$' , ' ' , ' ' )
@@ -3184,11 +3193,7 @@ function! C_InsertTemplate ( key, ... )
3184
3193
if a: 0 != 0 && a: 1 == ' v' && getline (" ." ) = ~ ' ^\s*$'
3185
3194
normal J
3186
3195
else
3187
- if getpos (" ." )[2 ] < len (getline (" ." )) || mode == ' insert'
3188
- :startinsert
3189
- else
3190
- :startinsert !
3191
- endif
3196
+ :startinsert !
3192
3197
endif
3193
3198
else
3194
3199
call setline ( mtch, substitute ( line , ' <CURSOR>\|{CURSOR}' , ' ' , ' ' ) )
@@ -3456,6 +3461,8 @@ endfunction " ---------- end of function C_DateAndTime ----------
3456
3461
" ------------------------------------------------------------------------------
3457
3462
function ! C_InsertTemplateWrapper ()
3458
3463
" prevent insertion for a file generated from a link error:
3464
+ "
3465
+ call C_CheckAndRereadTemplates ()
3459
3466
if isdirectory (expand (' %:p:h' ))
3460
3467
if index ( s: C_SourceCodeExtensionsList , expand (' %:e' ) ) >= 0
3461
3468
call C_InsertTemplate (" comment.file-description" )
@@ -3687,9 +3694,6 @@ if s:C_LoadMenus == 'yes' && s:C_CreateMenusDelayed == 'no'
3687
3694
call C_CreateGuiMenus ()
3688
3695
endif
3689
3696
"
3690
- nmap <unique> <silent> <Leader> lcs :call C_CreateGuiMenus()<CR>
3691
- nmap <unique> <silent> <Leader> ucs :call C_RemoveGuiMenus()<CR>
3692
- "
3693
3697
" ------------------------------------------------------------------------------
3694
3698
" Automated header insertion
3695
3699
" Local settings for the quickfix window
@@ -3719,26 +3723,27 @@ if has("autocmd")
3719
3723
\ if (&filetype == ' cpp' || &filetype == ' c' ) |
3720
3724
\ call C_CreateMenusDelayed () |
3721
3725
\ endif
3722
- "
3723
- " Automated header insertion (suffixes from the gcc manual)
3724
- "
3725
- if ! exists ( ' g:C_Styles' )
3726
- " -------------------------------------------------------------------------------
3727
- " template styles are the default settings
3728
- " -------------------------------------------------------------------------------
3729
- autocmd BufNewFile * if &filetype = ~ ' ^\(c\|cpp\)$' && expand (" %:e" ) !~ ' ii\?' |
3730
- \ call C_InsertTemplateWrapper () | endif
3731
- "
3732
- else
3726
+
3733
3727
" -------------------------------------------------------------------------------
3734
- " template styles are related to file extensions
3728
+ " style switching :Automated header insertion (suffixes from the gcc manual)
3735
3729
" -------------------------------------------------------------------------------
3736
- for [ pattern, stl ] in items ( g: C_Styles )
3737
- exe " autocmd BufNewFile,BufRead,BufEnter " .pattern." call C_Style( '" .stl ." ' )"
3738
- exe " autocmd BufNewFile " .pattern." call C_InsertTemplateWrapper()"
3739
- endfor
3740
- "
3741
- endif
3730
+ if ! exists ( ' g:C_Styles' )
3731
+ " -------------------------------------------------------------------------------
3732
+ " template styles are the default settings
3733
+ " -------------------------------------------------------------------------------
3734
+ autocmd BufNewFile * if &filetype = ~ ' ^\(c\|cpp\)$' && expand (" %:e" ) !~ ' ii\?' |
3735
+ \ call C_InsertTemplateWrapper () | endif
3736
+ "
3737
+ else
3738
+ " -------------------------------------------------------------------------------
3739
+ " template styles are related to file extensions
3740
+ " -------------------------------------------------------------------------------
3741
+ for [ pattern, stl ] in items ( g: C_Styles )
3742
+ exe " autocmd BufNewFile,BufRead,BufEnter " .pattern." call C_Style( '" .stl ." ' )"
3743
+ exe " autocmd BufNewFile " .pattern." call C_InsertTemplateWrapper()"
3744
+ endfor
3745
+ "
3746
+ endif
3742
3747
"
3743
3748
" Wrap error descriptions in the quickfix window.
3744
3749
"
0 commit comments