11
11
" Organization:
12
12
" Version: see variable g:Templates_Version below
13
13
" Created: 30.08.2011
14
- " Revision: 11.02.2013
14
+ " Revision: 28.03.2014
15
15
" License: Copyright (c) 2012-2013, Wolfgang Mehner
16
16
" This program is free software; you can redistribute it and/or
17
17
" modify it under the terms of the GNU General Public License as
@@ -38,14 +38,103 @@ endif
38
38
"
39
39
" prevent duplicate loading
40
40
" need compatible
41
- if &cp || ( exists (' g:Templates_Version' ) && ! exists (' g:Templates_DevelopmentOverwrite' ) )
41
+ if &cp || ( exists (' g:Templates_Version' ) && g: Templates_Version != ' searching ' && ! exists (' g:Templates_DevelopmentOverwrite' ) )
42
42
finish
43
43
endif
44
- let g: Templates_Version= ' 0.9.2-1' " version number of this script; do not change
45
44
"
46
- if ! exists ( ' g:Templates_MapInUseWarn' )
47
- let g: Templates_MapInUseWarn = 1
45
+ let s: Templates_Version = ' 0.9.3' " version number of this script; do not change
46
+ "
47
+ " ----------------------------------------------------------------------
48
+ " --- Find Newest Version --- {{{2
49
+ " ----------------------------------------------------------------------
50
+ "
51
+ if exists (' g:Templates_DevelopmentOverwrite' )
52
+ " skip ahead
53
+ elseif exists (' g:Templates_VersionUse' )
54
+ "
55
+ " not the newest one: abort
56
+ if s: Templates_Version != g: Templates_VersionUse
57
+ finish
58
+ endif
59
+ "
60
+ " otherwise: skip ahead
61
+ "
62
+ elseif exists (' g:Templates_VersionSearch' )
63
+ "
64
+ " add own version number to the list
65
+ call add ( g: Templates_VersionSearch , s: Templates_Version )
66
+ "
67
+ finish
68
+ "
69
+ else
70
+ "
71
+ " -------------------------------------------------------------------------------
72
+ " s:VersionComp : Compare two version numbers. {{{3
73
+ "
74
+ " Parameters:
75
+ " op1 - first version number (string)
76
+ " op2 - second version number (string)
77
+ " Returns:
78
+ " result - -1, 0 or 1, to the specifications of sort() (integer)
79
+ " -------------------------------------------------------------------------------
80
+ function ! s: VersionComp ( op1, op2 )
81
+ "
82
+ let l1 = split ( a: op1 , ' [.-]' )
83
+ let l2 = split ( a: op2 , ' [.-]' )
84
+ "
85
+ for i in range ( 0 , max ( [ len ( l1 ), len ( l2 ) ] ) - 1 )
86
+ " until now, all fields where equal
87
+ if len ( l2 ) <= i
88
+ return -1 " op1 has more fields -> sorts first
89
+ elseif len ( l1 ) <= i
90
+ return 1 " op2 has more fields -> sorts first
91
+ elseif str2nr ( l1[i ] ) > str2nr ( l2[i ] )
92
+ return -1 " op1 is larger here -> sorts first
93
+ elseif str2nr ( l2[i ] ) > str2nr ( l1[i ] )
94
+ return 1 " op2 is larger here -> sorts first
95
+ endif
96
+ endfor
97
+ "
98
+ return 0 " same amount of fields, all equal
99
+ endfunction " ---------- end of function s:VersionComp ----------
100
+ " }}}3
101
+ " -------------------------------------------------------------------------------
102
+ "
103
+ try
104
+ "
105
+ " collect all available version
106
+ let g: Templates_Version = ' searching'
107
+ let g: Templates_VersionSearch = []
108
+ "
109
+ runtime ! autoload/mmtemplates/ core.vim
110
+ "
111
+ " select the newest one
112
+ call sort ( g: Templates_VersionSearch , ' s:VersionComp' )
113
+ "
114
+ let g: Templates_VersionUse = g: Templates_VersionSearch [ 0 ]
115
+ "
116
+ " run all scripts again, the newest one will be used
117
+ runtime ! autoload/mmtemplates/ core.vim
118
+ "
119
+ unlet g: Templates_VersionSearch
120
+ unlet g: Templates_VersionUse
121
+ "
122
+ finish
123
+ "
124
+ catch /.*/
125
+ "
126
+ " an error occurred, skip ahead
127
+ echohl WarningMsg
128
+ echomsg ' Search for the newest version number failed.'
129
+ echomsg ' Using this version (' .s: Templates_Version .' ).'
130
+ echohl None
131
+ endtry
132
+ "
48
133
endif
134
+ " }}}2
135
+ " -------------------------------------------------------------------------------
136
+ "
137
+ let g: Templates_Version = s: Templates_Version " version number of this script; do not change
49
138
"
50
139
" ----------------------------------------------------------------------
51
140
" === Modul Setup === {{{1
@@ -54,6 +143,10 @@ endif
54
143
let s: DebugGlobalOverwrite = 0
55
144
let s: DebugLevel = s: DebugGlobalOverwrite
56
145
"
146
+ if ! exists ( ' g:Templates_MapInUseWarn' )
147
+ let g: Templates_MapInUseWarn = 1
148
+ endif
149
+ "
57
150
let s: StateStackStyleTop = -2
58
151
let s: StateStackFile = -1
59
152
"
@@ -409,7 +502,7 @@ function! s:OpenFold ( mode )
409
502
" jump to the last line of the previously closed fold
410
503
let foldstart = foldclosed (" ." )
411
504
let foldend = foldclosedend (" ." )
412
- normal zv
505
+ normal ! zv
413
506
if a: mode == ' below'
414
507
exe " :" .foldend
415
508
elseif a: mode == ' start'
@@ -2495,7 +2588,7 @@ function! s:InsertIntoBuffer ( text, placement, indentation, flag_mode )
2495
2588
" puts the selected area into the buffer @"
2496
2589
let pos1 = line (" '<" )
2497
2590
let pos2 = line (" '>" ) + len (split ( text, ' \n' )) - 1
2498
- normal gvy
2591
+ normal ! gvy
2499
2592
let repl = escape ( part[0 ].@" .part[1 ], ' \&~' )
2500
2593
" substitute the selected area (using the '< and '> marks)
2501
2594
exe ' :s/\%'' <.*\%'' >./' .repl.' /'
@@ -2516,7 +2609,7 @@ function! s:InsertIntoBuffer ( text, placement, indentation, flag_mode )
2516
2609
" proper indenting
2517
2610
if indentation
2518
2611
silent exe " :" .pos1
2519
- silent exe " normal " .( pos2- pos1+ 1 )." =="
2612
+ silent exe " normal! " .( pos2- pos1+ 1 )." =="
2520
2613
endif
2521
2614
"
2522
2615
return [ pos1, pos2 ]
@@ -2533,8 +2626,8 @@ function! s:PositionCursor ( placement, flag_mode, pos1, pos2 )
2533
2626
" :TODO:12.08.2013 11:03:WM: changeable syntax?
2534
2627
" :TODO:12.08.2013 12:00:WM: change behavior?
2535
2628
"
2536
- exe " : " . a: pos1
2537
- let mtch = search ( ' <CURSOR>\|{CURSOR}' , ' c' , a: pos2 )
2629
+ call setpos ( ' . ' , [ bufnr ( ' % ' ), a: pos1, 1 , 0 ] )
2630
+ let mtch = search ( ' \m <CURSOR>\|{CURSOR}' , ' c' , a: pos2 )
2538
2631
if mtch != 0
2539
2632
" tag found (and cursor moved, we are now at the position of the match)
2540
2633
let line = getline (mtch)
@@ -2545,9 +2638,9 @@ function! s:PositionCursor ( placement, flag_mode, pos1, pos2 )
2545
2638
" if a:flag_mode == 'v' && getline('.') =~ '^\s*\%(<CURSOR>\|{CURSOR}\)\s*$'
2546
2639
" the line contains nothing but the tag: remove and join without
2547
2640
" changing the second line
2548
- normal J
2641
+ normal ! J
2549
2642
" call setline( mtch, '' )
2550
- " normal gJ
2643
+ " normal! gJ
2551
2644
else
2552
2645
" the line contains other characters: remove the tag and start appending
2553
2646
" call setline( mtch, substitute( line, '<CURSOR>\|{CURSOR}', '', '' ) )
@@ -2758,7 +2851,7 @@ function! mmtemplates#core#InsertTemplate ( library, t_name, ... ) range
2758
2851
" restore the state: folding and formatter program
2759
2852
if &foldenable
2760
2853
exe " set foldmethod=" .foldmethod_save
2761
- normal zv
2854
+ normal ! zv
2762
2855
endif
2763
2856
let &equalprg = equalprg_save
2764
2857
"
@@ -3034,11 +3127,11 @@ function! s:CreateSubmenu ( t_lib, root_menu, global_name, menu, priority )
3034
3127
let assemble .= ' .'
3035
3128
"
3036
3129
if -1 != stridx ( clean, ' <TAB>' )
3037
- exe ' amenu ' .priority_str.a: root_menu .escape ( assemble.clean, ' ' ).' :echo "This is a menu header."<CR>'
3130
+ exe ' anoremenu ' .priority_str.a: root_menu .escape ( assemble.clean, ' ' ).' :echo "This is a menu header."<CR>'
3038
3131
else
3039
- exe ' amenu ' .priority_str.a: root_menu .escape ( assemble.clean, ' ' ).' <TAB>' .escape ( a: global_name , ' .' ).' :echo "This is a menu header."<CR>'
3132
+ exe ' anoremenu ' .priority_str.a: root_menu .escape ( assemble.clean, ' ' ).' <TAB>' .escape ( a: global_name , ' .' ).' :echo "This is a menu header."<CR>'
3040
3133
endif
3041
- exe ' amenu ' .a: root_menu .escape ( assemble, ' ' ).' -TSep00- <Nop>'
3134
+ exe ' anoremenu ' .a: root_menu .escape ( assemble, ' ' ).' -TSep00- <Nop>'
3042
3135
endif
3043
3136
let submenu .= clean.' .'
3044
3137
endfor
@@ -3080,7 +3173,7 @@ function! s:CreateTemplateMenus ( t_lib, root_menu, global_name, t_lib_name )
3080
3173
let sep_nr = a: t_lib .menu_existing[ m_key ] + 1
3081
3174
let a: t_lib .menu_existing[ m_key ] = sep_nr
3082
3175
"
3083
- exe ' amenu ' .a: root_menu .escape ( t_menu, ' ' ).' -TSep' .sep_nr.' - :'
3176
+ exe ' anoremenu ' .a: root_menu .escape ( t_menu, ' ' ).' -TSep' .sep_nr.' - :'
3084
3177
"
3085
3178
continue
3086
3179
endif
@@ -3104,26 +3197,26 @@ function! s:CreateTemplateMenus ( t_lib, root_menu, global_name, t_lib_name )
3104
3197
"
3105
3198
if entry == 1
3106
3199
" <Esc><Esc> prevents problems in insert mode
3107
- exe ' amenu <silent> ' .a: root_menu .compl_entry.map_entry.' <Esc><Esc>:call mmtemplates#core#InsertTemplate(' .a: t_lib_name .' ,"' .t_name.' ")<CR>'
3108
- exe ' imenu <silent> ' .a: root_menu .compl_entry.map_entry.' <Esc><Esc>:call mmtemplates#core#InsertTemplate(' .a: t_lib_name .' ,"' .t_name.' ","i")<CR>'
3200
+ exe ' anoremenu <silent> ' .a: root_menu .compl_entry.map_entry.' <Esc><Esc>:call mmtemplates#core#InsertTemplate(' .a: t_lib_name .' ,"' .t_name.' ")<CR>'
3201
+ exe ' inoremenu <silent> ' .a: root_menu .compl_entry.map_entry.' <Esc><Esc>:call mmtemplates#core#InsertTemplate(' .a: t_lib_name .' ,"' .t_name.' ","i")<CR>'
3109
3202
if visual == 1
3110
- exe ' vmenu <silent> ' .a: root_menu .compl_entry.map_entry.' <Esc><Esc>:call mmtemplates#core#InsertTemplate(' .a: t_lib_name .' ,"' .t_name.' ","v")<CR>'
3203
+ exe ' vnoremenu <silent> ' .a: root_menu .compl_entry.map_entry.' <Esc><Esc>:call mmtemplates#core#InsertTemplate(' .a: t_lib_name .' ,"' .t_name.' ","v")<CR>'
3111
3204
endif
3112
3205
elseif entry == 2
3113
3206
call s: CreateSubmenu ( a: t_lib , a: root_menu , a: global_name , t_menu.t_last.map_entry, s: StandardPriority )
3114
3207
"
3115
3208
for item in s: GetPickList ( t_name )
3116
3209
let item_entry = compl_entry.' .' .substitute ( substitute ( escape ( item, ' .' ), ' &' , ' \&\&' , ' g' ), ' \w' , ' \&&' , ' ' )
3117
- exe ' amenu <silent> ' .a: root_menu .item_entry.' <Esc><Esc>:call mmtemplates#core#InsertTemplate(' .a: t_lib_name .' ,"' .t_name.' ","pick",' .string (item).' )<CR>'
3118
- exe ' imenu <silent> ' .a: root_menu .item_entry.' <Esc><Esc>:call mmtemplates#core#InsertTemplate(' .a: t_lib_name .' ,"' .t_name.' ","i","pick",' .string (item).' )<CR>'
3210
+ exe ' anoremenu <silent> ' .a: root_menu .item_entry.' <Esc><Esc>:call mmtemplates#core#InsertTemplate(' .a: t_lib_name .' ,"' .t_name.' ","pick",' .string (item).' )<CR>'
3211
+ exe ' inoremenu <silent> ' .a: root_menu .item_entry.' <Esc><Esc>:call mmtemplates#core#InsertTemplate(' .a: t_lib_name .' ,"' .t_name.' ","i","pick",' .string (item).' )<CR>'
3119
3212
if visual == 1
3120
- exe ' vmenu <silent> ' .a: root_menu .item_entry.' <Esc><Esc>:call mmtemplates#core#InsertTemplate(' .a: t_lib_name .' ,"' .t_name.' ","v","pick",' .string (item).' )<CR>'
3213
+ exe ' vnoremenu <silent> ' .a: root_menu .item_entry.' <Esc><Esc>:call mmtemplates#core#InsertTemplate(' .a: t_lib_name .' ,"' .t_name.' ","v","pick",' .string (item).' )<CR>'
3121
3214
endif
3122
3215
endfor
3123
3216
"
3124
- " exe 'amenu '.a:root_menu.compl_entry.'.-\ choose\ -'.map_entry.' <Esc><Esc>:call mmtemplates#core#InsertTemplate('.a:t_lib_name.',"'.t_name.'")<CR>'
3217
+ " exe 'anoremenu '.a:root_menu.compl_entry.'.-\ choose\ -'.map_entry.' <Esc><Esc>:call mmtemplates#core#InsertTemplate('.a:t_lib_name.',"'.t_name.'")<CR>'
3125
3218
" if visual == 1
3126
- " exe 'vmenu '.a:root_menu.compl_entry.'.-\ choose\ -'.map_entry.' <Esc><Esc>:call mmtemplates#core#InsertTemplate('.a:t_lib_name.',"'.t_name.'","v")<CR>'
3219
+ " exe 'vnoremenu '.a:root_menu.compl_entry.'.-\ choose\ -'.map_entry.' <Esc><Esc>:call mmtemplates#core#InsertTemplate('.a:t_lib_name.',"'.t_name.'","v")<CR>'
3127
3220
" endif
3128
3221
endif
3129
3222
"
@@ -3155,9 +3248,9 @@ function! s:CreateSpecialsMenus ( t_lib, root_menu, global_name, t_lib_name, spe
3155
3248
" create edit and reread templates
3156
3249
let entry_edit = s: InsertShortcut ( ' .edit\ templates' , sc_edit, 1 ).' <TAB>' .map_edit
3157
3250
let entry_read = s: InsertShortcut ( ' .reread\ templates' , sc_read, 1 ).' <TAB>' .map_read
3158
- exe ' amenu <silent> ' .a: root_menu .specials_menu.entry_edit
3251
+ exe ' anoremenu <silent> ' .a: root_menu .specials_menu.entry_edit
3159
3252
\ .' :call mmtemplates#core#EditTemplateFiles(' .a: t_lib_name .' ,-1)<CR>'
3160
- exe ' amenu <silent> ' .a: root_menu .specials_menu.entry_read
3253
+ exe ' anoremenu <silent> ' .a: root_menu .specials_menu.entry_read
3161
3254
\ .' :call mmtemplates#core#ReadTemplates(' .a: t_lib_name .' ,"reload","all")<CR>'
3162
3255
endif
3163
3256
"
@@ -3168,7 +3261,7 @@ function! s:CreateSpecialsMenus ( t_lib, root_menu, global_name, t_lib_name, spe
3168
3261
call s: CreateSubmenu ( a: t_lib , a: root_menu , a: global_name , specials_menu.entry_styles, s: StandardPriority )
3169
3262
"
3170
3263
for s in a: t_lib .styles
3171
- exe ' amenu <silent> ' .a: root_menu .specials_menu.' .choose\ style.&' .s
3264
+ exe ' anoremenu <silent> ' .a: root_menu .specials_menu.' .choose\ style.&' .s
3172
3265
\ .' :call mmtemplates#core#ChooseStyle(' .a: t_lib_name .' ,' .string (s ).' )<CR>'
3173
3266
endfor
3174
3267
"
@@ -3735,7 +3828,7 @@ endfunction " ---------- end of function mmtemplates#core#EditTemplateFiles
3735
3828
"
3736
3829
function ! mmtemplates#core#JumpToTag ( regex )
3737
3830
"
3738
- let match = search ( a: regex , ' c' )
3831
+ let match = search ( ' \m ' . a: regex , ' c' )
3739
3832
if match > 0
3740
3833
" remove the target
3741
3834
call setline ( match , substitute ( getline (' .' ), a: regex , ' ' , ' ' ) )
@@ -3744,6 +3837,46 @@ function! mmtemplates#core#JumpToTag ( regex )
3744
3837
return ' '
3745
3838
endfunction " ---------- end of function mmtemplates#core#JumpToTag ----------
3746
3839
"
3840
+ " ----------------------------------------------------------------------
3841
+ " mmtemplates#core#SetMapleader : Set the local mapleader. {{{1
3842
+ " ----------------------------------------------------------------------
3843
+ "
3844
+ " list of lists: [ "<localleader>", "<globalleader>" ]
3845
+ let s: mapleader_stack = []
3846
+ "
3847
+ function ! mmtemplates#core#SetMapleader ( localleader )
3848
+ "
3849
+ if empty ( a: localleader )
3850
+ call add ( s: mapleader_stack , [] )
3851
+ else
3852
+ if exists ( ' g:maplocalleader' )
3853
+ call add ( s: mapleader_stack , [ a: localleader , g: maplocalleader ] )
3854
+ else
3855
+ call add ( s: mapleader_stack , [ a: localleader ] )
3856
+ endif
3857
+ let g: maplocalleader = a: localleader
3858
+ endif
3859
+ "
3860
+ endfunction " ---------- end of function mmtemplates#core#SetMapleader ----------
3861
+ "
3862
+ " ----------------------------------------------------------------------
3863
+ " mmtemplates#core#ResetMapleader : Reset the local mapleader. {{{1
3864
+ " ----------------------------------------------------------------------
3865
+ "
3866
+ function ! mmtemplates#core#ResetMapleader ()
3867
+ "
3868
+ let ll_save = remove ( s: mapleader_stack , -1 )
3869
+ "
3870
+ if ! empty ( ll_save )
3871
+ if len ( ll_save ) > 1
3872
+ let g: maplocalleader = ll_save[1 ]
3873
+ else
3874
+ unlet g: maplocalleader
3875
+ endif
3876
+ endif
3877
+ "
3878
+ endfunction " ---------- end of function mmtemplates#core#ResetMapleader ----------
3879
+ "
3747
3880
" }}}1
3748
3881
"
3749
3882
" =====================================================================================
0 commit comments