Skip to content

Commit 73e16bb

Browse files
Fritz Mehnervim-scripts
Fritz Mehner
authored andcommitted
Version 4.1
- Filetype plugin added. - Bugfix: Setup of local templates in case of global installation. - Adjusting end-of-line comments improved. - Submenu 'Regexp' renamed to 'PatternMatching'. Appropriate hotkeys renamed. - Minor bugfixes. - Documentation updated.
1 parent 5525a7c commit 73e16bb

19 files changed

+767
-319
lines changed

README

+8
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ The installation explained: http://www.thegeekstuff.com article
2828

2929
Plugin featured in the linux.com article 'Turn Vim into a bash IDE' : http://www.linux.com/articles/114359
3030

31+
GitHub
32+
--------------------------------------------------------
33+
Bash Support is on GitHub:
34+
35+
https://github.com/WolfgangMehner/vim-plugins
36+
37+
(Please help us keep track of all the issues and name your report/request "Bash-Support: <title>")
38+
3139
MAILING LIST
3240
--------------------------------------------------------
3341
You can subscribe to the vim-plugins-list mailing list to post your questions or

autoload/mmtemplates/core.vim

+97-39
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ endif
4141
if &cp || ( exists('g:Templates_Version') && ! exists('g:Templates_DevelopmentOverwrite') )
4242
finish
4343
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
4545
"
4646
if ! exists ( 'g:Templates_MapInUseWarn' )
4747
let g:Templates_MapInUseWarn = 1
@@ -69,6 +69,8 @@ let s:Flagactions = {
6969
"
7070
let s:StandardPriority = 500
7171
"
72+
let g:CheckedFiletypes = {}
73+
"
7274
"----------------------------------------------------------------------
7375
" s:StandardMacros : The standard macros. {{{2
7476
"----------------------------------------------------------------------
@@ -213,7 +215,6 @@ function! s:UpdateTemplateRegex ( regex, settings )
213215
let a:regex.MacroName = a:settings.MacroName
214216
let a:regex.MacroNameC = '\('.a:settings.MacroName.'\)'
215217
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
217218
"
218219
" Syntax Categories
219220
let a:regex.FunctionLine = '^'.a:settings.MacroStart.'\('.a:regex.MacroNameC.'(\(.*\))\)'.a:settings.MacroEnd.'\s*\n'
@@ -223,6 +224,7 @@ function! s:UpdateTemplateRegex ( regex, settings )
223224
let a:regex.FunctionInsert = a:settings.MacroStart.'\(Insert\|InsertLine\)'.'(\(.\{-}\))'.a:settings.MacroEnd
224225
let a:regex.MacroRequest = a:settings.MacroStart.'?'.a:regex.MacroNameC.'\%(:\(\a\)\)\?'.a:settings.MacroEnd
225226
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
226228
let a:regex.ListItem = a:settings.MacroStart.''.a:regex.MacroNameC.':ENTRY_*'.a:settings.MacroEnd
227229
"
228230
let a:regex.TextBlockFunctions = '^\%(C\|Comment\|Insert\|InsertLine\)$'
@@ -361,7 +363,10 @@ endfunction " ---------- end of function s:UserInput ----------
361363
"----------------------------------------------------------------------
362364
"
363365
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\*''' )
365370
endfunction " ---------- end of function mmtemplates#core#UserInputEx ----------
366371
" }}}3
367372
"
@@ -842,12 +847,12 @@ let s:FileReadNameSpace = {
842847
\ 'SetFormat' : 'ss',
843848
\ 'SetMacro' : 'ss',
844849
\ 'SetPath' : 'ss',
850+
\ 'SetProperty' : 'ss',
845851
\ 'SetStyle' : 's',
846852
\
847853
\ 'MenuShortcut' : 'ss',
848854
\ }
849855
" \ 'SetMap' : 'ss',
850-
" \ 'SetProperty' : 'ss',
851856
" \ 'SetShortcut' : 'ss',
852857
"
853858
"----------------------------------------------------------------------
@@ -946,12 +951,16 @@ function! s:SetMap ( name, map )
946951
endfunction " ---------- end of function s:SetMap ----------
947952
"
948953
"----------------------------------------------------------------------
949-
" s:SetProperty : TODO (template function). {{{2
954+
" s:SetProperty : Set an existing property. {{{2
950955
"----------------------------------------------------------------------
951956
"
952-
function! s:SetProperty ( name, shortcut )
957+
function! s:SetProperty ( name, value )
953958
"
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
955964
"
956965
endfunction " ---------- end of function s:SetProperty ----------
957966
"
@@ -1484,7 +1493,7 @@ function! s:ReplaceMacros ( text, m_local )
14841493
let m_text = get ( s:library.macros, mlist[2], '' )
14851494
end
14861495
"
1487-
if m_text =~ s:library.regex_template.MacroSimple
1496+
if m_text =~ s:library.regex_template.MacroNoCapture
14881497
"
14891498
call add ( s:t_runtime.macro_stack, mlist[2] )
14901499
"
@@ -2481,16 +2490,16 @@ function! s:InsertIntoBuffer ( text, placement, indentation, flag_mode )
24812490
" part0 and part1 can consist of several lines
24822491
"
24832492
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.'/'
24912502
let indentation = 0
2492-
let pos1 = l1
2493-
let pos2 = l2 + len(split( text, '\n' )) - 1
24942503
elseif placement == 'below'
24952504
silent '<put! = part[0]
24962505
silent '>put = part[1]
@@ -2521,26 +2530,39 @@ endfunction " ---------- end of function s:InsertIntoBuffer ----------
25212530
"
25222531
function! s:PositionCursor ( placement, flag_mode, pos1, pos2 )
25232532
"
2524-
" TODO: syntax
2533+
" :TODO:12.08.2013 11:03:WM: changeable syntax?
2534+
" :TODO:12.08.2013 12:00:WM: change behavior?
25252535
"
25262536
exe ":".a:pos1
25272537
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)
25292540
let line = getline(mtch)
25302541
if line =~ '<CURSOR>$\|{CURSOR}$'
2542+
" the tag is at the end of the line
25312543
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
25332548
normal J
2549+
"call setline( mtch, '' )
2550+
"normal gJ
25342551
else
2552+
" the line contains other characters: remove the tag and start appending
2553+
"call setline( mtch, substitute( line, '<CURSOR>\|{CURSOR}', '', '' ) )
25352554
startinsert!
25362555
endif
25372556
else
2557+
" the line contains other characters: remove the tag and start inserting
25382558
call setline( mtch, substitute( line, '<CURSOR>\|{CURSOR}', '', '' ) )
2539-
:startinsert
2559+
startinsert
25402560
endif
2541-
else " no CURSOR found
2561+
else
2562+
" no tag found (and cursor not moved)
25422563
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
25442566
endif
25452567
endif
25462568
"
@@ -2834,6 +2856,13 @@ function! mmtemplates#core#CreateMaps ( library, localleader, ... )
28342856
" generate new commands
28352857
" ==================================================
28362858
"
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+
"
28372866
" go through all the templates
28382867
for t_name in t_lib.menu_order
28392868
"
@@ -2849,7 +2878,7 @@ function! mmtemplates#core#CreateMaps ( library, localleader, ... )
28492878
"
28502879
" map already existing?
28512880
if ! empty ( maparg( leader.mp, mode ) )
2852-
if g:Templates_MapInUseWarn != 0
2881+
if echo_warning
28532882
call s:ErrorMsg ( 'Mapping already in use: "'.leader.mp.'", mode "'.mode.'"' )
28542883
endif
28552884
continue
@@ -2877,7 +2906,9 @@ function! mmtemplates#core#CreateMaps ( library, localleader, ... )
28772906
if do_jump_map
28782907
let jump_key = '<C-j>' " TODO: configurable
28792908
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
28812912
else
28822913
let jump_regex = string ( escape ( t_lib.regex_template.JumpTagBoth, '|' ) )
28832914
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, ... )
28972928
"
28982929
for [ mp, action ] in items ( special_maps )
28992930
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
29012934
else
29022935
let cmd .= ' noremap '.options.' '.leader.mp.' '.action.sep
29032936
let cmd .= 'inoremap '.options.' '.leader.mp.' <Esc>'.action.sep
@@ -3018,7 +3051,7 @@ endfunction " ---------- end of function s:CreateSubmenu ----------
30183051
"
30193052
function! s:CreateTemplateMenus ( t_lib, root_menu, global_name, t_lib_name )
30203053
"
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' )
30223055
"
30233056
" go through all the templates
30243057
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
31073140
" remove trailing point
31083141
let specials_menu = substitute( a:specials_menu, '\.$', '', '' )
31093142
"
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' )
31173150
"
31183151
" create the specials menu
31193152
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, ... )
31793212
let root_menu = global_name.'.'
31803213
let specials_menu = '&Run'
31813214
let priority = s:StandardPriority
3182-
let existing = []
3215+
let existing = []
31833216
"
31843217
" jobs
31853218
let do_reset = 0
@@ -3283,10 +3316,35 @@ endfunction " ---------- end of function mmtemplates#core#CreateMenus -----
32833316
" mmtemplates#core#EscapeMenu : Escape a string so it can be used as a menu item. {{{1
32843317
"----------------------------------------------------------------------
32853318
"
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
32873336
"
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
32903348
"
32913349
return str
32923350
"
@@ -3379,7 +3437,7 @@ function! mmtemplates#core#Resource ( library, mode, ... )
33793437
if a:mode == 'add' || a:mode == 'get' || a:mode == 'set'
33803438
" continue below
33813439
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' ), '' ]
33833441
elseif a:mode == 'jumptag'
33843442
return [ t_lib.regex_template.JumpTagBoth, '' ]
33853443
elseif a:mode == 'style'

bash-support/README.bashsupport

+9-16
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
README for bash-support.vim (Version 4.0) / July 07 2013
1+
README for bash-support.vim (Version 4.1) / December 09 2013
22

33
* INSTALLATION
44
* RELEASE NOTES
@@ -123,24 +123,16 @@ Look at the bashsupport help with
123123
+-----------------------------------------------+
124124

125125
=======================================================================================
126-
RELEASE NOTES FOR VERSION 4.0
126+
RELEASE NOTES FOR VERSION 4.1
127127
=======================================================================================
128128

129-
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
130-
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
131-
++ The plug-in version 4.0+ is a rewriting of version 3.12.1. ++
132-
++ The versions 4.0+ are based on a new and more powerful template system ++
133-
++ (please see ":help template-support" for more information). ++
134-
++ The template syntax has changed! ++
135-
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
136-
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
129+
- Filetype plugin added.
130+
- Bugfix: Setup of local templates in case of global installation.
131+
- Adjusting end-of-line comments improved.
132+
- Submenu 'Regexp' renamed to 'PatternMatching'. Appropriate hotkeys renamed.
133+
- Minor bugfixes.
134+
- Documentation updated.
137135

138-
- New template system (many thanks to Wolfgang Mehner)
139-
- A few new hotkeys and menu item.
140-
- A few hotkeys and menu items renamed.
141-
142-
143-
=======================================================================================
144136
OLDER RELEASE NOTES : see file 'ChangeLog'
145137
=======================================================================================
146138

@@ -150,6 +142,7 @@ Look at the bashsupport help with
150142

151143
README.bashsupport This file.
152144

145+
ftplugin/sh.vim The bash filetype plugin.
153146
plugin/bash-support.vim The bash plugin for Vim/gVim.
154147
bash-support/scripts/wrapper.sh A wrapper script for the use of an xterm.
155148

bash-support/codesnippets/create-tempfile-in-secure-manner

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@ TMPDIR=${TMPDIR:-/tmp} # defaults to /tmp if unset
33

44
#-------------------------------------------------------------------------------
55
# Creates a particular temporary directory inside $TMPDIR.
6-
# mkdir(1) is an atomic check-and-create operation.
76
#-------------------------------------------------------------------------------
8-
TEMPORARY_DIR=$(mktemp -d "$TMPDIR/XXXXXXXXXXXXXXXXXXXXXXXXXXXXX") || \
7+
TEMPORARY_DIR=$(mktemp -d "$TMPDIR/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX") || \
98
{ echo "ERROR creating a temporary file"; exit 1; }
109

1110
#-------------------------------------------------------------------------------
1211
# When the program exits, it tries to remove the temporary folder.
1312
# This code is executed even if the process receives a signal 1,2,3 or 15.
1413
#-------------------------------------------------------------------------------
15-
trap 'rm --recursive --force "$TEMPORARY_DIR"' 0
14+
trap '[ "$TEMPORARY_DIR" ] && rm --recursive --force "$TEMPORARY_DIR"' 0
1615

1716
touch $TEMPORARY_DIR/tempfile # new tempfile inside folder
1817

Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
1+
# PS4 : timestamp; the current time in 24-hour HH:MM:SS format
2+
PS4='+[\t] '
3+
14
# PS4 : timestamp; 'seconds.nanoseconds' since 1970-01-01 00:00:00 UT
2-
PS4='+ [$(date "+%s.%N")] '
5+
PS4='+[$(date "+%s.%N")] '
36

47
# PS4 : position, line number, function name
8+
# The following line avoids error messages due to an unset FUNCNAME[0] :
9+
# set +o nounset # Treat unset variables as an error
10+
#
511
PS4='+|${BASH_SOURCE##*/} ${LINENO}${FUNCNAME[0]:+ ${FUNCNAME[0]}}| '
612

713
# PS4 : position, line number, function name, subshell information
8-
PS4='+(${BASH_SOURCE##*/}: ${LINENO}) : ${FUNCNAME[0]} - [level ${SHLVL}, subshell ${BASH_SUBSHELL}, return code $?]
9-
'
14+
# The following line avoids error messages due to an unset FUNCNAME[0] :
15+
# set +o nounset # Treat unset variables as an error
16+
#
17+
PS4='+(${BASH_SOURCE##*/}: ${LINENO}) : ${FUNCNAME[0]} - [level ${SHLVL}, '
18+
PS4=$PS4'subshell ${BASH_SUBSHELL}, return code $?]\n '
1019

1120
# PS4 : default prompt
12-
PS4='+'
21+
PS4='+ '
1322

0 commit comments

Comments
 (0)