41
41
if &cp || ( exists (' g:Templates_Version' ) && ! exists (' g:Templates_DevelopmentOverwrite' ) )
42
42
finish
43
43
endif
44
- let g: Templates_Version= ' 0.9.1.1 ' " version number of this script; do not change
44
+ let g: Templates_Version= ' 0.9.2 ' " version number of this script; do not change
45
45
"
46
46
if ! exists ( ' g:Templates_MapInUseWarn' )
47
47
let g: Templates_MapInUseWarn = 1
@@ -69,6 +69,8 @@ let s:Flagactions = {
69
69
"
70
70
let s: StandardPriority = 500
71
71
"
72
+ let g: CheckedFiletypes = {}
73
+ "
72
74
" ----------------------------------------------------------------------
73
75
" s:StandardMacros : The standard macros. {{{2
74
76
" ----------------------------------------------------------------------
@@ -213,7 +215,6 @@ function! s:UpdateTemplateRegex ( regex, settings )
213
215
let a: regex .MacroName = a: settings .MacroName
214
216
let a: regex .MacroNameC = ' \(' .a: settings .MacroName.' \)'
215
217
let a: regex .MacroMatch = ' ^' .a: settings .MacroStart.a: settings .MacroName.a: settings .MacroEnd.' $'
216
- let a: regex .MacroSimple = a: settings .MacroStart.a: settings .MacroName.a: settings .MacroEnd
217
218
"
218
219
" Syntax Categories
219
220
let a: regex .FunctionLine = ' ^' .a: settings .MacroStart.' \(' .a: regex .MacroNameC.' (\(.*\))\)' .a: settings .MacroEnd.' \s*\n'
@@ -223,6 +224,7 @@ function! s:UpdateTemplateRegex ( regex, settings )
223
224
let a: regex .FunctionInsert = a: settings .MacroStart.' \(Insert\|InsertLine\)' .' (\(.\{-}\))' .a: settings .MacroEnd
224
225
let a: regex .MacroRequest = a: settings .MacroStart.' ?' .a: regex .MacroNameC.' \%(:\(\a\)\)\?' .a: settings .MacroEnd
225
226
let a: regex .MacroInsert = a: settings .MacroStart.' ' .a: regex .MacroNameC.' \%(:\(\a\)\)\?' .a: settings .MacroEnd
227
+ let a: regex .MacroNoCapture = a: settings .MacroStart.a: settings .MacroName.' \%(:\a\)\?' .a: settings .MacroEnd
226
228
let a: regex .ListItem = a: settings .MacroStart.' ' .a: regex .MacroNameC.' :ENTRY_*' .a: settings .MacroEnd
227
229
"
228
230
let a: regex .TextBlockFunctions = ' ^\%(C\|Comment\|Insert\|InsertLine\)$'
@@ -361,7 +363,10 @@ endfunction " ---------- end of function s:UserInput ----------
361
363
" ----------------------------------------------------------------------
362
364
"
363
365
function ! mmtemplates#core#UserInputEx ( ArgLead, CmdLine, CursorPos )
364
- return filter ( copy ( s: UserInputList ), ' v:val =~ "\\V\\<' .escape (a: ArgLead ,' \' ).' \\w\\*"' )
366
+ if empty ( a: ArgLead )
367
+ return copy ( s: UserInputList )
368
+ endif
369
+ return filter ( copy ( s: UserInputList ), ' v:val =~ '' \V\<' .escape (a: ArgLead ,' \' ).' \w\*'' ' )
365
370
endfunction " ---------- end of function mmtemplates#core#UserInputEx ----------
366
371
" }}}3
367
372
"
@@ -842,12 +847,12 @@ let s:FileReadNameSpace = {
842
847
\ ' SetFormat' : ' ss' ,
843
848
\ ' SetMacro' : ' ss' ,
844
849
\ ' SetPath' : ' ss' ,
850
+ \ ' SetProperty' : ' ss' ,
845
851
\ ' SetStyle' : ' s' ,
846
852
\
847
853
\ ' MenuShortcut' : ' ss' ,
848
854
\ }
849
855
" \ 'SetMap' : 'ss',
850
- " \ 'SetProperty' : 'ss',
851
856
" \ 'SetShortcut' : 'ss',
852
857
"
853
858
" ----------------------------------------------------------------------
@@ -946,12 +951,16 @@ function! s:SetMap ( name, map )
946
951
endfunction " ---------- end of function s:SetMap ----------
947
952
"
948
953
" ----------------------------------------------------------------------
949
- " s:SetProperty : TODO (template function) . {{{2
954
+ " s:SetProperty : Set an existing property . {{{2
950
955
" ----------------------------------------------------------------------
951
956
"
952
- function ! s: SetProperty ( name, shortcut )
957
+ function ! s: SetProperty ( name, value )
953
958
"
954
- echo ' SetProperty: TO BE IMPLEMENTED'
959
+ let [ _, err ] = mmtemplates#core#Resource ( s: library , ' set' , ' property' , a: name , a: value )
960
+ "
961
+ if err != ' '
962
+ return s: ErrorMsg ( ' Can not set the property "' .a: name .' ".' )
963
+ endif
955
964
"
956
965
endfunction " ---------- end of function s:SetProperty ----------
957
966
"
@@ -1484,7 +1493,7 @@ function! s:ReplaceMacros ( text, m_local )
1484
1493
let m_text = get ( s: library .macros, mlist[2 ], ' ' )
1485
1494
end
1486
1495
"
1487
- if m_text = ~ s: library .regex_template.MacroSimple
1496
+ if m_text = ~ s: library .regex_template.MacroNoCapture
1488
1497
"
1489
1498
call add ( s: t_runtime .macro_stack, mlist[2 ] )
1490
1499
"
@@ -2481,16 +2490,16 @@ function! s:InsertIntoBuffer ( text, placement, indentation, flag_mode )
2481
2490
" part0 and part1 can consist of several lines
2482
2491
"
2483
2492
if placement == ' insert'
2484
- " [_,line,col,off] = getpos()
2485
- let [_,l1,c1,o1] = getpos (" '<" )
2486
- let [_,l2,c2,o2] = getpos (" '>" )
2487
- call cursor ( l2, c2, o2 )
2488
- exe ' normal! a' .part[1 ]
2489
- call cursor ( l1, c1, o1 )
2490
- exe ' normal! i' .part[0 ]
2493
+ " windows: register @* does not work
2494
+ " solution: recover area of the visual mode and yank,
2495
+ " puts the selected area into the buffer @"
2496
+ let pos1 = line (" '<" )
2497
+ let pos2 = line (" '>" ) + len (split ( text, ' \n' )) - 1
2498
+ normal gvy
2499
+ let repl = escape ( part[0 ].@" .part[1 ], ' \&~' )
2500
+ " substitute the selected area (using the '< and '> marks)
2501
+ exe ' :s/\%'' <.*\%'' >./' .repl.' /'
2491
2502
let indentation = 0
2492
- let pos1 = l1
2493
- let pos2 = l2 + len (split ( text, ' \n' )) - 1
2494
2503
elseif placement == ' below'
2495
2504
silent '<put ! = part[0 ]
2496
2505
silent '>put = part[1 ]
@@ -2521,26 +2530,39 @@ endfunction " ---------- end of function s:InsertIntoBuffer ----------
2521
2530
"
2522
2531
function ! s: PositionCursor ( placement, flag_mode, pos1, pos2 )
2523
2532
"
2524
- " TODO: syntax
2533
+ " :TODO:12.08.2013 11:03:WM: changeable syntax?
2534
+ " :TODO:12.08.2013 12:00:WM: change behavior?
2525
2535
"
2526
2536
exe " :" .a: pos1
2527
2537
let mtch = search ( ' <CURSOR>\|{CURSOR}' , ' c' , a: pos2 )
2528
- if mtch != 0 " CURSOR found:
2538
+ if mtch != 0
2539
+ " tag found (and cursor moved, we are now at the position of the match)
2529
2540
let line = getline (mtch)
2530
2541
if line = ~ ' <CURSOR>$\|{CURSOR}$'
2542
+ " the tag is at the end of the line
2531
2543
call setline ( mtch, substitute ( line , ' <CURSOR>\|{CURSOR}' , ' ' , ' ' ) )
2532
- if a: flag_mode == ' v' && getline (" ." ) = ~ ' ^\s*$'
2544
+ if a: flag_mode == ' v' && getline (' .' ) = ~ ' ^\s*$'
2545
+ " if a:flag_mode == 'v' && getline('.') =~ '^\s*\%(<CURSOR>\|{CURSOR}\)\s*$'
2546
+ " the line contains nothing but the tag: remove and join without
2547
+ " changing the second line
2533
2548
normal J
2549
+ " call setline( mtch, '' )
2550
+ " normal gJ
2534
2551
else
2552
+ " the line contains other characters: remove the tag and start appending
2553
+ " call setline( mtch, substitute( line, '<CURSOR>\|{CURSOR}', '', '' ) )
2535
2554
startinsert !
2536
2555
endif
2537
2556
else
2557
+ " the line contains other characters: remove the tag and start inserting
2538
2558
call setline ( mtch, substitute ( line , ' <CURSOR>\|{CURSOR}' , ' ' , ' ' ) )
2539
- : startinsert
2559
+ startinsert
2540
2560
endif
2541
- else " no CURSOR found
2561
+ else
2562
+ " no tag found (and cursor not moved)
2542
2563
if a: placement == ' below'
2543
- exe " :" .a: pos2 | " to the end of the block; needed for repeated inserts
2564
+ " to the end of the block, needed for repeated inserts
2565
+ exe " :" .a: pos2
2544
2566
endif
2545
2567
endif
2546
2568
"
@@ -2834,6 +2856,13 @@ function! mmtemplates#core#CreateMaps ( library, localleader, ... )
2834
2856
" generate new commands
2835
2857
" ==================================================
2836
2858
"
2859
+ if has_key ( g: CheckedFiletypes , &filetype )
2860
+ let echo_warning = 0
2861
+ else
2862
+ let g: CheckedFiletypes [ &filetype ] = 1
2863
+ let echo_warning = g: Templates_MapInUseWarn != 0
2864
+ endif
2865
+ "
2837
2866
" go through all the templates
2838
2867
for t_name in t_lib.menu_order
2839
2868
"
@@ -2849,7 +2878,7 @@ function! mmtemplates#core#CreateMaps ( library, localleader, ... )
2849
2878
"
2850
2879
" map already existing?
2851
2880
if ! empty ( maparg ( leader .mp , mode ) )
2852
- if g: Templates_MapInUseWarn != 0
2881
+ if echo_warning
2853
2882
call s: ErrorMsg ( ' Mapping already in use: "' .leader .mp .' ", mode "' .mode .' "' )
2854
2883
endif
2855
2884
continue
@@ -2877,7 +2906,9 @@ function! mmtemplates#core#CreateMaps ( library, localleader, ... )
2877
2906
if do_jump_map
2878
2907
let jump_key = ' <C-j>' " TODO: configurable
2879
2908
if ! empty ( maparg ( jump_key ) )
2880
- call s: ErrorMsg ( ' Mapping already in use: "' .jump_key.' "' )
2909
+ if echo_warning
2910
+ call s: ErrorMsg ( ' Mapping already in use: "' .jump_key.' "' )
2911
+ endif
2881
2912
else
2882
2913
let jump_regex = string ( escape ( t_lib.regex_template.JumpTagBoth, ' |' ) )
2883
2914
let cmd .= ' nnoremap ' .options .' ' .jump_key.' i<C-R>=mmtemplates#core#JumpToTag(' .jump_regex.' )<CR>' .sep
@@ -2897,7 +2928,9 @@ function! mmtemplates#core#CreateMaps ( library, localleader, ... )
2897
2928
"
2898
2929
for [ mp , action ] in items ( special_maps )
2899
2930
if ! empty ( maparg ( leader .mp ) )
2900
- call s: ErrorMsg ( ' Mapping already in use: "' .leader .mp .' "' )
2931
+ if echo_warning
2932
+ call s: ErrorMsg ( ' Mapping already in use: "' .leader .mp .' "' )
2933
+ endif
2901
2934
else
2902
2935
let cmd .= ' noremap ' .options .' ' .leader .mp .' ' .action.sep
2903
2936
let cmd .= ' inoremap ' .options .' ' .leader .mp .' <Esc>' .action.sep
@@ -3018,7 +3051,7 @@ endfunction " ---------- end of function s:CreateSubmenu ----------
3018
3051
"
3019
3052
function ! s: CreateTemplateMenus ( t_lib, root_menu, global_name, t_lib_name )
3020
3053
"
3021
- let map_ldr = mmtemplates#core#EscapeMenu ( a: t_lib .properties[ ' Templates::Mapleader' ] )
3054
+ let map_ldr = mmtemplates#core#EscapeMenu ( a: t_lib .properties[ ' Templates::Mapleader' ], ' right ' )
3022
3055
"
3023
3056
" go through all the templates
3024
3057
for t_name in a: t_lib .menu_order
@@ -3107,13 +3140,13 @@ function! s:CreateSpecialsMenus ( t_lib, root_menu, global_name, t_lib_name, spe
3107
3140
" remove trailing point
3108
3141
let specials_menu = substitute ( a: specials_menu , ' \.$' , ' ' , ' ' )
3109
3142
"
3110
- let map_ldr = mmtemplates#core#EscapeMenu ( a: t_lib .properties[ ' Templates::Mapleader' ] )
3111
- let map_edit = map_ldr.mmtemplates#core#EscapeMenu ( a: t_lib .properties[ ' Templates::EditTemplates::Map' ] )
3112
- let map_read = map_ldr.mmtemplates#core#EscapeMenu ( a: t_lib .properties[ ' Templates::RereadTemplates::Map' ] )
3113
- let map_style = map_ldr.mmtemplates#core#EscapeMenu ( a: t_lib .properties[ ' Templates::ChooseStyle::Map' ] )
3114
- let sc_edit = mmtemplates#core#EscapeMenu ( a: t_lib .properties[ ' Templates::EditTemplates::Shortcut' ] )
3115
- let sc_read = mmtemplates#core#EscapeMenu ( a: t_lib .properties[ ' Templates::RereadTemplates::Shortcut' ] )
3116
- let sc_style = mmtemplates#core#EscapeMenu ( a: t_lib .properties[ ' Templates::ChooseStyle::Shortcut' ] )
3143
+ let map_ldr = mmtemplates#core#EscapeMenu ( a: t_lib .properties[ ' Templates::Mapleader' ], ' right ' )
3144
+ let map_edit = map_ldr.mmtemplates#core#EscapeMenu ( a: t_lib .properties[ ' Templates::EditTemplates::Map' ], ' right ' )
3145
+ let map_read = map_ldr.mmtemplates#core#EscapeMenu ( a: t_lib .properties[ ' Templates::RereadTemplates::Map' ], ' right ' )
3146
+ let map_style = map_ldr.mmtemplates#core#EscapeMenu ( a: t_lib .properties[ ' Templates::ChooseStyle::Map' ], ' right ' )
3147
+ let sc_edit = mmtemplates#core#EscapeMenu ( a: t_lib .properties[ ' Templates::EditTemplates::Shortcut' ], ' right ' )
3148
+ let sc_read = mmtemplates#core#EscapeMenu ( a: t_lib .properties[ ' Templates::RereadTemplates::Shortcut' ], ' right ' )
3149
+ let sc_style = mmtemplates#core#EscapeMenu ( a: t_lib .properties[ ' Templates::ChooseStyle::Shortcut' ], ' right ' )
3117
3150
"
3118
3151
" create the specials menu
3119
3152
call s: CreateSubmenu ( a: t_lib , a: root_menu , a: global_name , specials_menu, s: StandardPriority )
@@ -3179,7 +3212,7 @@ function! mmtemplates#core#CreateMenus ( library, root_menu, ... )
3179
3212
let root_menu = global_name.' .'
3180
3213
let specials_menu = ' &Run'
3181
3214
let priority = s: StandardPriority
3182
- let existing = []
3215
+ let existing = []
3183
3216
"
3184
3217
" jobs
3185
3218
let do_reset = 0
@@ -3283,10 +3316,35 @@ endfunction " ---------- end of function mmtemplates#core#CreateMenus -----
3283
3316
" mmtemplates#core#EscapeMenu : Escape a string so it can be used as a menu item. {{{1
3284
3317
" ----------------------------------------------------------------------
3285
3318
"
3286
- function ! mmtemplates#core#EscapeMenu ( str )
3319
+ function ! mmtemplates#core#EscapeMenu ( str, ... )
3320
+ "
3321
+ let mode = ' entry'
3322
+ "
3323
+ if a: 0 > 0
3324
+ if type ( a: 1 ) != type ( ' ' )
3325
+ return s: ErrorMsg ( ' Argument "mode" must be given as a string.' )
3326
+ elseif a: 1 == ' menu'
3327
+ let mode = ' menu'
3328
+ elseif a: 1 == ' entry'
3329
+ let mode = ' entry'
3330
+ elseif a: 1 == ' right'
3331
+ let mode = ' right'
3332
+ else
3333
+ return s: ErrorMsg ( ' Unknown mode: ' .a: 1 )
3334
+ endif
3335
+ endif
3287
3336
"
3288
- let str = escape ( a: str , ' \.|' )
3289
- let str = substitute ( str, ' &' , ' \&\&' , ' g' )
3337
+ " whole menu: do not escape '.'
3338
+ if mode == ' menu'
3339
+ let str = escape ( a: str , ' \|' )
3340
+ else
3341
+ let str = escape ( a: str , ' \|.' )
3342
+ endif
3343
+ "
3344
+ " right-aligned text: do not escape '&'
3345
+ if mode != ' right'
3346
+ let str = substitute ( str, ' &' , ' \&\&' , ' g' )
3347
+ endif
3290
3348
"
3291
3349
return str
3292
3350
"
@@ -3379,7 +3437,7 @@ function! mmtemplates#core#Resource ( library, mode, ... )
3379
3437
if a: mode == ' add' || a: mode == ' get' || a: mode == ' set'
3380
3438
" continue below
3381
3439
elseif a: mode == ' escaped_mapleader'
3382
- return [ mmtemplates#core#EscapeMenu ( t_lib.properties[ ' Templates::Mapleader' ] ), ' ' ]
3440
+ return [ mmtemplates#core#EscapeMenu ( t_lib.properties[ ' Templates::Mapleader' ], ' right ' ), ' ' ]
3383
3441
elseif a: mode == ' jumptag'
3384
3442
return [ t_lib.regex_template.JumpTagBoth, ' ' ]
3385
3443
elseif a: mode == ' style'
0 commit comments