Skip to content

Commit

Permalink
Version 4.1
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
Fritz Mehner authored and vim-scripts committed Jan 29, 2014
1 parent 5525a7c commit 73e16bb
Show file tree
Hide file tree
Showing 19 changed files with 767 additions and 319 deletions.
8 changes: 8 additions & 0 deletions README
Expand Up @@ -28,6 +28,14 @@ The installation explained: http://www.thegeekstuff.com article

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

GitHub
--------------------------------------------------------
Bash Support is on GitHub:

https://github.com/WolfgangMehner/vim-plugins

(Please help us keep track of all the issues and name your report/request "Bash-Support: <title>")

MAILING LIST
--------------------------------------------------------
You can subscribe to the vim-plugins-list mailing list to post your questions or
Expand Down
136 changes: 97 additions & 39 deletions autoload/mmtemplates/core.vim
Expand Up @@ -41,7 +41,7 @@ endif
if &cp || ( exists('g:Templates_Version') && ! exists('g:Templates_DevelopmentOverwrite') )
finish
endif
let g:Templates_Version= '0.9.1.1' " version number of this script; do not change
let g:Templates_Version= '0.9.2' " version number of this script; do not change
"
if ! exists ( 'g:Templates_MapInUseWarn' )
let g:Templates_MapInUseWarn = 1
Expand Down Expand Up @@ -69,6 +69,8 @@ let s:Flagactions = {
"
let s:StandardPriority = 500
"
let g:CheckedFiletypes = {}
"
"----------------------------------------------------------------------
" s:StandardMacros : The standard macros. {{{2
"----------------------------------------------------------------------
Expand Down Expand Up @@ -213,7 +215,6 @@ function! s:UpdateTemplateRegex ( regex, settings )
let a:regex.MacroName = a:settings.MacroName
let a:regex.MacroNameC = '\('.a:settings.MacroName.'\)'
let a:regex.MacroMatch = '^'.a:settings.MacroStart.a:settings.MacroName.a:settings.MacroEnd.'$'
let a:regex.MacroSimple = a:settings.MacroStart.a:settings.MacroName.a:settings.MacroEnd
"
" Syntax Categories
let a:regex.FunctionLine = '^'.a:settings.MacroStart.'\('.a:regex.MacroNameC.'(\(.*\))\)'.a:settings.MacroEnd.'\s*\n'
Expand All @@ -223,6 +224,7 @@ function! s:UpdateTemplateRegex ( regex, settings )
let a:regex.FunctionInsert = a:settings.MacroStart.'\(Insert\|InsertLine\)'.'(\(.\{-}\))'.a:settings.MacroEnd
let a:regex.MacroRequest = a:settings.MacroStart.'?'.a:regex.MacroNameC.'\%(:\(\a\)\)\?'.a:settings.MacroEnd
let a:regex.MacroInsert = a:settings.MacroStart.''.a:regex.MacroNameC.'\%(:\(\a\)\)\?'.a:settings.MacroEnd
let a:regex.MacroNoCapture = a:settings.MacroStart.a:settings.MacroName.'\%(:\a\)\?'.a:settings.MacroEnd
let a:regex.ListItem = a:settings.MacroStart.''.a:regex.MacroNameC.':ENTRY_*'.a:settings.MacroEnd
"
let a:regex.TextBlockFunctions = '^\%(C\|Comment\|Insert\|InsertLine\)$'
Expand Down Expand Up @@ -361,7 +363,10 @@ endfunction " ---------- end of function s:UserInput ----------
"----------------------------------------------------------------------
"
function! mmtemplates#core#UserInputEx ( ArgLead, CmdLine, CursorPos )
return filter( copy( s:UserInputList ), 'v:val =~ "\\V\\<'.escape(a:ArgLead,'\').'\\w\\*"' )
if empty( a:ArgLead )
return copy( s:UserInputList )
endif
return filter( copy( s:UserInputList ), 'v:val =~ ''\V\<'.escape(a:ArgLead,'\').'\w\*''' )
endfunction " ---------- end of function mmtemplates#core#UserInputEx ----------
" }}}3
"
Expand Down Expand Up @@ -842,12 +847,12 @@ let s:FileReadNameSpace = {
\ 'SetFormat' : 'ss',
\ 'SetMacro' : 'ss',
\ 'SetPath' : 'ss',
\ 'SetProperty' : 'ss',
\ 'SetStyle' : 's',
\
\ 'MenuShortcut' : 'ss',
\ }
" \ 'SetMap' : 'ss',
" \ 'SetProperty' : 'ss',
" \ 'SetShortcut' : 'ss',
"
"----------------------------------------------------------------------
Expand Down Expand Up @@ -946,12 +951,16 @@ function! s:SetMap ( name, map )
endfunction " ---------- end of function s:SetMap ----------
"
"----------------------------------------------------------------------
" s:SetProperty : TODO (template function). {{{2
" s:SetProperty : Set an existing property. {{{2
"----------------------------------------------------------------------
"
function! s:SetProperty ( name, shortcut )
function! s:SetProperty ( name, value )
"
echo 'SetProperty: TO BE IMPLEMENTED'
let [ _, err ] = mmtemplates#core#Resource ( s:library, 'set', 'property', a:name , a:value )
"
if err != ''
return s:ErrorMsg ( 'Can not set the property "'.a:name.'".' )
endif
"
endfunction " ---------- end of function s:SetProperty ----------
"
Expand Down Expand Up @@ -1484,7 +1493,7 @@ function! s:ReplaceMacros ( text, m_local )
let m_text = get ( s:library.macros, mlist[2], '' )
end
"
if m_text =~ s:library.regex_template.MacroSimple
if m_text =~ s:library.regex_template.MacroNoCapture
"
call add ( s:t_runtime.macro_stack, mlist[2] )
"
Expand Down Expand Up @@ -2481,16 +2490,16 @@ function! s:InsertIntoBuffer ( text, placement, indentation, flag_mode )
" part0 and part1 can consist of several lines
"
if placement == 'insert'
" [_,line,col,off] = getpos()
let [_,l1,c1,o1] = getpos("'<")
let [_,l2,c2,o2] = getpos("'>")
call cursor ( l2, c2, o2 )
exe 'normal! a'.part[1]
call cursor ( l1, c1, o1 )
exe 'normal! i'.part[0]
" windows: register @* does not work
" solution: recover area of the visual mode and yank,
" puts the selected area into the buffer @"
let pos1 = line("'<")
let pos2 = line("'>") + len(split( text, '\n' )) - 1
normal gvy
let repl = escape ( part[0].@".part[1], '\&~' )
" substitute the selected area (using the '< and '> marks)
exe ':s/\%''<.*\%''>./'.repl.'/'
let indentation = 0
let pos1 = l1
let pos2 = l2 + len(split( text, '\n' )) - 1
elseif placement == 'below'
silent '<put! = part[0]
silent '>put = part[1]
Expand Down Expand Up @@ -2521,26 +2530,39 @@ endfunction " ---------- end of function s:InsertIntoBuffer ----------
"
function! s:PositionCursor ( placement, flag_mode, pos1, pos2 )
"
" TODO: syntax
" :TODO:12.08.2013 11:03:WM: changeable syntax?
" :TODO:12.08.2013 12:00:WM: change behavior?
"
exe ":".a:pos1
let mtch = search( '<CURSOR>\|{CURSOR}', 'c', a:pos2 )
if mtch != 0 " CURSOR found:
if mtch != 0
" tag found (and cursor moved, we are now at the position of the match)
let line = getline(mtch)
if line =~ '<CURSOR>$\|{CURSOR}$'
" the tag is at the end of the line
call setline( mtch, substitute( line, '<CURSOR>\|{CURSOR}', '', '' ) )
if a:flag_mode == 'v' && getline(".") =~ '^\s*$'
if a:flag_mode == 'v' && getline('.') =~ '^\s*$'
"if a:flag_mode == 'v' && getline('.') =~ '^\s*\%(<CURSOR>\|{CURSOR}\)\s*$'
" the line contains nothing but the tag: remove and join without
" changing the second line
normal J
"call setline( mtch, '' )
"normal gJ
else
" the line contains other characters: remove the tag and start appending
"call setline( mtch, substitute( line, '<CURSOR>\|{CURSOR}', '', '' ) )
startinsert!
endif
else
" the line contains other characters: remove the tag and start inserting
call setline( mtch, substitute( line, '<CURSOR>\|{CURSOR}', '', '' ) )
:startinsert
startinsert
endif
else " no CURSOR found
else
" no tag found (and cursor not moved)
if a:placement == 'below'
exe ":".a:pos2 | " to the end of the block; needed for repeated inserts
" to the end of the block, needed for repeated inserts
exe ":".a:pos2
endif
endif
"
Expand Down Expand Up @@ -2834,6 +2856,13 @@ function! mmtemplates#core#CreateMaps ( library, localleader, ... )
" generate new commands
" ==================================================
"
if has_key ( g:CheckedFiletypes, &filetype )
let echo_warning = 0
else
let g:CheckedFiletypes[ &filetype ] = 1
let echo_warning = g:Templates_MapInUseWarn != 0
endif
"
" go through all the templates
for t_name in t_lib.menu_order
"
Expand All @@ -2849,7 +2878,7 @@ function! mmtemplates#core#CreateMaps ( library, localleader, ... )
"
" map already existing?
if ! empty ( maparg( leader.mp, mode ) )
if g:Templates_MapInUseWarn != 0
if echo_warning
call s:ErrorMsg ( 'Mapping already in use: "'.leader.mp.'", mode "'.mode.'"' )
endif
continue
Expand Down Expand Up @@ -2877,7 +2906,9 @@ function! mmtemplates#core#CreateMaps ( library, localleader, ... )
if do_jump_map
let jump_key = '<C-j>' " TODO: configurable
if ! empty ( maparg( jump_key ) )
call s:ErrorMsg ( 'Mapping already in use: "'.jump_key.'"' )
if echo_warning
call s:ErrorMsg ( 'Mapping already in use: "'.jump_key.'"' )
endif
else
let jump_regex = string ( escape ( t_lib.regex_template.JumpTagBoth, '|' ) )
let cmd .= 'nnoremap '.options.' '.jump_key.' i<C-R>=mmtemplates#core#JumpToTag('.jump_regex.')<CR>'.sep
Expand All @@ -2897,7 +2928,9 @@ function! mmtemplates#core#CreateMaps ( library, localleader, ... )
"
for [ mp, action ] in items ( special_maps )
if ! empty ( maparg( leader.mp ) )
call s:ErrorMsg ( 'Mapping already in use: "'.leader.mp.'"' )
if echo_warning
call s:ErrorMsg ( 'Mapping already in use: "'.leader.mp.'"' )
endif
else
let cmd .= ' noremap '.options.' '.leader.mp.' '.action.sep
let cmd .= 'inoremap '.options.' '.leader.mp.' <Esc>'.action.sep
Expand Down Expand Up @@ -3018,7 +3051,7 @@ endfunction " ---------- end of function s:CreateSubmenu ----------
"
function! s:CreateTemplateMenus ( t_lib, root_menu, global_name, t_lib_name )
"
let map_ldr = mmtemplates#core#EscapeMenu ( a:t_lib.properties[ 'Templates::Mapleader' ] )
let map_ldr = mmtemplates#core#EscapeMenu ( a:t_lib.properties[ 'Templates::Mapleader' ], 'right' )
"
" go through all the templates
for t_name in a:t_lib.menu_order
Expand Down Expand Up @@ -3107,13 +3140,13 @@ function! s:CreateSpecialsMenus ( t_lib, root_menu, global_name, t_lib_name, spe
" remove trailing point
let specials_menu = substitute( a:specials_menu, '\.$', '', '' )
"
let map_ldr = mmtemplates#core#EscapeMenu ( a:t_lib.properties[ 'Templates::Mapleader' ] )
let map_edit = map_ldr.mmtemplates#core#EscapeMenu ( a:t_lib.properties[ 'Templates::EditTemplates::Map' ] )
let map_read = map_ldr.mmtemplates#core#EscapeMenu ( a:t_lib.properties[ 'Templates::RereadTemplates::Map' ] )
let map_style = map_ldr.mmtemplates#core#EscapeMenu ( a:t_lib.properties[ 'Templates::ChooseStyle::Map' ] )
let sc_edit = mmtemplates#core#EscapeMenu ( a:t_lib.properties[ 'Templates::EditTemplates::Shortcut' ] )
let sc_read = mmtemplates#core#EscapeMenu ( a:t_lib.properties[ 'Templates::RereadTemplates::Shortcut' ] )
let sc_style = mmtemplates#core#EscapeMenu ( a:t_lib.properties[ 'Templates::ChooseStyle::Shortcut' ] )
let map_ldr = mmtemplates#core#EscapeMenu ( a:t_lib.properties[ 'Templates::Mapleader' ], 'right' )
let map_edit = map_ldr.mmtemplates#core#EscapeMenu ( a:t_lib.properties[ 'Templates::EditTemplates::Map' ], 'right' )
let map_read = map_ldr.mmtemplates#core#EscapeMenu ( a:t_lib.properties[ 'Templates::RereadTemplates::Map' ], 'right' )
let map_style = map_ldr.mmtemplates#core#EscapeMenu ( a:t_lib.properties[ 'Templates::ChooseStyle::Map' ], 'right' )
let sc_edit = mmtemplates#core#EscapeMenu ( a:t_lib.properties[ 'Templates::EditTemplates::Shortcut' ], 'right' )
let sc_read = mmtemplates#core#EscapeMenu ( a:t_lib.properties[ 'Templates::RereadTemplates::Shortcut' ], 'right' )
let sc_style = mmtemplates#core#EscapeMenu ( a:t_lib.properties[ 'Templates::ChooseStyle::Shortcut' ], 'right' )
"
" create the specials menu
call s:CreateSubmenu ( a:t_lib, a:root_menu, a:global_name, specials_menu, s:StandardPriority )
Expand Down Expand Up @@ -3179,7 +3212,7 @@ function! mmtemplates#core#CreateMenus ( library, root_menu, ... )
let root_menu = global_name.'.'
let specials_menu = '&Run'
let priority = s:StandardPriority
let existing = []
let existing = []
"
" jobs
let do_reset = 0
Expand Down Expand Up @@ -3283,10 +3316,35 @@ endfunction " ---------- end of function mmtemplates#core#CreateMenus -----
" mmtemplates#core#EscapeMenu : Escape a string so it can be used as a menu item. {{{1
"----------------------------------------------------------------------
"
function! mmtemplates#core#EscapeMenu ( str )
function! mmtemplates#core#EscapeMenu ( str, ... )
"
let mode = 'entry'
"
if a:0 > 0
if type( a:1 ) != type( '' )
return s:ErrorMsg ( 'Argument "mode" must be given as a string.' )
elseif a:1 == 'menu'
let mode = 'menu'
elseif a:1 == 'entry'
let mode = 'entry'
elseif a:1 == 'right'
let mode = 'right'
else
return s:ErrorMsg ( 'Unknown mode: '.a:1 )
endif
endif
"
let str = escape ( a:str, ' \.|' )
let str = substitute ( str, '&', '\&\&', 'g' )
" whole menu: do not escape '.'
if mode == 'menu'
let str = escape ( a:str, ' \|' )
else
let str = escape ( a:str, ' \|.' )
endif
"
" right-aligned text: do not escape '&'
if mode != 'right'
let str = substitute ( str, '&', '\&\&', 'g' )
endif
"
return str
"
Expand Down Expand Up @@ -3379,7 +3437,7 @@ function! mmtemplates#core#Resource ( library, mode, ... )
if a:mode == 'add' || a:mode == 'get' || a:mode == 'set'
" continue below
elseif a:mode == 'escaped_mapleader'
return [ mmtemplates#core#EscapeMenu( t_lib.properties[ 'Templates::Mapleader' ] ), '' ]
return [ mmtemplates#core#EscapeMenu( t_lib.properties[ 'Templates::Mapleader' ], 'right' ), '' ]
elseif a:mode == 'jumptag'
return [ t_lib.regex_template.JumpTagBoth, '' ]
elseif a:mode == 'style'
Expand Down
25 changes: 9 additions & 16 deletions bash-support/README.bashsupport
@@ -1,4 +1,4 @@
README for bash-support.vim (Version 4.0) / July 07 2013
README for bash-support.vim (Version 4.1) / December 09 2013

* INSTALLATION
* RELEASE NOTES
Expand Down Expand Up @@ -123,24 +123,16 @@ Look at the bashsupport help with
+-----------------------------------------------+

=======================================================================================
RELEASE NOTES FOR VERSION 4.0
RELEASE NOTES FOR VERSION 4.1
=======================================================================================

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++ The plug-in version 4.0+ is a rewriting of version 3.12.1. ++
++ The versions 4.0+ are based on a new and more powerful template system ++
++ (please see ":help template-support" for more information). ++
++ The template syntax has changed! ++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- 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.

- New template system (many thanks to Wolfgang Mehner)
- A few new hotkeys and menu item.
- A few hotkeys and menu items renamed.


=======================================================================================
OLDER RELEASE NOTES : see file 'ChangeLog'
=======================================================================================

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

README.bashsupport This file.

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

Expand Down
5 changes: 2 additions & 3 deletions bash-support/codesnippets/create-tempfile-in-secure-manner
Expand Up @@ -3,16 +3,15 @@ TMPDIR=${TMPDIR:-/tmp} # defaults to /tmp if unset

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

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

touch $TEMPORARY_DIR/tempfile # new tempfile inside folder

17 changes: 13 additions & 4 deletions bash-support/codesnippets/debugging/_debug_PS4
@@ -1,13 +1,22 @@
# PS4 : timestamp; the current time in 24-hour HH:MM:SS format
PS4='+[\t] '

# PS4 : timestamp; 'seconds.nanoseconds' since 1970-01-01 00:00:00 UT
PS4='+ [$(date "+%s.%N")] '
PS4='+[$(date "+%s.%N")] '

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

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

# PS4 : default prompt
PS4='+'
PS4='+ '

0 comments on commit 73e16bb

Please sign in to comment.