"################################################################################# " " Filename: perl-support.vim " " Description: perl-support.vim implements a Perl-IDE for Vim/gVim. It is " written to considerably speed up writing code in a consistent " style. " This is done by inserting complete statements, comments, " idioms, code snippets, templates, comments and POD " documentation. Reading perldoc is integrated. Syntax " checking, running a script, starting a debugger and a " profiler can be done by a keystroke. " There a many additional hints and options which can improve " speed and comfort when writing Perl. Please read the " documentation. " " Configuration: There are at least some personal details which should be " configured (see the files README.perlsupport and " perlsupport.txt). " " Dependencies: perl pod2man " podchecker pod2text " pod2html perldoc " " optional: " " Devel::FastProf (profiler) " Devel::NYTProf (profiler) " Devel::SmallProf (profiler) " Devel::ptkdb (debugger frontend) " Perl::Critic (stylechecker) " Perl::Tags::Naive (generate Ctags style tags) " Perl::Tidy (beautifier) " YAPE::Regex::Explain (regular expression analyzer) " ddd (debugger frontend) " sort(1) (rearrange profiler statistics) " " Author: Dr.-Ing. Fritz Mehner " " Version: see variable g:Perl_PluginVersion below " Created: 09.07.2001 " License: Copyright (c) 2001-2014, Fritz Mehner " This program is free software; you can redistribute it " and/or modify it under the terms of the GNU General Public " License as published by the Free Software Foundation, " version 2 of the License. " This program is distributed in the hope that it will be " useful, but WITHOUT ANY WARRANTY; without even the implied " warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR " PURPOSE. " See the GNU General Public License version 2 for more details. " Credits: see perlsupport.txt "------------------------------------------------------------------------------- " " Prevent duplicate loading: " if exists("g:Perl_PluginVersion") || &compatible finish endif let g:Perl_PluginVersion= "5.3.2" " "=== FUNCTION ================================================================ " NAME: Perl_SetGlobalVariable {{{1 " DESCRIPTION: Define a global variable and assign a default value if nor " already defined " PARAMETERS: name - global variable " default - default value "=============================================================================== function! s:perl_SetGlobalVariable ( name, default ) if !exists('g:'.a:name) exe 'let g:'.a:name." = '".a:default."'" else " check for an empty initialization exe 'let val = g:'.a:name if empty(val) exe 'let g:'.a:name." = '".a:default."'" endif endif endfunction " ---------- end of function s:perl_SetGlobalVariable ---------- " "=== FUNCTION ================================================================ " NAME: Perl_SetLocalVariable {{{1 " DESCRIPTION: Assign a value to a local variable if a corresponding global " variable exists " PARAMETERS: name - name of a global variable "=============================================================================== function! s:perl_SetLocalVariable ( name ) if exists('g:'.a:name) exe 'let s:'.a:name.' = g:'.a:name endif endfunction " ---------- end of function s:perl_SetLocalVariable ---------- " call s:perl_SetGlobalVariable( "Perl_MenuHeader",'yes' ) call s:perl_SetGlobalVariable( "Perl_OutputGvim",'vim' ) call s:perl_SetGlobalVariable( "Perl_PerlRegexSubstitution",'$~' ) " "------------------------------------------------------------------------------ " " Platform specific items: " - plugin directory " - characters that must be escaped for filenames " let s:MSWIN = has("win16") || has("win32") || has("win64") || has("win95") let s:UNIX = has("unix") || has("macunix") || has("win32unix") " let s:Perl_Perl = '' " the Perl interpreter used let s:Perl_Perl_is_executable = 0 " the Perl interpreter used let g:Perl_Installation = '*undefined*' let g:Perl_PluginDir = '' " let s:Perl_GlobalTemplateFile = '' let s:Perl_LocalTemplateFile = '' let g:Perl_FilenameEscChar = '' " let s:Perl_ToolboxDir = [] " if s:MSWIN " ========== MS Windows ====================================================== " let g:Perl_PluginDir = substitute( expand(':p:h:h'), '\', '/', 'g' ) " " change '\' to '/' to avoid interpretation as escape character if match( substitute( expand(""), '\', '/', 'g' ), \ substitute( expand("$HOME"), '\', '/', 'g' ) ) == 0 " USER INSTALLATION ASSUMED let g:Perl_Installation = 'local' let s:Perl_LocalTemplateFile = g:Perl_PluginDir.'/perl-support/templates/Templates' let s:Perl_ToolboxDir += [ g:Perl_PluginDir.'/autoload/mmtoolbox/' ] else " SYSTEM WIDE INSTALLATION let g:Perl_Installation = 'system' let s:Perl_GlobalTemplateFile = g:Perl_PluginDir.'/perl-support/templates/Templates' let s:Perl_LocalTemplateFile = $HOME.'/vimfiles/perl-support/templates/Templates' let s:Perl_ToolboxDir += [ \ g:Perl_PluginDir.'/autoload/mmtoolbox/', \ $HOME.'/vimfiles/autoload/mmtoolbox/' ] end " let s:Perl_Perl = 'C:/Perl/bin/perl.exe' let g:Perl_FilenameEscChar = '' " else " ========== Linux/Unix ====================================================== " let g:Perl_PluginDir = expand(":p:h:h") " if match( expand(""), resolve( expand("$HOME") ) ) == 0 " USER INSTALLATION ASSUMED let g:Perl_Installation = 'local' let s:Perl_LocalTemplateFile = g:Perl_PluginDir.'/perl-support/templates/Templates' let s:Perl_ToolboxDir += [ g:Perl_PluginDir.'/autoload/mmtoolbox/' ] else " SYSTEM WIDE INSTALLATION let g:Perl_Installation = 'system' let s:Perl_GlobalTemplateFile = g:Perl_PluginDir.'/perl-support/templates/Templates' let s:Perl_LocalTemplateFile = $HOME.'/.vim/perl-support/templates/Templates' let s:Perl_ToolboxDir += [ \ g:Perl_PluginDir.'/autoload/mmtoolbox/', \ $HOME.'/.vim/autoload/mmtoolbox/' ] endif " let s:Perl_Perl = '/usr/bin/perl' let g:Perl_FilenameEscChar = ' \%#[]' " " ============================================================================== endif " " g:Perl_CodeSnippets is used in autoload/perlsupportgui.vim " let s:Perl_CodeSnippets = g:Perl_PluginDir.'/perl-support/codesnippets/' call s:perl_SetGlobalVariable( 'Perl_CodeSnippets', s:Perl_CodeSnippets ) " " call s:perl_SetGlobalVariable( 'Perl_PerlTags', 'off' ) " if !exists("g:Perl_Dictionary_File") let g:Perl_Dictionary_File = g:Perl_PluginDir.'/perl-support/wordlists/perl.list' endif " " " Modul global variables (with default values) which can be overridden. {{{1 " let s:Perl_LoadMenus = 'yes' " display the menus ? let s:Perl_TemplateOverriddenMsg = 'no' let s:Perl_Ctrl_j = 'on' " let s:Perl_TimestampFormat = '%Y%m%d.%H%M%S' let s:Perl_PerlModuleList = g:Perl_PluginDir.'/perl-support/modules/perl-modules.list' let s:Perl_XtermDefaults = "-fa courier -fs 12 -geometry 80x24" let s:Perl_Debugger = "perl" let s:Perl_ProfilerTimestamp = "no" let s:Perl_LineEndCommColDefault = 49 let s:PerlStartComment = '#' let s:Perl_PodcheckerWarnings = "yes" let s:Perl_PerlcriticOptions = "" let s:Perl_PerlcriticSeverity = 3 let s:Perl_PerlcriticVerbosity = 5 let s:Perl_Printheader = "%<%f%h%m%< %=%{strftime('%x %X')} Page %N" let s:Perl_GuiSnippetBrowser = 'gui' " gui / commandline let s:Perl_GuiTemplateBrowser = 'gui' " gui / explorer / commandline let s:Perl_CreateMenusDelayed = 'yes' let s:Perl_DirectRun = 'no' " let s:Perl_InsertFileHeader = 'yes' let s:Perl_Wrapper = g:Perl_PluginDir.'/perl-support/scripts/wrapper.sh' let s:Perl_PerlModuleListGenerator = g:Perl_PluginDir.'/perl-support/scripts/pmdesc3.pl' let s:Perl_PerltidyBackup = "no" " call s:perl_SetGlobalVariable ( 'Perl_MapLeader', '' ) let s:Perl_RootMenu = '&Perl' " let s:Perl_UseToolbox = 'yes' call s:perl_SetGlobalVariable ( 'Perl_UseTool_make', 'yes' ) " "------------------------------------------------------------------------------ " " Look for global variables (if any), to override the defaults. " call s:perl_SetLocalVariable('Perl_Perl ') call s:perl_SetLocalVariable('Perl_DirectRun ') call s:perl_SetLocalVariable('Perl_InsertFileHeader ') call s:perl_SetLocalVariable('Perl_CreateMenusDelayed ') call s:perl_SetLocalVariable('Perl_Ctrl_j ') call s:perl_SetLocalVariable('Perl_Debugger ') call s:perl_SetLocalVariable('Perl_GlobalTemplateFile ') call s:perl_SetLocalVariable('Perl_LocalTemplateFile ') call s:perl_SetLocalVariable('Perl_GuiSnippetBrowser ') call s:perl_SetLocalVariable('Perl_GuiTemplateBrowser ') call s:perl_SetLocalVariable('Perl_LineEndCommColDefault ') call s:perl_SetLocalVariable('Perl_LoadMenus ') call s:perl_SetLocalVariable('Perl_NYTProf_browser ') call s:perl_SetLocalVariable('Perl_NYTProf_html ') call s:perl_SetLocalVariable('Perl_PerlcriticOptions ') call s:perl_SetLocalVariable('Perl_PerlcriticSeverity ') call s:perl_SetLocalVariable('Perl_PerlcriticVerbosity ') call s:perl_SetLocalVariable('Perl_PerlModuleList ') call s:perl_SetLocalVariable('Perl_PerlModuleListGenerator') call s:perl_SetLocalVariable('Perl_PerltidyBackup ') call s:perl_SetLocalVariable('Perl_PodcheckerWarnings ') call s:perl_SetLocalVariable('Perl_Printheader ') call s:perl_SetLocalVariable('Perl_ProfilerTimestamp ') call s:perl_SetLocalVariable('Perl_TemplateOverriddenMsg ') call s:perl_SetLocalVariable('Perl_TimestampFormat ') call s:perl_SetLocalVariable('Perl_UseToolbox ') call s:perl_SetLocalVariable('Perl_XtermDefaults ') " let s:Perl_Perl_is_executable = executable(s:Perl_Perl) " " set default geometry if not specified " if match( s:Perl_XtermDefaults, "-geometry\\s\\+\\d\\+x\\d\\+" ) < 0 let s:Perl_XtermDefaults = s:Perl_XtermDefaults." -geometry 80x24" endif " " Flags for perldoc " if has("gui_running") let s:Perl_perldoc_flags = "" else " Display docs using plain text converter. let s:Perl_perldoc_flags = "-otext" endif " " escape the printheader " let s:Perl_Printheader = escape( s:Perl_Printheader, ' %' ) let s:Perl_PerlExecutableVersion = '' " "------------------------------------------------------------------------------ " Control variables (not user configurable) "------------------------------------------------------------------------------ " let s:Perl_MenuVisible = 'no' let s:Perl_TemplateJumpTarget = '' let s:MsgInsNotAvail = "insertion not available for a fold" let g:Perl_PerlRegexAnalyser = 'no' let g:Perl_InterfaceInitialized = 'no' let s:Perl_saved_global_option = {} " let s:PCseverityName = [ "DUMMY", "brutal", "cruel", "harsh", "stern", "gentle" ] let s:PCverbosityName = [ '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11' ] " "=== FUNCTION ================================================================ " NAME: Perl_Input {{{1 " DESCRIPTION: Input after a highlighted prompt " PARAMETERS: prompt - prompt " text - default reply " ... - completion (optional) " RETURNS: "=============================================================================== function! Perl_Input ( prompt, text, ... ) echohl Search " highlight prompt call inputsave() " preserve typeahead if a:0 == 0 || empty(a:1) let retval =input( a:prompt, a:text ) else let retval =input( a:prompt, a:text, a:1 ) endif call inputrestore() " restore typeahead echohl None " reset highlighting let retval = substitute( retval, '^\s\+', "", "" ) " remove leading whitespaces let retval = substitute( retval, '\s\+$', "", "" ) " remove trailing whitespaces return retval endfunction " ---------- end of function Perl_Input ---------- " "------------------------------------------------------------------------------ " Perl_SaveGlobalOption {{{1 " param 1 : option name " param 2 : characters to be escaped (optional) "------------------------------------------------------------------------------ function! s:Perl_SaveGlobalOption ( option, ... ) exe 'let escaped =&'.a:option if a:0 == 0 let escaped = escape( escaped, ' |"\' ) else let escaped = escape( escaped, ' |"\'.a:1 ) endif let s:Perl_saved_global_option[a:option] = escaped endfunction " ---------- end of function Perl_SaveGlobalOption ---------- " "------------------------------------------------------------------------------ " Perl_RestoreGlobalOption {{{1 "------------------------------------------------------------------------------ function! s:Perl_RestoreGlobalOption ( option ) exe ':set '.a:option.'='.s:Perl_saved_global_option[a:option] endfunction " ---------- end of function Perl_RestoreGlobalOption ---------- " "=== FUNCTION ================================================================ " NAME: Perl_GetLineEndCommCol {{{1 " DESCRIPTION: get end-of-line comment position "=============================================================================== function! Perl_GetLineEndCommCol () let actcol = virtcol(".") if actcol+1 == virtcol("$") let b:Perl_LineEndCommentColumn = '' while match( b:Perl_LineEndCommentColumn, '^\s*\d\+\s*$' ) < 0 let b:Perl_LineEndCommentColumn = Perl_Input( 'start line-end comment at virtual column : ', actcol, '' ) endwhile else let b:Perl_LineEndCommentColumn = virtcol(".") endif echomsg "line end comments will start at column ".b:Perl_LineEndCommentColumn endfunction " ---------- end of function Perl_GetLineEndCommCol ---------- " "=== FUNCTION ================================================================ " NAME: Perl_EndOfLineComment {{{1 " DESCRIPTION: apply single end-of-line comment "=============================================================================== function! Perl_EndOfLineComment ( ) range if !exists("b:Perl_LineEndCommentColumn") let b:Perl_LineEndCommentColumn = s:Perl_LineEndCommColDefault endif " ----- trim whitespaces ----- exe a:firstline.','.a:lastline.'s/\s*$//' for line in range( a:lastline, a:firstline, -1 ) silent exe ":".line if getline(line) !~ '^\s*$' let linelength = virtcol( [line, "$"] ) - 1 let diff = 1 if linelength < b:Perl_LineEndCommentColumn let diff = b:Perl_LineEndCommentColumn -1 -linelength endif exe "normal! ".diff."A " call mmtemplates#core#InsertTemplate(g:Perl_Templates, 'Comments.end-of-line-comment') endif endfor endfunction " ---------- end of function Perl_EndOfLineComment ---------- " "------------------------------------------------------------------------------ " Perl_AlignLineEndComm: adjust line-end comments "------------------------------------------------------------------------------ " " patterns to ignore when adjusting line-end comments (incomplete): " some heuristics used (only Perl can parse Perl) let s:AlignRegex = [ \ '\$#' , \ "'\\%(\\\\'\\|[^']\\)*'" , \ '"\%(\\.\|[^"]\)*"' , \ '`[^`]\+`' , \ '\%(m\|qr\)#[^#]\+#' , \ '\%(m\|qr\)\?\([\?\/]\).*\1[imsxg]*' , \ '\%(m\|qr\)\([[:punct:]]\).*\2[imsxg]*' , \ '\%(m\|qr\){.*}[imsxg]*' , \ '\%(m\|qr\)(.*)[imsxg]*' , \ '\%(m\|qr\)\[.*\][imsxg]*' , \ '\%(s\|tr\)#[^#]\+#[^#]\+#' , \ '\%(s\|tr\){[^}]\+}{[^}]\+}' , \ ] "=== FUNCTION ================================================================ " NAME: Perl_AlignLineEndComm {{{1 " DESCRIPTION: align end-of-line comments "=============================================================================== function! Perl_AlignLineEndComm ( ) range " " comment character (for use in regular expression) let cc = '#' " start of a Perl comment " " patterns to ignore when adjusting line-end comments (maybe incomplete): let align_regex = join( s:AlignRegex, '\|' ) " " local position if !exists( 'b:Perl_LineEndCommentColumn' ) let b:Perl_LineEndCommentColumn = s:Perl_LineEndCommColDefault endif let correct_idx = b:Perl_LineEndCommentColumn " " === plug-in specific code ends here === " === the behavior is governed by the variables above === " " save the cursor position let save_cursor = getpos('.') " for line in range( a:firstline, a:lastline ) silent exe ':'.line " let linetxt = getline('.') " " "pure" comment line left unchanged if match ( linetxt, '^\s*'.cc ) == 0 "echo 'line '.line.': "pure" comment' continue endif " let b_idx1 = 1 + match ( linetxt, '\s*'.cc.'.*$', 0 ) let b_idx2 = 1 + match ( linetxt, cc.'.*$', 0 ) " " not found? if b_idx1 == 0 "echo 'line '.line.': no end-of-line comment' continue endif " " walk through ignored patterns let idx_start = 0 " while 1 let this_start = match ( linetxt, align_regex, idx_start ) " if this_start == -1 break else let idx_start = matchend ( linetxt, align_regex, idx_start ) "echo 'line '.line.': ignoring >>>'.strpart(linetxt,this_start,idx_start-this_start).'<<<' endif endwhile " let b_idx1 = 1 + match ( linetxt, '\s*'.cc.'.*$', idx_start ) let b_idx2 = 1 + match ( linetxt, cc.'.*$', idx_start ) " " not found? if b_idx1 == 0 "echo 'line '.line.': no end-of-line comment' continue endif " call cursor ( line, b_idx2 ) let v_idx2 = virtcol('.') " " do b_idx1 last, so the cursor is in the right position for substitute below call cursor ( line, b_idx1 ) let v_idx1 = virtcol('.') " " already at right position? if ( v_idx2 == correct_idx ) "echo 'line '.line.': already at right position' continue endif " ... or line too long? if ( v_idx1 > correct_idx ) "echo 'line '.line.': line too long' continue endif " " substitute all whitespaces behind the cursor (regex '\%#') and the next character, " to ensure the match is at least one character long silent exe 'substitute/\%#\s*\(\S\)/'.repeat( ' ', correct_idx - v_idx1 ).'\1/' "echo 'line '.line.': adjusted' " endfor " " restore the cursor position call setpos ( '.', save_cursor ) " endfunction " ---------- end of function Perl_AlignLineEndComm ---------- " let s:Perl_CmtCounter = 0 let s:Perl_CmtLabel = "BlockCommentNo_" " "=== FUNCTION ================================================================ " NAME: Perl_CommentBlock {{{1 " DESCRIPTION: set block of code within POD == begin / == end " PARAMETERS: mode - curent edit mode "=============================================================================== function! Perl_CommentBlock (mode) " let s:Perl_CmtCounter = 0 let save_line = line(".") let actual_line = 0 " " search for the maximum option number (if any) " normal! gg while actual_line < search( s:Perl_CmtLabel."\\d\\+" ) let actual_line = line(".") let actual_opt = matchstr( getline(actual_line), s:Perl_CmtLabel."\\d\\+" ) let actual_opt = strpart( actual_opt, strlen(s:Perl_CmtLabel),strlen(actual_opt)-strlen(s:Perl_CmtLabel)) if s:Perl_CmtCounter < actual_opt let s:Perl_CmtCounter = actual_opt endif endwhile let s:Perl_CmtCounter = s:Perl_CmtCounter+1 silent exe ":".save_line " if a:mode=='a' let zz= "\n=begin BlockComment # ".s:Perl_CmtLabel.s:Perl_CmtCounter let zz= zz."\n\n=end BlockComment # ".s:Perl_CmtLabel.s:Perl_CmtCounter let zz= zz."\n\n=cut\n\n" put =zz endif if a:mode=='v' let zz= "\n=begin BlockComment # ".s:Perl_CmtLabel.s:Perl_CmtCounter."\n\n" :'put =zz endif endfunction " ---------- end of function Perl_CommentBlock ---------- " "=== FUNCTION ================================================================ " NAME: Perl_UncommentBlock {{{1 " DESCRIPTION: uncomment block of code (remove POD commands) "=============================================================================== function! Perl_UncommentBlock () let frstline = searchpair( '^=begin\s\+BlockComment\s*#\s*'.s:Perl_CmtLabel.'\d\+', \ '', \ '^=end\s\+BlockComment\s\+#\s*'.s:Perl_CmtLabel.'\d\+', \ 'bn' ) if frstline<=0 echohl WarningMsg | echo 'no comment block/tag found or cursor not inside a comment block'| echohl None return endif let lastline = searchpair( '^=begin\s\+BlockComment\s*#\s*'.s:Perl_CmtLabel.'\d\+', \ '', \ '^=end\s\+BlockComment\s\+#\s*'.s:Perl_CmtLabel.'\d\+', \ 'n' ) if lastline<=0 echohl WarningMsg | echo 'no comment block/tag found or cursor not inside a comment block'| echohl None return endif let actualnumber1 = matchstr( getline(frstline), s:Perl_CmtLabel."\\d\\+" ) let actualnumber2 = matchstr( getline(lastline), s:Perl_CmtLabel."\\d\\+" ) if actualnumber1 != actualnumber2 echohl WarningMsg | echo 'lines '.frstline.', '.lastline.': comment tags do not match'| echohl None return endif let line1 = lastline let line2 = lastline " empty line before =end if match( getline(lastline-1), '^\s*$' ) != -1 let line1 = line1-1 endif if lastline+11 && match( getline(frstline-1), '^\s*$' ) != -1 let line1 = line1-1 endif if match( getline(frstline+1), '^\s*$' ) != -1 let line2 = line2+1 endif silent exe ':'.line1.','.line2.'d' endfunction " ---------- end of function Perl_UncommentBlock ---------- " "=== FUNCTION ================================================================ " NAME: Perl_CommentToggle {{{1 " DESCRIPTION: toggle comment "=============================================================================== function! Perl_CommentToggle () range let comment=1 " for line in range( a:firstline, a:lastline ) if match( getline(line), '^#') == -1 " no comment let comment = 0 break endif endfor if comment == 0 exe a:firstline.','.a:lastline."s/^/#/" else exe a:firstline.','.a:lastline."s/^#//" endif endfunction " ---------- end of function Perl_CommentToggle ---------- " "=== FUNCTION ================================================================ " NAME: Perl_CodeSnippet {{{1 " DESCRIPTION: read / write / edit code sni " PARAMETERS: mode - edit, read, write, writemarked, view "=============================================================================== function! Perl_CodeSnippet(mode) if isdirectory(g:Perl_CodeSnippets) " " read snippet file, put content below current line " if a:mode == "read" if has("gui_running") && s:Perl_GuiSnippetBrowser == 'gui' let l:snippetfile=browse(0,"read a code snippet",g:Perl_CodeSnippets,"") else let l:snippetfile=input("read snippet ", g:Perl_CodeSnippets, "file" ) endif if filereadable(l:snippetfile) let linesread= line("$") let l:old_cpoptions = &cpoptions " Prevent the alternate buffer from being set to this files setlocal cpoptions-=a :execute "read ".l:snippetfile let &cpoptions = l:old_cpoptions " restore previous options " let linesread= line("$")-linesread-1 if linesread>=0 && match( l:snippetfile, '\.\(ni\|noindent\)$' ) < 0 silent exe "normal! =".linesread."+" endif endif endif " " update current buffer / split window / edit snippet file " if a:mode == "edit" if has("gui_running") && s:Perl_GuiSnippetBrowser == 'gui' let l:snippetfile=browse(0,"edit a code snippet",g:Perl_CodeSnippets,"") else let l:snippetfile=input("edit snippet ", g:Perl_CodeSnippets, "file" ) endif if !empty(l:snippetfile) :execute "update! | split | edit ".l:snippetfile endif endif " " update current buffer / split window / view snippet file " if a:mode == "view" if has("gui_running") && s:Perl_GuiSnippetBrowser == 'gui' let l:snippetfile=browse(0,"view a code snippet",g:Perl_CodeSnippets,"") else let l:snippetfile=input("view snippet ", g:Perl_CodeSnippets, "file" ) endif if !empty(l:snippetfile) :execute "update! | split | view ".l:snippetfile endif endif " " write whole buffer or marked area into snippet file " if a:mode == "write" || a:mode == "writemarked" if has("gui_running") && s:Perl_GuiSnippetBrowser == 'gui' let l:snippetfile=browse(1,"write a code snippet",g:Perl_CodeSnippets,"") else let l:snippetfile=input("write snippet ", g:Perl_CodeSnippets, "file" ) endif if !empty(l:snippetfile) if filereadable(l:snippetfile) if confirm("File ".l:snippetfile." exists ! Overwrite ? ", "&Cancel\n&No\n&Yes") != 3 return endif endif if a:mode == "write" :execute ":write! ".l:snippetfile else :execute ":*write! ".l:snippetfile endif endif endif else redraw! echohl ErrorMsg echo "code snippet directory ".g:Perl_CodeSnippets." does not exist" echohl None endif endfunction " ---------- end of function Perl_CodeSnippet ---------- " "------------------------------------------------------------------------------ " Perl-Run : Perl_perldoc - lookup word under the cursor or ask "------------------------------------------------------------------------------ " let s:Perl_PerldocBufferName = "PERLDOC" let s:Perl_PerldocHelpBufferNumber = -1 let s:Perl_PerldocModulelistBuffer = -1 let s:Perl_PerldocSearchWord = "" let s:Perl_PerldocTry = "module" " "=== FUNCTION ================================================================ " NAME: Perl_perldoc {{{1 " DESCRIPTION: Perl_perldoc - lookup word under the cursor or ask "=============================================================================== function! Perl_perldoc() if( expand("%:p") == s:Perl_PerlModuleList ) normal! 0 let item=expand("") " WORD under the cursor else let cuc = getline(".")[col(".") - 1] " character under the cursor let item = expand("") " word under the cursor if empty(item) || match( item, cuc ) == -1 let item=Perl_Input("perldoc - module, function or FAQ keyword : ", "", '') endif endif "------------------------------------------------------------------------------ " replace buffer content with Perl documentation "------------------------------------------------------------------------------ if item != "" " " jump to an already open PERLDOC window or create one " if bufloaded(s:Perl_PerldocBufferName) != 0 && bufwinnr(s:Perl_PerldocHelpBufferNumber) != -1 exe bufwinnr(s:Perl_PerldocHelpBufferNumber) . "wincmd w" " buffer number may have changed, e.g. after a 'save as' if bufnr("%") != s:Perl_PerldocHelpBufferNumber let s:Perl_PerldocHelpBufferNumber=bufnr(s:Perl_OutputBufferName) exe ":bn ".s:Perl_PerldocHelpBufferNumber endif else exe ":new ".s:Perl_PerldocBufferName let s:Perl_PerldocHelpBufferNumber=bufnr("%") setlocal buftype=nofile setlocal noswapfile setlocal bufhidden=delete setlocal syntax=OFF endif " " search order: library module --> builtin function --> FAQ keyword " let delete_perldoc_errors = "" if s:UNIX && ( match( $shell, '\ccsh$' ) >= 0 ) " not for csh, tcsh let delete_perldoc_errors = " 2>/dev/null" endif setlocal modifiable " " controll repeated search " if item == s:Perl_PerldocSearchWord " last item : search ring : if s:Perl_PerldocTry == 'module' let next = 'function' endif if s:Perl_PerldocTry == 'function' let next = 'faq' endif if s:Perl_PerldocTry == 'faq' let next = 'module' endif let s:Perl_PerldocTry = next else " new item : let s:Perl_PerldocSearchWord = item let s:Perl_PerldocTry = 'module' endif " " module documentation if s:Perl_PerldocTry == 'module' let command=":%!perldoc ".s:Perl_perldoc_flags." ".item.delete_perldoc_errors silent exe command if v:shell_error != 0 redraw! let s:Perl_PerldocTry = 'function' endif if s:MSWIN call s:perl_RemoveSpecialCharacters() endif endif " " function documentation if s:Perl_PerldocTry == 'function' " -otext has to be ahead of -f and -q silent exe ":%!perldoc ".s:Perl_perldoc_flags." -f ".item.delete_perldoc_errors if v:shell_error != 0 redraw! let s:Perl_PerldocTry = 'faq' endif endif " " FAQ documentation if s:Perl_PerldocTry == 'faq' silent exe ":%!perldoc ".s:Perl_perldoc_flags." -q ".item.delete_perldoc_errors if v:shell_error != 0 redraw! let s:Perl_PerldocTry = 'error' endif endif " " no documentation found if s:Perl_PerldocTry == 'error' redraw! let zz= "No documentation found for perl module, perl function or perl FAQ keyword\n" let zz=zz." '".item."' " silent put! =zz normal! 2jdd$ let s:Perl_PerldocTry = 'module' let s:Perl_PerldocSearchWord = "" endif if s:UNIX " remove windows line ends silent! exe ":%s/\r$// | normal! gg" endif setlocal nomodifiable redraw! " highlight the headlines :match Search '^\S.*$' " ------------ " " ---------- Add ':' to the keyword characters ------------------------------- " Tokens like 'File::Find' are recognized as one keyword setlocal iskeyword+=: noremap :call Perl_perldoc() inoremap :call Perl_perldoc() endif endfunction " ---------- end of function Perl_perldoc ---------- " "=== FUNCTION ================================================================ " NAME: Perl_RemoveSpecialCharacters {{{1 " DESCRIPTION: remove in CYGWIN man(1) output " remove _ in CYGWIN man(1) output "=============================================================================== function! s:perl_RemoveSpecialCharacters ( ) let patternunderline = '_\%x08' let patternbold = '\%x08.' setlocal modifiable if search(patternunderline) != 0 silent exe ':%s/'.patternunderline.'//g' endif if search(patternbold) != 0 silent exe ':%s/'.patternbold.'//g' endif setlocal nomodifiable silent normal! gg endfunction " ---------- end of function s:perl_RemoveSpecialCharacters ---------- " "=== FUNCTION ================================================================ " NAME: Perl_perldoc_show_module_list {{{1 " DESCRIPTION: show module list "=============================================================================== function! Perl_perldoc_show_module_list() if !filereadable(s:Perl_PerlModuleList) redraw! echohl WarningMsg | echo 'Have to create '.s:Perl_PerlModuleList.' for the first time:'| echohl None call Perl_perldoc_generate_module_list() endif " " jump to the already open buffer or create one " if bufexists(s:Perl_PerldocModulelistBuffer) && bufwinnr(s:Perl_PerldocModulelistBuffer)!=-1 silent exe bufwinnr(s:Perl_PerldocModulelistBuffer) . "wincmd w" else :split exe ":view ".s:Perl_PerlModuleList let s:Perl_PerldocModulelistBuffer=bufnr("%") setlocal nomodifiable setlocal filetype=perl setlocal syntax=none noremap :call Perl_perldoc() inoremap :call Perl_perldoc() endif normal! gg redraw! if has("gui_running") echohl Search | echomsg 'use S-F1 to show a manual' | echohl None else echohl Search | echomsg 'use \hh in normal mode to show a manual' | echohl None endif endfunction " ---------- end of function Perl_perldoc_show_module_list ---------- " "=== FUNCTION ================================================================ " NAME: Perl_perldoc_generate_module_list {{{1 " DESCRIPTION: generate module list "=============================================================================== function! Perl_perldoc_generate_module_list() " save the module list, if any if filereadable( s:Perl_PerlModuleList ) let backupfile = s:Perl_PerlModuleList.'.backup' if rename( s:Perl_PerlModuleList, backupfile ) != 0 echomsg 'Could not rename "'.s:Perl_PerlModuleList.'" to "'.backupfile.'"' endif endif " echohl Search echo " ... generating Perl module list ... " if s:MSWIN silent exe ":!".s:Perl_Perl." ".fnameescape(s:Perl_PerlModuleListGenerator)." > ".shellescape(s:Perl_PerlModuleList) silent exe ":!sort ".fnameescape(s:Perl_PerlModuleList)." /O ".fnameescape(s:Perl_PerlModuleList) else " direct STDOUT and STDERR to the module list file : silent exe ":!".s:Perl_Perl." ".shellescape(s:Perl_PerlModuleListGenerator)." -s &> ".s:Perl_PerlModuleList endif redraw! echo " DONE " echohl None endfunction " ---------- end of function Perl_perldoc_generate_module_list ---------- " "=== FUNCTION ================================================================ " NAME: Perl_Settings {{{1 " DESCRIPTION: display various plugin settings " PARAMETERS: - " RETURNS: "=============================================================================== function! Perl_Settings () let txt = " Perl-Support settings\n\n" let txt = txt.' code snippet directory : "'.g:Perl_CodeSnippets."\"\n" let txt = txt.' author : "'.mmtemplates#core#ExpandText( g:Perl_Templates, '|AUTHOR|' )."\"\n" let txt = txt.' authorref : "'.mmtemplates#core#ExpandText( g:Perl_Templates, '|AUTHORREF|' )."\"\n" let txt = txt.' copyright holder : "'.mmtemplates#core#ExpandText( g:Perl_Templates, '|COPYRIGHT|' )."\"\n" let txt = txt.' email : "'.mmtemplates#core#ExpandText( g:Perl_Templates, '|EMAIL|' )."\"\n" let txt = txt.' organization : "'.mmtemplates#core#ExpandText( g:Perl_Templates, '|ORGANIZATION|' )."\"\n" let txt = txt.' template style : "'.mmtemplates#core#Resource ( g:Perl_Templates, "style" )[0]."\"\n" let txt = txt.' plugin installation : "'.g:Perl_Installation."\"\n" " ----- template files ------------------------ if g:Perl_Installation == 'system' let txt = txt.' global template file : "'.s:Perl_GlobalTemplateFile."\"\n" if filereadable( s:Perl_LocalTemplateFile ) let txt = txt.' local template file : '.s:Perl_LocalTemplateFile."\n" endif else let txt = txt.' local template file : '.s:Perl_LocalTemplateFile."\n" endif " ----- xterm ------------------------ if !s:MSWIN let txt = txt.' xterm defaults : '.s:Perl_XtermDefaults."\n" endif " ----- dictionaries ------------------------ if !empty(g:Perl_Dictionary_File) let ausgabe= &dictionary let ausgabe = substitute( ausgabe, ",", ",\n + ", "g" ) let txt = txt." dictionary file(s) : ".ausgabe."\n" endif let txt = txt." current output dest. : ".g:Perl_OutputGvim."\n" let txt = txt." perlcritic : perlcritic -severity ".s:Perl_PerlcriticSeverity \ .' ['.s:PCseverityName[s:Perl_PerlcriticSeverity].']' \ ." -verbosity ".s:Perl_PerlcriticVerbosity \ ." ".s:Perl_PerlcriticOptions."\n" if !empty(s:Perl_PerlExecutableVersion) let txt = txt." Perl interface version : ".s:Perl_PerlExecutableVersion."\n" endif " ----- toolbox ----------------------------- if s:Perl_UseToolbox == 'yes' let toollist = mmtoolbox#tools#GetList ( s:Perl_Toolbox ) if empty ( toollist ) let txt .= " toolbox : -no tools-\n" else let sep = "\n"." " let txt .= " toolbox : " \ .join ( toollist, sep )."\n" endif endif let txt = txt."\n" let txt = txt." Additional hot keys\n\n" let txt = txt." Shift-F1 : read perldoc (for word under cursor)\n" let txt = txt." F9 : start a debugger (".s:Perl_Debugger.")\n" let txt = txt." Alt-F9 : run syntax check \n" let txt = txt." Ctrl-F9 : run script \n" let txt = txt." Shift-F9 : set command line arguments\n" let txt = txt."_________________________________________________________________________\n" let txt = txt." Perl-Support, Version ".g:Perl_PluginVersion." / Dr.-Ing. Fritz Mehner / mehner.fritz@fh-swf.de\n\n" echo txt endfunction " ---------- end of function Perl_Settings ---------- " "=== FUNCTION ================================================================ " NAME: Perl_SyntaxCheck {{{1 " DESCRIPTION: syntax check " PARAMETERS: - " RETURNS: "=============================================================================== function! Perl_SyntaxCheck () if !Perl_Check_Interpreter() return endif exe ":cclose" let l:currentbuffer = bufname("%") let l:fullname = expand("%:p") silent exe ":update" " " avoid filtering the Perl output if the file name does not contain blanks: " call s:Perl_SaveGlobalOption('errorformat') call s:Perl_SaveGlobalOption('makeprg') " " Errorformat from compiler/perl.vim (VIM distribution). " exe ':set makeprg='.s:Perl_Perl.'\ -cW' exe ':set errorformat= \%-G%.%#had\ compilation\ errors., \%-G%.%#syntax\ OK, \%m\ at\ %f\ line\ %l., \%+A%.%#\ at\ %f\ line\ %l\\,%.%#, \%+C%.%#' silent exe ':make '. shellescape (l:fullname) exe ":botright cwindow" call s:Perl_RestoreGlobalOption('makeprg') call s:Perl_RestoreGlobalOption('errorformat') " " message in case of success " redraw! if l:currentbuffer == bufname("%") echohl Search echomsg l:currentbuffer." : Syntax is OK" echohl None return 0 else setlocal wrap setlocal linebreak endif endfunction " ---------- end of function Perl_SyntaxCheck ---------- " "=== FUNCTION ================================================================ " NAME: Perl_Toggle_Gvim_Xterm {{{1 " DESCRIPTION: toggle output destination (vim/buffer/xterm) " PARAMETERS: - " RETURNS: "=============================================================================== function! Perl_Toggle_Gvim_Xterm () let [ esc_mapl, err ] = mmtemplates#core#Resource ( g:Perl_Templates, 'escaped_mapleader' ) if g:Perl_OutputGvim == "vim" exe "aunmenu ".s:Perl_RootMenu.'.&Run.&output:\ VIM->buffer->xterm' exe "amenu ".s:Perl_RootMenu.'.&Run.&output:\ BUFFER->xterm->vim'.esc_mapl.'ro :call Perl_Toggle_Gvim_Xterm()' let g:Perl_OutputGvim = "buffer" else if g:Perl_OutputGvim == "buffer" exe "aunmenu ".s:Perl_RootMenu.'.&Run.&output:\ BUFFER->xterm->vim' if (!s:MSWIN) exe "amenu ".s:Perl_RootMenu.'.&Run.&output:\ XTERM->vim->buffer'.esc_mapl.'ro :call Perl_Toggle_Gvim_Xterm()' else exe "amenu ".s:Perl_RootMenu.'.&Run.&output:\ VIM->buffer->xterm '.esc_mapl.'ro :call Perl_Toggle_Gvim_Xterm()' endif if (!s:MSWIN) && (!empty($DISPLAY)) let g:Perl_OutputGvim = "xterm" else let g:Perl_OutputGvim = "vim" endif else " ---------- output : xterm -> gvim exe "aunmenu ".s:Perl_RootMenu.'.&Run.&output:\ XTERM->vim->buffer' exe "amenu ".s:Perl_RootMenu.'.&Run.&output:\ VIM->buffer->xterm'.esc_mapl.'ro :call Perl_Toggle_Gvim_Xterm()' let g:Perl_OutputGvim = "vim" endif endif echomsg "output destination is '".g:Perl_OutputGvim."'" endfunction " ---------- end of function Perl_Toggle_Gvim_Xterm ---------- " "------------------------------------------------------------------------------ " Command line arguments {{{1 "------------------------------------------------------------------------------ function! Perl_ScriptCmdLineArguments ( ... ) let b:Perl_CmdLineArgs= join( a:000 ) endfunction " ---------- end of function Perl_ScriptCmdLineArguments ---------- " "------------------------------------------------------------------------------ " Perl command line arguments {{{1 "------------------------------------------------------------------------------ function! Perl_PerlCmdLineArguments ( ... ) let b:Perl_Switches = join( a:000 ) endfunction " ---------- end of function Perl_PerlCmdLineArguments ---------- " let s:Perl_OutputBufferName = "Perl-Output" let s:Perl_OutputBufferNumber = -1 " "------------------------------------------------------------------------------ " Check if perl interpreter is executable {{{1 "------------------------------------------------------------------------------ function! Perl_Check_Interpreter () if !s:Perl_Perl_is_executable echohl WarningMsg echomsg '(possibly default) Perl interpreter "'.s:Perl_Perl.'" not executable' echohl None return 0 endif return 1 endfunction " ---------- end of function Perl_Check_Interpreter ---------- "=== FUNCTION ================================================================ " NAME: Perl_Run {{{1 " DESCRIPTION: run the current buffer " PARAMETERS: - " RETURNS: "=============================================================================== function! Perl_Run () if !Perl_Check_Interpreter() return endif if &filetype != "perl" echohl WarningMsg | echo expand("%:p").' seems not to be a Perl file' | echohl None return endif let buffername = expand("%") if fnamemodify( s:Perl_PerlModuleList, ":p:t" ) == buffername || s:Perl_PerldocBufferName == buffername return endif " let l:currentbuffernr = bufnr("%") let l:arguments = exists("b:Perl_CmdLineArgs") ? " ".b:Perl_CmdLineArgs : "" let l:switches = exists("b:Perl_Switches") ? b:Perl_Switches.' ' : "" let l:currentbuffer = bufname("%") let l:fullname = expand("%:p") " silent exe ":update" silent exe ":cclose" " "------------------------------------------------------------------------------ " run : run from the vim command line "------------------------------------------------------------------------------ if g:Perl_OutputGvim == "vim" " if executable(l:fullname) && s:Perl_DirectRun == 'yes' exe "!".shellescape(l:fullname).l:arguments else exe '!'.s:Perl_Perl.' '.l:switches.shellescape(l:fullname).l:arguments endif " endif " "------------------------------------------------------------------------------ " run : redirect output to an output buffer "------------------------------------------------------------------------------ if g:Perl_OutputGvim == "buffer" let l:currentbuffernr = bufnr("%") if l:currentbuffer == bufname("%") " " if bufloaded(s:Perl_OutputBufferName) != 0 && bufwinnr(s:Perl_OutputBufferNumber) != -1 exe bufwinnr(s:Perl_OutputBufferNumber) . "wincmd w" " buffer number may have changed, e.g. after a 'save as' if bufnr("%") != s:Perl_OutputBufferNumber let s:Perl_OutputBufferNumber=bufnr(s:Perl_OutputBufferName) exe ":bn ".s:Perl_OutputBufferNumber endif else silent exe ":new ".s:Perl_OutputBufferName let s:Perl_OutputBufferNumber=bufnr("%") setlocal buftype=nofile setlocal noswapfile setlocal syntax=none setlocal bufhidden=delete setlocal tabstop=8 endif " " run script " setlocal modifiable silent exe ":update" " if executable(l:fullname) && s:Perl_DirectRun == 'yes' exe "%!".shellescape(l:fullname).l:arguments else exe '%!'.s:Perl_Perl.' '.l:switches.shellescape(l:fullname).l:arguments endif " setlocal nomodifiable " if winheight(winnr()) >= line("$") exe bufwinnr(l:currentbuffernr) . "wincmd w" endif " endif endif " "------------------------------------------------------------------------------ " run : run in a detached xterm (not available for MS Windows) "------------------------------------------------------------------------------ if g:Perl_OutputGvim == "xterm" " if s:MSWIN " MSWIN : same as "vim" exe '!'.s:Perl_Perl.' '.l:switches.shellescape(l:fullname).l:arguments else " Linux if executable(l:fullname) == 1 && s:Perl_DirectRun == 'yes' silent exe '!xterm -title '.shellescape(l:fullname).' '.s:Perl_XtermDefaults.' -e '.s:Perl_Wrapper.' '.shellescape(l:fullname).l:arguments else silent exe '!xterm -title '.shellescape(l:fullname).' '.s:Perl_XtermDefaults.' -e '.s:Perl_Wrapper.' '.s:Perl_Perl.' '.l:switches.shellescape(l:fullname).l:arguments endif :redraw! endif " endif " endfunction " ---------- end of function Perl_Run ---------- " "=== FUNCTION ================================================================ " NAME: Perl_Debugger {{{1 " DESCRIPTION: start debugger " PARAMETERS: - " RETURNS: "=============================================================================== function! Perl_Debugger () " silent exe ":update" let l:arguments = exists("b:Perl_CmdLineArgs") ? " ".b:Perl_CmdLineArgs : "" let l:switches = exists("b:Perl_Switches") ? b:Perl_Switches.' ' : "" let filename = expand("%:p") " if s:MSWIN let l:arguments = substitute( l:arguments, '^\s\+', ' ', '' ) let l:arguments = substitute( l:arguments, '\s\+', "\" \"", 'g') let l:switches = substitute( l:switches, '^\s\+', ' ', '' ) let l:switches = substitute( l:switches, '\s\+', "\" \"", 'g') endif " " debugger is ' perl -d ... ' " if s:Perl_Debugger == "perl" if !Perl_Check_Interpreter() return endif if s:MSWIN exe '!'. s:Perl_Perl .' -d '.shellescape( filename.l:arguments ) else if has("gui_running") || &term == "xterm" silent exe "!xterm ".s:Perl_XtermDefaults.' -e ' . s:Perl_Perl . l:switches .' -d '.shellescape(filename).l:arguments.' &' else silent exe '!clear; ' .s:Perl_Perl. l:switches . ' -d '.shellescape(filename).l:arguments endif endif endif " if v:windowid != 0 " " grapical debugger is 'ptkdb', uses a PerlTk interface " if s:Perl_Debugger == "ptkdb" if s:MSWIN exe '!perl -d:ptkdb "'.filename.l:arguments.'"' else silent exe '!perl -d:ptkdb '.shellescape(filename).l:arguments.' &' endif endif " " debugger is 'ddd' (not available for MS Windows); graphical front-end for GDB " if s:Perl_Debugger == "ddd" && !s:MSWIN if !executable("ddd") echohl WarningMsg echo 'ddd does not exist or is not executable!' echohl None return else silent exe '!ddd '.shellescape(filename).l:arguments.' &' endif endif " endif " redraw! endfunction " ---------- end of function Perl_Debugger ---------- " "=== FUNCTION ================================================================ " NAME: Perl_XtermSize {{{1 " DESCRIPTION: read xterm geometry " PARAMETERS: - " RETURNS: "=============================================================================== function! Perl_XtermSize () let regex = '-geometry\s\+\d\+x\d\+' let geom = matchstr( s:Perl_XtermDefaults, regex ) let geom = matchstr( geom, '\d\+x\d\+' ) let geom = substitute( geom, 'x', ' ', "" ) let answer= Perl_Input(" xterm size (COLUMNS LINES) : ", geom ) while match(answer, '^\s*\d\+\s\+\d\+\s*$' ) < 0 let answer= Perl_Input(" + xterm size (COLUMNS LINES) : ", geom ) endwhile let answer = substitute( answer, '\s\+', "x", "" ) " replace inner whitespaces let s:Perl_XtermDefaults = substitute( s:Perl_XtermDefaults, regex, "-geometry ".answer , "" ) endfunction " ---------- end of function Perl_XtermSize ---------- " "=== FUNCTION ================================================================ " NAME: Perl_MakeScriptExecutable {{{1 " DESCRIPTION: make script executable " PARAMETERS: - " RETURNS: "=============================================================================== function! Perl_MakeScriptExecutable () let filename = expand("%:p") if executable(filename) == 0 " " not executable -> executable " if Perl_Input( '"'.filename.'" NOT executable. Make it executable [y/n] : ', 'y' ) == 'y' silent exe "!chmod u+x ".shellescape(filename) if v:shell_error " confirmation for the user echohl WarningMsg echo 'Could not make "'.filename.'" executable!' else " reload the file, otherwise the message will not be visible if ! &l:modified silent exe "edit" endif " confirmation for the user echohl Search echo 'Made "'.filename.'" executable.' endif echohl None endif else " " executable -> not executable " if Perl_Input( '"'.filename.'" is executable. Make it NOT executable [y/n] : ', 'y' ) == 'y' " reset all execution bits silent exe "!chmod -x ".shellescape(filename) if v:shell_error " confirmation for the user echohl WarningMsg echo 'Could not make "'.filename.'" not executable!' else " reload the file, otherwise the message will not be visible if ! &l:modified silent exe "edit" endif " confirmation for the user echohl Search echo 'Made "'.filename.'" not executable.' endif echohl None endif endif endfunction " ---------- end of function Perl_MakeScriptExecutable ---------- " "=== FUNCTION ================================================================ " NAME: Perl_PodCheck {{{1 " DESCRIPTION: run POD checker " PARAMETERS: - " RETURNS: "=============================================================================== function! Perl_PodCheck () exe ":cclose" let l:currentbuffer = bufname("%") silent exe ":update" " if s:Perl_PodcheckerWarnings == "no" let PodcheckerWarnings = '-nowarnings ' else let PodcheckerWarnings = '-warnings ' endif call s:Perl_SaveGlobalOption('makeprg') set makeprg=podchecker call s:Perl_SaveGlobalOption('errorformat') exe ':set errorformat=***\ %m\ at\ line\ %l\ in\ file\ %f' if s:MSWIN silent exe ':make '.PodcheckerWarnings.'"'.expand("%:p").'"' else silent exe ':make '.PodcheckerWarnings.fnameescape( expand("%:p") ) endif exe ":botright cwindow" call s:Perl_RestoreGlobalOption('makeprg') call s:Perl_RestoreGlobalOption('errorformat') " " message in case of success " redraw! if l:currentbuffer == bufname("%") echohl Search echomsg l:currentbuffer." : POD syntax is OK" echohl None return 0 endif return 1 endfunction " ---------- end of function Perl_PodCheck ---------- " "=== FUNCTION ================================================================ " NAME: Perl_POD {{{1 " DESCRIPTION: convert POD into html / man / text " PARAMETERS: format - target format " RETURNS: "=============================================================================== function! Perl_POD ( format ) let source = expand("%:p") let source_esc = fnameescape( expand("%:p"), ) let target = source.'.'.a:format let target_esc = source_esc.'.'.a:format silent exe ":update" if executable( 'pod2'.a:format ) if s:MSWIN if a:format=='html' silent exe ':!pod2'.a:format.' "--infile='.source.'" "--outfile='.target.'"' else silent exe ':!pod2'.a:format.' "'.source.'" "'.target.'"' endif else if a:format=='html' silent exe ':!pod2'.a:format.' --infile='.source_esc.' --outfile='.target_esc else silent exe ':!pod2'.a:format.' '.source_esc.' '.target_esc endif endif redraw! echo "file '".target."' generated" else redraw! echomsg 'Application "pod2'.a:format.'" does not exist or is not executable.' endif endfunction " ---------- end of function Perl_POD ---------- "=== FUNCTION ================================================================ " NAME: Perl_BrowseTemplateFiles {{{1 " DESCRIPTION: browse the template files " PARAMETERS: type - local / global " RETURNS: "=============================================================================== function! Perl_BrowseTemplateFiles ( type ) let templatefile = eval( 's:Perl_'.a:type.'TemplateFile' ) let templatedir = eval( 's:Perl_'.a:type.'TemplateDir' ) if isdirectory( templatedir ) if has("browse") && s:Perl_GuiTemplateBrowser == 'gui' let l:templatefile = browse(0,"edit a template file", templatedir, "" ) else let l:templatefile = '' if s:Perl_GuiTemplateBrowser == 'explorer' exe ':Explore '.templatedir endif if s:Perl_GuiTemplateBrowser == 'commandline' let l:templatefile = input("edit a template file", templatedir, "file" ) endif endif if !empty(l:templatefile) :execute "update! | split | edit ".l:templatefile endif else echomsg "Template directory '".templatedir."' does not exist." endif endfunction " ---------- end of function Perl_BrowseTemplateFiles ---------- "=== FUNCTION ================================================================ " NAME: Perl_OpenFold {{{1 " DESCRIPTION: Open fold and go to the first or last line of this fold " PARAMETERS: mode - below / start " RETURNS: "=============================================================================== function! Perl_OpenFold ( mode ) if foldclosed(".") >= 0 " we are on a closed fold: get end position, open fold, jump to the " last line of the previously closed fold let foldstart = foldclosed(".") let foldend = foldclosedend(".") normal! zv if a:mode == 'below' exe ":".foldend endif if a:mode == 'start' exe ":".foldstart endif endif endfunction " ---------- end of function Perl_OpenFold ---------- "=== FUNCTION ================================================================ " NAME: Perl_HighlightJumpTargets {{{1 " DESCRIPTION: highlight the jump targets " PARAMETERS: - " RETURNS: "=============================================================================== function! Perl_HighlightJumpTargets () if s:Perl_Ctrl_j == 'on' exe 'match Search /'.s:Perl_TemplateJumpTarget.'/' endif endfunction " ---------- end of function Perl_HighlightJumpTargets ---------- "=== FUNCTION ================================================================ " NAME: Perl_JumpCtrlJ {{{1 " DESCRIPTION: replaces the template system function for C-j " PARAMETERS: - " RETURNS: "=============================================================================== function! Perl_JumpCtrlJ () let match = search( s:Perl_TemplateJumpTarget, 'c' ) if match > 0 " remove the target call setline( match, substitute( getline('.'), s:Perl_TemplateJumpTarget, '', '' ) ) else " try to jump behind parenthesis or strings in the current line if match( getline(".")[col(".") - 1], "[\]})\"'`]" ) != 0 call search( "[\]})\"'`]", '', line(".") ) endif normal! l endif return '' endfunction " ---------- end of function Perl_JumpCtrlJ ---------- let s:Perl_perltidy_startscript_executable = 'no' let s:Perl_perltidy_module_executable = 'no' "=== FUNCTION ================================================================ " NAME: Perl_Perltidy {{{1 " DESCRIPTION: run perltidy(1) as a compiler " PARAMETERS: mode - n:normal / v:visual " RETURNS: "=============================================================================== function! Perl_Perltidy (mode) let Sou = expand("%") " name of the file in the current buffer if (&filetype != 'perl') && \ ( a:mode != 'v' || input( "'".Sou."' seems not to be a Perl file. Continue (y/n) : " ) != 'y' ) echomsg "'".Sou."' seems not to be a Perl file." return endif " " check if perltidy start script is executable " if s:Perl_perltidy_startscript_executable == 'no' if !executable("perltidy") echohl WarningMsg echo 'perltidy does not exist or is not executable!' echohl None return else let s:Perl_perltidy_startscript_executable = 'yes' endif endif " " check if perltidy module is executable " WORKAROUND: after upgrading Perl the module will no longer be found " if s:Perl_perltidy_module_executable == 'no' let perltidy_version = system("perltidy -v") if match( perltidy_version, 'copyright\c' ) >= 0 && \ match( perltidy_version, 'Steve\s\+Hancock' ) >= 0 let s:Perl_perltidy_module_executable = 'yes' else echohl WarningMsg echo 'The module Perl::Tidy can not be found! Please reinstall perltidy.' echohl None return endif endif " " ----- normal mode ---------------- if a:mode=="n" if Perl_Input("reformat whole file [y/n/Esc] : ", "y", '' ) != "y" return endif if s:Perl_PerltidyBackup == 'yes' exe ':write! '.Sou.'.bak' endif silent exe ":update" let pos1 = line(".") exe '%!perltidy' exe ':'.pos1 echo 'File "'.Sou.'" reformatted.' endif " ----- visual mode ---------------- if a:mode=="v" let pos1 = line("'<") let pos2 = line("'>") if s:Perl_PerltidyBackup == 'yes' exe pos1.','.pos2.':write! '.Sou.'.bak' endif silent exe pos1.','.pos2.'!perltidy' echo 'File "'.Sou.'" (lines '.pos1.'-'.pos2.') reformatted.' endif " if v:shell_error echohl WarningMsg echomsg 'perltidy reported error code '.v:shell_error.' !' echohl None endif " if filereadable("perltidy.ERR") echohl WarningMsg echo 'Perltidy detected an error when processing file "'.Sou.'". Please see file perltidy.ERR' echohl None endif " endfunction " ---------- end of function Perl_Perltidy ---------- "=== FUNCTION ================================================================ " NAME: Perl_SaveWithTimestamp {{{1 " DESCRIPTION: Save buffer with timestamp " PARAMETERS: - " RETURNS: "=============================================================================== function! Perl_SaveWithTimestamp () let file = fnameescape( expand("%") ) " name of the file in the current buffer if empty(file) " do we have a quickfix buffer : syntax errors / profiler report if &filetype == 'qf' let file = getcwd().'/Quickfix-List' else redraw! echohl WarningMsg | echo " no file name " | echohl None return endif endif let file = file.'.'.strftime(s:Perl_TimestampFormat) silent exe ":write ".file echomsg 'file "'.file.'" written' endfunction " ---------- end of function Perl_SaveWithTimestamp ---------- " "=== FUNCTION ================================================================ " NAME: Perl_Hardcopy {{{1 " DESCRIPTION: print PostScript to file " PARAMETERS: mode - n:normal / v:visual " RETURNS: "=============================================================================== function! Perl_Hardcopy (mode) let outfile = expand("%") if empty(outfile) redraw! echohl WarningMsg | echo " no file name " | echohl None return endif let outdir = getcwd() if outdir == substitute( s:Perl_PerlModuleList, '/[^/]\+$', '', '' ) || filewritable(outdir) != 2 let outdir = $HOME endif if !s:MSWIN let outdir = outdir.'/' endif let old_printheader=&printheader exe ':set printheader='.s:Perl_Printheader " ----- normal mode ---------------- if a:mode=="n" silent exe 'hardcopy > '.outdir.outfile.'.ps' if !s:MSWIN echo 'file "'.outfile.'" printed to "'.outdir.outfile.'.ps"' endif endif " ----- visual mode ---------------- if a:mode=="v" silent exe "*hardcopy > ".outdir.outfile.".ps" if !s:MSWIN echo 'file "'.outfile.'" (lines '.line("'<").'-'.line("'>").') printed to "'.outdir.outfile.'.ps"' endif endif exe ':set printheader='.escape( old_printheader, ' %' ) endfunction " ---------- end of function Perl_Hardcopy ---------- " "=== FUNCTION ================================================================ " NAME: Perl_HelpPerlsupport {{{1 " DESCRIPTION: display plugin help " PARAMETERS: - " RETURNS: "=============================================================================== function! Perl_HelpPerlsupport () try :help perlsupport catch exe ':helptags '.g:Perl_PluginDir.'/doc' :help perlsupport endtry endfunction " ---------- end of function Perl_HelpPerlsupport ---------- " "------------------------------------------------------------------------------ " run : perlcritic "------------------------------------------------------------------------------ " " All formats consist of 2 parts: " 1. the perlcritic message format " 2. the trailing '%+A%.%#\ at\ %f\ line\ %l%.%#' " Part 1 rebuilds the original perlcritic message. This is done to make " parsing of the messages easier. " Part 2 captures errors from inside perlcritic if any. " Some verbosity levels are treated equal to give quickfix the filename. " " verbosity rebuilt " let s:PCverbosityFormat1 = 1 let s:PCverbosityFormat2 = 2 let s:PCverbosityFormat3 = 3 let s:PCverbosityFormat4 = escape( '"%f:%l:%c:%m. %e (Severity: %s)\n"', '%' ) let s:PCverbosityFormat5 = escape( '"%f:%l:%c:%m. %e (Severity: %s)\n"', '%' ) let s:PCverbosityFormat6 = escape( '"%f:%l:%m, near ' . "'%r'." . ' (Severity: %s)\n"', '%' ) let s:PCverbosityFormat7 = escape( '"%f:%l:%m, near ' . "'%r'." . ' (Severity: %s)\n"', '%' ) let s:PCverbosityFormat8 = escape( '"%f:%l:%c:[%p] %m. (Severity: %s)\n"', '%' ) let s:PCverbosityFormat9 = escape( '"%f:%l:[%p] %m, near ' . "'%r'" . '. (Severity: %s)\n"', '%' ) let s:PCverbosityFormat10 = escape( '"%f:%l:%c:%m.\n %p (Severity: %s)\n%d\n"', '%' ) let s:PCverbosityFormat11 = escape( '"%f:%l:%m, near ' . "'%r'" . '.\n %p (Severity: %s)\n%d\n"', '%' ) " " parses output for different verbosity levels: " let s:PCInnerErrorFormat = ',\%+A%.%#\ at\ %f\ line\ %l%.%#' let s:PCerrorFormat1 = '%f:%l:%c:%m' . s:PCInnerErrorFormat let s:PCerrorFormat2 = '%f:\ (%l:%c)\ %m' . s:PCInnerErrorFormat let s:PCerrorFormat3 = '%m\ at\ %f\ line\ %l'. s:PCInnerErrorFormat let s:PCerrorFormat4 = '%f:%l:%c:%m' . s:PCInnerErrorFormat let s:PCerrorFormat5 = '%f:%l:%c:%m' . s:PCInnerErrorFormat let s:PCerrorFormat6 = '%f:%l:%m' . s:PCInnerErrorFormat let s:PCerrorFormat7 = '%f:%l:%m' . s:PCInnerErrorFormat let s:PCerrorFormat8 = '%f:%l:%m' . s:PCInnerErrorFormat let s:PCerrorFormat9 = '%f:%l:%m' . s:PCInnerErrorFormat let s:PCerrorFormat10 = '%f:%l:%m' . s:PCInnerErrorFormat let s:PCerrorFormat11 = '%f:%l:%m' . s:PCInnerErrorFormat " "=== FUNCTION ================================================================ " NAME: Perl_Perlcritic {{{1 " DESCRIPTION: run perlcritic(1) liek a compiler " PARAMETERS: - " RETURNS: "=============================================================================== function! Perl_Perlcritic () let l:currentbuffer = bufname("%") if &filetype != "perl" echohl WarningMsg | echo l:currentbuffer.' seems not to be a Perl file' | echohl None return endif if executable("perlcritic") == 0 " not executable echohl WarningMsg | echo 'perlcritic not installed or not executable' | echohl None return endif let s:Perl_PerlcriticMsg = "" exe ":cclose" silent exe ":update" " " check for a configuration file " let perlCriticRcFile = '' let perlCriticRcFileUsed = 'no' if exists("$PERLCRITIC") let perlCriticRcFile = $PERLCRITIC elseif filereadable( '.perlcriticrc' ) let perlCriticRcFile = '.perlcriticrc' elseif filereadable( $HOME.'/.perlcriticrc' ) let perlCriticRcFile = $HOME.'/.perlcriticrc' endif " " read severity and/or verbosity from the configuration file if specified " if perlCriticRcFile != '' for line in readfile(perlCriticRcFile) " default settings come before the first named block if line =~ '^\s*[' break else let list = matchlist( line, '^\s*severity\s*=\s*\([12345]\)' ) if !empty(list) let s:Perl_PerlcriticSeverity = list[1] let perlCriticRcFileUsed = 'yes' endif let list = matchlist( line, '^\s*severity\s*=\s*\(brutal\|cruel\|harsh\|stern\|gentle\)' ) if !empty(list) let s:Perl_PerlcriticSeverity = index( s:PCseverityName, list[1] ) let perlCriticRcFileUsed = 'yes' endif let list = matchlist( line, '^\s*verbose\s*=\s*\(\d\+\)' ) if !empty(list) && 1<= list[1] && list[1] <= 11 let s:Perl_PerlcriticVerbosity = list[1] let perlCriticRcFileUsed = 'yes' endif endif endfor endif " let perlcriticoptions = \ ' -severity '.s:Perl_PerlcriticSeverity \ .' -verbose '.eval("s:PCverbosityFormat".s:Perl_PerlcriticVerbosity) \ .' '.escape( s:Perl_PerlcriticOptions, g:Perl_FilenameEscChar ) \ .' ' " call s:Perl_SaveGlobalOption('errorformat') exe ':set errorformat='.eval("s:PCerrorFormat".s:Perl_PerlcriticVerbosity) call s:Perl_SaveGlobalOption('makeprg') set makeprg=perlcritic " if s:MSWIN silent exe ':make '.perlcriticoptions.'"'.expand("%:p").'"' else silent exe ':make '.perlcriticoptions.fnameescape( expand("%:p") ) endif " redraw! exe ":botright cwindow" call s:Perl_RestoreGlobalOption('errorformat') call s:Perl_RestoreGlobalOption('makeprg') " " message in case of success " let sev_and_verb = 'severity '.s:Perl_PerlcriticSeverity. \ ' ['.s:PCseverityName[s:Perl_PerlcriticSeverity].']'. \ ', verbosity '.s:Perl_PerlcriticVerbosity " let rcfile = '' if perlCriticRcFileUsed == 'yes' let rcfile = " ( configcfile '".perlCriticRcFile."' )" endif if l:currentbuffer == bufname("%") let s:Perl_PerlcriticMsg = l:currentbuffer.' : NO CRITIQUE, '.sev_and_verb.' '.rcfile else setlocal wrap setlocal linebreak let s:Perl_PerlcriticMsg = 'perlcritic : '.sev_and_verb.rcfile endif redraw! echohl Search | echo s:Perl_PerlcriticMsg | echohl None endfunction " ---------- end of function Perl_Perlcritic ---------- "=== FUNCTION ================================================================ " NAME: Perl_PerlcriticSeverityList {{{1 " DESCRIPTION: perlcritic severity : callback function for completion " PARAMETERS: ArgLead - " CmdLine - " CursorPos - " RETURNS: "=============================================================================== function! Perl_PerlcriticSeverityList ( ArgLead, CmdLine, CursorPos ) return filter( copy( s:PCseverityName[1:] ), 'v:val =~ "\\<'.a:ArgLead.'\\w*"' ) endfunction " ---------- end of function Perl_PerlcriticSeverityList ---------- "=== FUNCTION ================================================================ " NAME: Perl_PerlcriticVerbosityList {{{1 " DESCRIPTION: perlcritic verbosity : callback function for completion " PARAMETERS: ArgLead - " CmdLine - " CursorPos - " RETURNS: "=============================================================================== function! Perl_PerlcriticVerbosityList ( ArgLead, CmdLine, CursorPos ) return filter( copy( s:PCverbosityName), 'v:val =~ "\\<'.a:ArgLead.'\\w*"' ) endfunction " ---------- end of function Perl_PerlcriticVerbosityList ---------- "=== FUNCTION ================================================================ " NAME: Perl_GetPerlcriticSeverity {{{1 " DESCRIPTION: perlcritic severity : used in command definition " PARAMETERS: severity - perlcritic severity " RETURNS: "=============================================================================== function! Perl_GetPerlcriticSeverity ( severity ) let s:Perl_PerlcriticSeverity = 3 " the default let sev = a:severity let sev = substitute( sev, '^\s\+', '', '' ) " remove leading whitespaces let sev = substitute( sev, '\s\+$', '', '' ) " remove trailing whitespaces " if sev =~ '^\d$' && 1 <= sev && sev <= 5 " parameter is numeric let s:Perl_PerlcriticSeverity = sev " elseif sev =~ '^\a\+$' " parameter is a word let nr = index( s:PCseverityName, tolower(sev) ) if nr > 0 let s:Perl_PerlcriticSeverity = nr endif else " echomsg "wrong argument '".a:severity."' / severity is set to ".s:Perl_PerlcriticSeverity return endif echomsg "perlcritic severity is set to ".s:Perl_PerlcriticSeverity endfunction " ---------- end of function Perl_GetPerlcriticSeverity ---------- " "=== FUNCTION ================================================================ " NAME: Perl_PerlcriticSeverityInput " DESCRIPTION: read perlcritic severity from the command line " PARAMETERS: - " RETURNS: "=============================================================================== function! Perl_PerlcriticSeverityInput () let retval = input( "perlcritic severity (current = '".s:PCseverityName[s:Perl_PerlcriticSeverity]."' / tab exp.): ", '', 'customlist,Perl_PerlcriticSeverityList' ) redraw! call Perl_GetPerlcriticSeverity( retval ) return endfunction " ---------- end of function Perl_PerlcriticSeverityInput ---------- " "=== FUNCTION ================================================================ " NAME: Perl_GetPerlcriticVerbosity {{{1 " DESCRIPTION: perlcritic verbosity : used in command definition " PARAMETERS: verbosity - perlcritic verbosity " RETURNS: "=============================================================================== function! Perl_GetPerlcriticVerbosity ( verbosity ) let s:Perl_PerlcriticVerbosity = 4 let vrb = a:verbosity let vrb = substitute( vrb, '^\s\+', '', '' ) " remove leading whitespaces let vrb = substitute( vrb, '\s\+$', '', '' ) " remove trailing whitespaces if vrb =~ '^\d\{1,2}$' && 1 <= vrb && vrb <= 11 let s:Perl_PerlcriticVerbosity = vrb echomsg "perlcritic verbosity is set to ".s:Perl_PerlcriticVerbosity else echomsg "wrong argument '".a:verbosity."' / perlcritic verbosity is set to ".s:Perl_PerlcriticVerbosity endif endfunction " ---------- end of function Perl_GetPerlcriticVerbosity ---------- " "=== FUNCTION ================================================================ " NAME: Perl_PerlcriticVerbosityInput {{{1 " DESCRIPTION: read perlcritic verbosity from the command line " PARAMETERS: - " RETURNS: "=============================================================================== function! Perl_PerlcriticVerbosityInput () let retval = input( "perlcritic verbosity (current = ".s:Perl_PerlcriticVerbosity." / tab exp.): ", '', 'customlist,Perl_PerlcriticVerbosityList' ) redraw! call Perl_GetPerlcriticVerbosity( retval ) return endfunction " ---------- end of function Perl_PerlcriticVerbosityInput ---------- " "=== FUNCTION ================================================================ " NAME: Perl_GetPerlcriticOptions {{{1 " DESCRIPTION: perlcritic options : used in command definition " PARAMETERS: ... - " RETURNS: "=============================================================================== function! Perl_GetPerlcriticOptions ( ... ) let s:Perl_PerlcriticOptions = "" if a:0 > 0 let s:Perl_PerlcriticOptions = a:1 endif endfunction " ---------- end of function Perl_GetPerlcriticOptions ---------- " "=== FUNCTION ================================================================ " NAME: Perl_PerlcriticOptionsInput {{{1 " DESCRIPTION: read perlcritic options from the command line " PARAMETERS: - " RETURNS: "=============================================================================== function! Perl_PerlcriticOptionsInput () let retval = input( "perlcritic options (current = '".s:Perl_PerlcriticOptions."'): " ) redraw! call Perl_GetPerlcriticOptions( retval ) return endfunction " ---------- end of function Perl_PerlcriticOptionsInput ---------- " "=== FUNCTION ================================================================ " NAME: Perl_CreateGuiMenus {{{1 " DESCRIPTION: create GUI menus immediate " PARAMETERS: - " RETURNS: "=============================================================================== function! Perl_CreateGuiMenus () if s:Perl_MenuVisible != 'yes' aunmenu &Tools.Load\ Perl\ Support amenu 40.1000 &Tools.-SEP100- : amenu 40.1160 &Tools.Unload\ Perl\ Support :call Perl_RemoveGuiMenus() call s:Perl_RereadTemplates('no') call s:Perl_InitMenus () let s:Perl_MenuVisible = 'yes' endif endfunction " ---------- end of function Perl_CreateGuiMenus ---------- " "------------------------------------------------------------------------------ " === Templates API === {{{1 "------------------------------------------------------------------------------ " "------------------------------------------------------------------------------ " Perl_SetMapLeader {{{2 "------------------------------------------------------------------------------ function! Perl_SetMapLeader () if exists ( 'g:Perl_MapLeader' ) call mmtemplates#core#SetMapleader ( g:Perl_MapLeader ) endif endfunction " ---------- end of function Perl_SetMapLeader ---------- " "------------------------------------------------------------------------------ " Perl_ResetMapLeader {{{2 "------------------------------------------------------------------------------ function! Perl_ResetMapLeader () if exists ( 'g:Perl_MapLeader' ) call mmtemplates#core#ResetMapleader () endif endfunction " ---------- end of function Perl_ResetMapLeader ---------- " }}}2 " "=== FUNCTION ================================================================ " NAME: Perl_RereadTemplates {{{1 " DESCRIPTION: rebuild commands and the menu from the (changed) template file " PARAMETERS: displaymsg - yes / no " RETURNS: "=============================================================================== function! s:Perl_RereadTemplates ( displaymsg ) " "------------------------------------------------------------------------------- " SETUP TEMPLATE LIBRARY "------------------------------------------------------------------------------- let g:Perl_Templates = mmtemplates#core#NewLibrary () " " mapleader if empty ( g:Perl_MapLeader ) call mmtemplates#core#Resource ( g:Perl_Templates, 'set', 'property', 'Templates::Mapleader', '\' ) else call mmtemplates#core#Resource ( g:Perl_Templates, 'set', 'property', 'Templates::Mapleader', g:Perl_MapLeader ) endif " " map: choose style call mmtemplates#core#Resource ( g:Perl_Templates, 'set', 'property', 'Templates::ChooseStyle::Map', 'nts' ) " " syntax: comments call mmtemplates#core#ChangeSyntax ( g:Perl_Templates, 'comment', 'ยง' ) let s:Perl_TemplateJumpTarget = mmtemplates#core#Resource ( g:Perl_Templates, "jumptag" )[0] " let messsage = '' " if g:Perl_Installation == 'system' "------------------------------------------------------------------------------- " SYSTEM INSTALLATION "------------------------------------------------------------------------------- if filereadable( s:Perl_GlobalTemplateFile ) call mmtemplates#core#ReadTemplates ( g:Perl_Templates, 'load', s:Perl_GlobalTemplateFile ) else echomsg "Global template file '".s:Perl_GlobalTemplateFile."' not readable." return endif let messsage = "Templates read from '".s:Perl_GlobalTemplateFile."'" " "------------------------------------------------------------------------------- " handle local template files "------------------------------------------------------------------------------- let templ_dir = fnamemodify( s:Perl_LocalTemplateFile, ":p:h" ).'/' " if finddir( templ_dir ) == '' " try to create a local template directory if exists("*mkdir") try call mkdir( templ_dir, "p" ) catch /.*/ endtry endif endif if isdirectory( templ_dir ) && !filereadable( s:Perl_LocalTemplateFile ) " write a default local template file let template = [ ] let sample_template_file = g:Perl_PluginDir.'/perl-support/rc/sample_template_file' if filereadable( sample_template_file ) for line in readfile( sample_template_file ) call add( template, line ) endfor call writefile( template, s:Perl_LocalTemplateFile ) endif endif " if filereadable( s:Perl_LocalTemplateFile ) call mmtemplates#core#ReadTemplates ( g:Perl_Templates, 'load', s:Perl_LocalTemplateFile ) let messsage = messsage." and '".s:Perl_LocalTemplateFile."'" if mmtemplates#core#ExpandText( g:Perl_Templates, '|AUTHOR|' ) == 'YOUR NAME' echomsg "Please set your personal details in file '".s:Perl_LocalTemplateFile."'." endif endif " else "------------------------------------------------------------------------------- " LOCAL INSTALLATION "------------------------------------------------------------------------------- if filereadable( s:Perl_LocalTemplateFile ) call mmtemplates#core#ReadTemplates ( g:Perl_Templates, 'load', s:Perl_LocalTemplateFile ) let messsage = "Templates read from '".s:Perl_LocalTemplateFile."'" else echomsg "Local template file '".s:Perl_LocalTemplateFile."' not readable." return endif " endif if a:displaymsg == 'yes' echomsg messsage.'.' endif endfunction " ---------- end of function s:Perl_RereadTemplates ---------- " "------------------------------------------------------------------------------ " Check the perlcritic default severity and verbosity. "------------------------------------------------------------------------------ silent call Perl_GetPerlcriticSeverity (s:Perl_PerlcriticSeverity) silent call Perl_GetPerlcriticVerbosity(s:Perl_PerlcriticVerbosity) "=== FUNCTION ================================================================ " NAME: Perl_do_tags {{{1 " DESCRIPTION: tag a new file with Perl::Tags::Naive " PARAMETERS: filename - " tagfile - name of the tag file " RETURNS: "=============================================================================== function! Perl_do_tags(filename, tagfile) if g:Perl_PerlTags == 'on' perl <process(files => $filename, refresh=>1 ); } VIM::SetOption("tags+=$tagfile"); # of course, it may not even output, for example, if there's nothing new to process $naive_tagger->output( outfile => $tagfile ); PERL_DO_TAGS endif endfunction " ---------- end of function Perl_do_tags ---------- "=== FUNCTION ================================================================ " NAME: Perl_ModuleListFold {{{1 " DESCRIPTION: compute foldlevel for a module list " debug with "set debug=msg" " PARAMETERS: lnum - " RETURNS: "=============================================================================== function! Perl_ModuleListFold (lnum) let line1 = split( getline(a:lnum-1), '::' ) let line2 = split( getline(a:lnum ), '::' ) let foldlevel = 0 if !empty(line1) while foldlevel < len(line1) && foldlevel < len(line2) && line1[foldlevel] == line2[foldlevel] let foldlevel += 1 endwhile endif return foldlevel endfunction " ---------- end of function Perl_ModuleListFold ---------- " "=== FUNCTION ================================================================ " NAME: Perl_MenuTitle {{{1 " DESCRIPTION: display warning " PARAMETERS: - " RETURNS: "=============================================================================== function! Perl_MenuTitle () echohl WarningMsg | echo "This is a menu header." | echohl None endfunction " ---------- end of function Perl_MenuTitle ---------- " "=== FUNCTION ================================================================ " NAME: Perl_InitMenus {{{1 " DESCRIPTION: initialize the hardcoded menu items " PARAMETERS: - " RETURNS: "=============================================================================== function! s:Perl_InitMenus () " if ! has ( 'menu' ) return endif " " Preparation call mmtemplates#core#CreateMenus ( 'g:Perl_Templates', s:Perl_RootMenu, 'do_reset' ) " " get the mapleader (correctly escaped) let [ esc_mapl, err ] = mmtemplates#core#Resource ( g:Perl_Templates, 'escaped_mapleader' ) " exe 'amenu '.s:Perl_RootMenu.'.Perl ' exe 'amenu '.s:Perl_RootMenu.'.-Sep00- ' " "------------------------------------------------------------------------------- " menu headers "------------------------------------------------------------------------------- " call mmtemplates#core#CreateMenus ( 'g:Perl_Templates', s:Perl_RootMenu, 'sub_menu', '&Comments', 'priority', 500 ) " the other, automatically created menus go here; their priority is the standard priority 500 call mmtemplates#core#CreateMenus ( 'g:Perl_Templates', s:Perl_RootMenu, 'sub_menu', 'S&nippets' , 'priority', 600 ) call mmtemplates#core#CreateMenus ( 'g:Perl_Templates', s:Perl_RootMenu, 'sub_menu', '&Profiling', 'priority', 700 ) call mmtemplates#core#CreateMenus ( 'g:Perl_Templates', s:Perl_RootMenu, 'sub_menu', '&Run' , 'priority', 800 ) if s:Perl_UseToolbox == 'yes' && mmtoolbox#tools#Property ( s:Perl_Toolbox, 'empty-menu' ) == 0 call mmtemplates#core#CreateMenus ( 'g:Perl_Templates', s:Perl_RootMenu, 'sub_menu', '&Tool Box', 'priority', 900 ) endif call mmtemplates#core#CreateMenus ( 'g:Perl_Templates', s:Perl_RootMenu, 'sub_menu', '&Help' , 'priority', 1000 ) " "=============================================================================================== "----- Menu : Comments {{{2 "=============================================================================================== " let ahead = 'anoremenu '.s:Perl_RootMenu.'.&Comments.' let vhead = 'vnoremenu '.s:Perl_RootMenu.'.&Comments.' let ihead = 'inoremenu '.s:Perl_RootMenu.'.&Comments.' " exe ahead.'end-of-&line\ comment'.esc_mapl.'cl :call Perl_EndOfLineComment()' exe vhead.'end-of-&line\ comment'.esc_mapl.'cl :call Perl_EndOfLineComment()' exe ahead.'ad&just\ end-of-line\ com\.'.esc_mapl.'cj :call Perl_AlignLineEndComm()' exe vhead.'ad&just\ end-of-line\ com\.'.esc_mapl.'cj :call Perl_AlignLineEndComm()' exe ahead.'&set\ end-of-line\ com\.\ col\.'.esc_mapl.'cs :call Perl_GetLineEndCommCol()' " exe ahead.'-Sep01- ' exe ahead.'toggle\ &comment'.esc_mapl.'cc :call Perl_CommentToggle()j' exe ihead.'toggle\ &comment'.esc_mapl.'cc :call Perl_CommentToggle()j' exe vhead.'toggle\ &comment'.esc_mapl.'cc :call Perl_CommentToggle()j' exe ahead.'comment\ &block'.esc_mapl.'cb :call Perl_CommentBlock("a")' exe ihead.'comment\ &block'.esc_mapl.'cb :call Perl_CommentBlock("a")' exe vhead.'comment\ &block'.esc_mapl.'cb :call Perl_CommentBlock("v")' exe ahead.'u&ncomment\ block'.esc_mapl.'cub :call Perl_UncommentBlock()' exe ahead.'-Sep02- ' " "=============================================================================================== "----- Menu : GENERATE MENU ITEMS FROM THE TEMPLATES {{{2 "=============================================================================================== call mmtemplates#core#CreateMenus ( 'g:Perl_Templates', s:Perl_RootMenu, 'do_templates' ) " "=============================================================================================== "----- Menu : Snippets {{{2 "=============================================================================================== " let ahead = 'anoremenu '.s:Perl_RootMenu.'.S&nippets.' let vhead = 'vnoremenu '.s:Perl_RootMenu.'.S&nippets.' let ihead = 'inoremenu '.s:Perl_RootMenu.'.S&nippets.' " if !empty(s:Perl_CodeSnippets) exe ahead.'&read\ code\ snippet'.esc_mapl.'nr :call Perl_CodeSnippet("read")' exe ihead.'&read\ code\ snippet'.esc_mapl.'nr :call Perl_CodeSnippet("read")' exe ahead.'&view\ code\ snippet'.esc_mapl.'nv :call Perl_CodeSnippet("view")' exe ihead.'&view\ code\ snippet'.esc_mapl.'nv :call Perl_CodeSnippet("view")' exe ahead.'&write\ code\ snippet'.esc_mapl.'nw :call Perl_CodeSnippet("write")' exe vhead.'&write\ code\ snippet'.esc_mapl.'nw :call Perl_CodeSnippet("writemarked")' exe ihead.'&write\ code\ snippet'.esc_mapl.'nw :call Perl_CodeSnippet("write")' exe ahead.'&edit\ code\ snippet'.esc_mapl.'ne :call Perl_CodeSnippet("edit")' exe ihead.'&edit\ code\ snippet'.esc_mapl.'ne :call Perl_CodeSnippet("edit")' exe ahead.'-SepSnippets- :' endif " exe ahead.'edit\ &local\ templates'.esc_mapl.'ntl :call mmtemplates#core#EditTemplateFiles(g:Perl_Templates,-1)' exe ihead.'edit\ &local\ templates'.esc_mapl.'ntl :call mmtemplates#core#EditTemplateFiles(g:Perl_Templates,-1)' if g:Perl_Installation == 'system' exe ahead.'edit\ &global\ templates'.esc_mapl.'ntg :call mmtemplates#core#EditTemplateFiles(g:Perl_Templates,0)' exe ihead.'edit\ &global\ templates'.esc_mapl.'ntg :call mmtemplates#core#EditTemplateFiles(g:Perl_Templates,0)' endif " exe ahead.'reread\ &templates'.esc_mapl.'ntr :call mmtemplates#core#ReadTemplates(g:Perl_Templates,"reload","all")' exe ihead.'reread\ &templates'.esc_mapl.'ntr :call mmtemplates#core#ReadTemplates(g:Perl_Templates,"reload","all")' " call mmtemplates#core#CreateMenus ( 'g:Perl_Templates', s:Perl_RootMenu, 'do_styles', 'specials_menu', 'Snippets' ) " "=============================================================================================== "----- Menu : Profiling {{{2 "=============================================================================================== " let ahead = 'amenu '.s:Perl_RootMenu.'.&Profiling.' exe ahead.'&run\ SmallProf'.esc_mapl.'rps :call perlsupportprofiling#Perl_Smallprof()' exe ahead.'sort\ SmallProf\ report'.esc_mapl.'rpss :call perlsupportprofiling#Perl_SmallProfSortInput()' exe ahead.'open\ existing\ SmallProf\ results'.esc_mapl.'rpso :call perlsupportprofiling#Perl_Smallprof_OpenQuickfix()' exe ahead.'-Sep01- ' " if !s:MSWIN exe ahead.'&run\ FastProf'.esc_mapl.'rpf :call perlsupportprofiling#Perl_Fastprof()' exe ahead.'sort\ FastProf\ report'.esc_mapl.'rpfs :call perlsupportprofiling#Perl_FastProfSortInput()' exe ahead.'open\ existing\ FastProf\ results'.esc_mapl.'rpfo :call perlsupportprofiling#Perl_FastProf_OpenQuickfix()' exe ahead.'-Sep02- ' endif " exe ahead.'&run\ NYTProf'.esc_mapl.'rpn :call perlsupportprofiling#Perl_NYTprof()' exe ahead.'show\ &HTML\ report'.esc_mapl.'rph :call perlsupportprofiling#Perl_NYTprofReadHtml()' exe ahead.'open\ &CSV\ file'.esc_mapl.'rpno :call perlsupportprofiling#Perl_NYTprofReadCSV("read","line")' exe ahead.'sort\ NYTProf\ CSV\ report'.esc_mapl.'rpns :call perlsupportprofiling#Perl_SmallProfSortInput()' " "=============================================================================================== "----- Menu : Run {{{2 "=============================================================================================== " " run the script from the local directory " ( the one which is being edited; other versions may exist elsewhere ! ) " let ahead = 'amenu '.s:Perl_RootMenu.'.&Run.' let vhead = 'vmenu '.s:Perl_RootMenu.'.&Run.' " exe ahead.'update,\ &run\ script'.esc_mapl.'rr\ \ :call Perl_Run()' exe ahead.'update,\ check\ &syntax'.esc_mapl.'rs\ \ :call Perl_SyntaxCheck()' exe 'amenu '.s:Perl_RootMenu.'.&Run.cmd\.\ line\ &arg\.'.esc_mapl.'ra\ \ :PerlScriptArguments' exe 'amenu .'s:Perl_RootMenu.'.&Run.perl\ s&witches'.esc_mapl.'rw :PerlSwitches' " " set execution rights for user only ( user may be root ! ) if !s:MSWIN exe ahead.'make\ script\ &exe\./not\ exec\.'.esc_mapl.'re :call Perl_MakeScriptExecutable()' endif exe ahead.'start\ &debugger'.esc_mapl.'rd\ \ :call Perl_Debugger()' " exe ahead.'-SEP2- :' exe ahead.'show\ &installed\ Perl\ modules'.esc_mapl.'ri :call Perl_perldoc_show_module_list()' exe ahead.'&generate\ Perl\ module\ list'.esc_mapl.'rg :call Perl_perldoc_generate_module_list()' " exe ahead.'-SEP4- :' exe ahead.'run\ perltid&y'.esc_mapl.'ry :call Perl_Perltidy("n")' exe vhead.'run\ perltid&y'.esc_mapl.'ry :call Perl_Perltidy("v")' " " exe ahead.'-SEP3- :' exe ahead.'run\ perl&critic'.esc_mapl.'rpc :call Perl_Perlcritic()' " if g:Perl_MenuHeader == "yes" exe ahead.'perlcritic\ severity'.esc_mapl.'rpcs.severity :call Perl_MenuTitle()' exe ahead.'perlcritic\ severity'.esc_mapl.'rpcs.-Sep5- :' endif let levelnumber = 1 for level in s:PCseverityName[1:] exe ahead.'perlcritic\ severity'.esc_mapl.'rpcs.&'.level.'(='.levelnumber.') :call Perl_GetPerlcriticSeverity("'.level.'")' let levelnumber = levelnumber+1 endfor " if g:Perl_MenuHeader == "yes" exe ahead.'perlcritic\ &verbosity'.esc_mapl.'rpcv.verbosity :call Perl_MenuTitle()' exe ahead.'perlcritic\ &verbosity'.esc_mapl.'rpcv.-Sep6- :' endif for level in s:PCverbosityName exe ahead.'perlcritic\ &verbosity'.esc_mapl.'rpcv.&'.level.' :call Perl_GetPerlcriticVerbosity('.level.')' endfor exe ahead.'perlcritic\ &options'.esc_mapl.'rpco :call Perl_PerlcriticOptionsInput()' exe ahead.'-SEP5- :' exe ahead.'save\ buffer\ with\ ×tamp'.esc_mapl.'rt :call Perl_SaveWithTimestamp()' exe ahead.'&hardcopy\ to\ FILENAME\.ps'.esc_mapl.'rh :call Perl_Hardcopy("n")' exe vhead.'&hardcopy\ to\ FILENAME\.ps'.esc_mapl.'rh :call Perl_Hardcopy("v")' exe ahead.'-SEP6- :' exe ahead.'settings\ and\ hot\ &keys'.esc_mapl.'rk :call Perl_Settings()' " if !s:MSWIN exe ahead.'&xterm\ size'.esc_mapl.'rx :call Perl_XtermSize()' endif if g:Perl_OutputGvim == "vim" exe ahead.'&output:\ VIM->buffer->xterm'.esc_mapl.'ro :call Perl_Toggle_Gvim_Xterm()' else if g:Perl_OutputGvim == "buffer" exe ahead.'&output:\ BUFFER->xterm->vim'.esc_mapl.'ro :call Perl_Toggle_Gvim_Xterm()' else exe ahead.'&output:\ XTERM->vim->buffer'.esc_mapl.'ro :call Perl_Toggle_Gvim_Xterm()' endif endif " "=============================================================================================== "----- Menu : Tools {{{2 "=============================================================================================== " if s:Perl_UseToolbox == 'yes' && mmtoolbox#tools#Property ( s:Perl_Toolbox, 'empty-menu' ) == 0 call mmtoolbox#tools#AddMenus ( s:Perl_Toolbox, s:Perl_RootMenu.'.&Tool\ Box' ) endif " "=============================================================================================== "----- Menu : Help {{{2 "=============================================================================================== " let ahead = 'anoremenu '.s:Perl_RootMenu.'.Help.' let vhead = 'vnoremenu '.s:Perl_RootMenu.'.Help.' let ihead = 'inoremenu '.s:Perl_RootMenu.'.Help.' " exe ahead.'read\ &perldoc'.esc_mapl.'h :call Perl_perldoc()' exe ihead.'read\ &perldoc'.esc_mapl.'h :call Perl_perldoc()' exe ahead.'-SEP1- :' exe ahead.'&help\ (Perl-Support)'.esc_mapl.'hp :call Perl_HelpPerlsupport()' exe ihead.'&help\ (Perl-Support)'.esc_mapl.'hp :call Perl_HelpPerlsupport()' " "=============================================================================================== "----- Menu : Regex menu (items) {{{2 "=============================================================================================== " exe " noremenu ".s:Perl_RootMenu.'.Rege&x.-SEP7- :' exe "amenu ".s:Perl_RootMenu.'.Rege&x.pick\ up\ ®ex'.esc_mapl.'xr :call perlsupportregex#Perl_RegexPick( "Regexp", "n" )j' exe "amenu ".s:Perl_RootMenu.'.Rege&x.pick\ up\ s&tring'.esc_mapl.'xs :call perlsupportregex#Perl_RegexPick( "String", "n" )j' exe "amenu ".s:Perl_RootMenu.'.Rege&x.pick\ up\ &flag(s)'.esc_mapl.'xf :call perlsupportregex#Perl_RegexPickFlag( "n" )' exe "vmenu ".s:Perl_RootMenu.'.Rege&x.pick\ up\ ®ex'.esc_mapl.'xr :call perlsupportregex#Perl_RegexPick( "Regexp", "v" )'."'>j" exe "vmenu ".s:Perl_RootMenu.'.Rege&x.pick\ up\ s&tring'.esc_mapl.'xs :call perlsupportregex#Perl_RegexPick( "String", "v" )'."'>j" exe "vmenu ".s:Perl_RootMenu.'.Rege&x.pick\ up\ &flag(s)'.esc_mapl.'xf :call perlsupportregex#Perl_RegexPickFlag( "v" )'."'>j" " Menu exe "amenu ".s:Perl_RootMenu.'.Rege&x.&match'.esc_mapl.'xm :call perlsupportregex#Perl_RegexVisualize( )' exe "amenu ".s:Perl_RootMenu.'.Rege&x.matc&h\ several\ targets'.esc_mapl.'xmm :call perlsupportregex#Perl_RegexMatchSeveral( )' exe "amenu ".s:Perl_RootMenu.'.Rege&x.&explain\ regex'.esc_mapl.'xe :call perlsupportregex#Perl_RegexExplain( "n" )' exe "vmenu ".s:Perl_RootMenu.'.Rege&x.&explain\ regex'.esc_mapl.'xe :call perlsupportregex#Perl_RegexExplain( "v" )' " "=============================================================================================== "----- Menu : POD menu (items) {{{2 "=============================================================================================== " exe "amenu ".s:Perl_RootMenu.'.&POD.-SEP4- :' exe "amenu ".s:Perl_RootMenu.'.&POD.run\ &podchecker'.esc_mapl.'pod :call Perl_PodCheck()' exe "amenu ".s:Perl_RootMenu.'.&POD.POD\ ->\ &html'.esc_mapl.'podh :call Perl_POD("html")' exe "amenu ".s:Perl_RootMenu.'.&POD.POD\ ->\ &man'.esc_mapl.'podm :call Perl_POD("man")' exe "amenu ".s:Perl_RootMenu.'.&POD.POD\ ->\ &text'.esc_mapl.'podt :call Perl_POD("text")' " return endfunction " ---------- end of function s:Perl_InitMenus ---------- "=== FUNCTION ================================================================ " NAME: Perl_ToolMenu {{{1 " DESCRIPTION: generate the tool menu item " PARAMETERS: - " RETURNS: "=============================================================================== function! Perl_ToolMenu () amenu 40.1000 &Tools.-SEP100- : amenu 40.1160 &Tools.Load\ Perl\ Support :call Perl_CreateGuiMenus() endfunction " ---------- end of function Perl_ToolMenu ---------- "=== FUNCTION ================================================================ " NAME: Perl_RemoveGuiMenus {{{1 " DESCRIPTION: remove the Perl menu " PARAMETERS: - " RETURNS: "=============================================================================== function! Perl_RemoveGuiMenus () if s:Perl_MenuVisible == 'yes' exe "aunmenu ".s:Perl_RootMenu " aunmenu &Tools.Unload\ Perl\ Support call Perl_ToolMenu() " let s:Perl_MenuVisible = 'no' endif endfunction " ---------- end of function Perl_RemoveGuiMenus ---------- " "=== FUNCTION ================================================================ " NAME: Perl_GetRegexSubstitution {{{1 " DESCRIPTION: get regex control character replacements (2 characters) " PARAMETERS: - "=============================================================================== function! Perl_GetRegexSubstitution () let retval = input( "regex control character replacements (current = '".g:Perl_PerlRegexSubstitution."'): " ) if strlen( retval ) == 2 let g:Perl_PerlRegexSubstitution = retval endif endfunction " ---------- end of function Perl_GetRegexSubstitution ---------- " "=== FUNCTION ================================================================ " NAME: Perl_InitializePerlInterface {{{1 " DESCRIPTION: initialize the Perl interface " PARAMETERS: - " RETURNS: "=============================================================================== function! Perl_InitializePerlInterface( ) if g:Perl_InterfaceInitialized == 'no' if has('perl') perl < :call Perl_SyntaxCheck() inoremap :call Perl_SyntaxCheck() " noremap :call Perl_Run() inoremap :call Perl_Run() " noremap :PerlScriptArguments inoremap :PerlScriptArguments " noremap :call Perl_perldoc() inoremap :call Perl_perldoc() endif " " ---------- plugin help ----------------------------------------------------- " noremap h :call Perl_perldoc() inoremap h :call Perl_perldoc() noremap hp :call Perl_HelpPerlsupport() inoremap hp :call Perl_HelpPerlsupport() " " ---------------------------------------------------------------------------- " Comments " ---------------------------------------------------------------------------- " noremap cl :call Perl_EndOfLineComment() inoremap cl :call Perl_EndOfLineComment() " nnoremap cj :call Perl_AlignLineEndComm() inoremap cj :call Perl_AlignLineEndComm() vnoremap cj :call Perl_AlignLineEndComm() nnoremap cs :call Perl_GetLineEndCommCol() nnoremap cc :call Perl_CommentToggle()j vnoremap cc :call Perl_CommentToggle()j nnoremap cb :call Perl_CommentBlock("a") inoremap cb :call Perl_CommentBlock("a") vnoremap cb :call Perl_CommentBlock("v") nnoremap cub :call Perl_UncommentBlock() " " ---------------------------------------------------------------------------- " Snippets & Templates " ---------------------------------------------------------------------------- " nnoremap nr :call Perl_CodeSnippet("read") nnoremap nw :call Perl_CodeSnippet("write") vnoremap nw :call Perl_CodeSnippet("writemarked") nnoremap ne :call Perl_CodeSnippet("edit") nnoremap nv :call Perl_CodeSnippet("view") " inoremap nr :call Perl_CodeSnippet("read") inoremap nw :call Perl_CodeSnippet("write") inoremap ne :call Perl_CodeSnippet("edit") inoremap nv :call Perl_CodeSnippet("view") " nnoremap ntl :call mmtemplates#core#EditTemplateFiles(g:Perl_Templates,-1) inoremap ntl :call mmtemplates#core#EditTemplateFiles(g:Perl_Templates,-1) if g:Perl_Installation == 'system' nnoremap ntg :call mmtemplates#core#EditTemplateFiles(g:Perl_Templates,0) inoremap ntg :call mmtemplates#core#EditTemplateFiles(g:Perl_Templates,0) endif nnoremap ntr :call mmtemplates#core#ReadTemplates(g:Perl_Templates,"reload","all") inoremap ntr :call mmtemplates#core#ReadTemplates(g:Perl_Templates,"reload","all") nnoremap nts :call mmtemplates#core#ChooseStyle(g:Perl_Templates,"!pick") inoremap nts :call mmtemplates#core#ChooseStyle(g:Perl_Templates,"!pick") " " " ---------------------------------------------------------------------------- " Regex " ---------------------------------------------------------------------------- " nnoremap xr :call perlsupportregex#Perl_RegexPick( "Regexp", "n" )j nnoremap xs :call perlsupportregex#Perl_RegexPick( "String", "n" )j nnoremap xf :call perlsupportregex#Perl_RegexPickFlag( "n" ) vnoremap xr :call perlsupportregex#Perl_RegexPick( "Regexp", "v" )'>j vnoremap xs :call perlsupportregex#Perl_RegexPick( "String", "v" )'>j vnoremap xf :call perlsupportregex#Perl_RegexPickFlag( "v" )'>j nnoremap xm :call perlsupportregex#Perl_RegexVisualize( ) nnoremap xmm :call perlsupportregex#Perl_RegexMatchSeveral( ) nnoremap xe :call perlsupportregex#Perl_RegexExplain( "n" ) vnoremap xe :call perlsupportregex#Perl_RegexExplain( "v" ) " " " ---------------------------------------------------------------------------- " POD " ---------------------------------------------------------------------------- " nnoremap pod :call Perl_PodCheck() nnoremap podh :call Perl_POD('html') nnoremap podm :call Perl_POD('man') nnoremap podt :call Perl_POD('text') " inoremap pod :call Perl_PodCheck() inoremap podh :call Perl_POD('html') inoremap podm :call Perl_POD('man') inoremap podt :call Perl_POD('text') " " ---------------------------------------------------------------------------- " Profiling " ---------------------------------------------------------------------------- " nnoremap rps :call perlsupportprofiling#Perl_Smallprof() inoremap rps :call perlsupportprofiling#Perl_Smallprof() nnoremap rpss :call perlsupportprofiling#Perl_SmallProfSortInput() inoremap rpss :call perlsupportprofiling#Perl_SmallProfSortInput() nnoremap rpf :call perlsupportprofiling#Perl_Fastprof() inoremap rpf :call perlsupportprofiling#Perl_Fastprof() nnoremap rpfs :call perlsupportprofiling#Perl_FastProfSortInput() inoremap rpfs :call perlsupportprofiling#Perl_FastProfSortInput() nnoremap rpn :call perlsupportprofiling#Perl_NYTprof() nnoremap rpnc :call perlsupportprofiling#Perl_NYTprofReadCSV("read","line") nnoremap rpns :call perlsupportprofiling#Perl_NYTProfSortInput() nnoremap rpnh :call perlsupportprofiling#Perl_NYTprofReadHtml() " inoremap rpn :call perlsupportprofiling#Perl_NYTprof() inoremap rpnc :call perlsupportprofiling#Perl_NYTprofReadCSV("read","line") inoremap rpns :call perlsupportprofiling#Perl_NYTProfSortInput() inoremap rpnh :call perlsupportprofiling#Perl_NYTprofReadHtml() " " ---------------------------------------------------------------------------- " Run " ---------------------------------------------------------------------------- " noremap rr :call Perl_Run() noremap rs :call Perl_SyntaxCheck() noremap ra :PerlScriptArguments noremap rw :PerlSwitches " inoremap rr :call Perl_Run() inoremap rs :call Perl_SyntaxCheck() inoremap ra :PerlScriptArguments inoremap rw :PerlSwitches " noremap rd :call Perl_Debugger() noremap :call Perl_Debugger() inoremap :call Perl_Debugger() " if s:UNIX noremap re :call Perl_MakeScriptExecutable() inoremap re :call Perl_MakeScriptExecutable() endif " noremap ri :call Perl_perldoc_show_module_list() noremap rg :call Perl_perldoc_generate_module_list() " noremap ry :call Perl_Perltidy("n") vnoremap ry :call Perl_Perltidy("v") " noremap rpc :call Perl_Perlcritic() noremap rt :call Perl_SaveWithTimestamp() noremap rh :call Perl_Hardcopy("n") vnoremap rh :call Perl_Hardcopy("v") " noremap rk :call Perl_Settings() " inoremap ri :call Perl_perldoc_show_module_list() inoremap rg :call Perl_perldoc_generate_module_list() inoremap ry :call Perl_Perltidy("n") inoremap rpc :call Perl_Perlcritic() inoremap rt :call Perl_SaveWithTimestamp() inoremap rh :call Perl_Hardcopy("n") inoremap rk :call Perl_Settings() " if has("gui_running") && s:UNIX noremap rx :call Perl_XtermSize() inoremap rx :call Perl_XtermSize() endif " noremap ro :call Perl_Toggle_Gvim_Xterm() inoremap ro :call Perl_Toggle_Gvim_Xterm() " noremap rpcs :call Perl_PerlcriticSeverityInput() noremap rpcv :call Perl_PerlcriticVerbosityInput() noremap rpco :call Perl_PerlcriticOptionsInput() " " ---------------------------------------------------------------------------- " if !exists("g:Perl_Ctrl_j") || ( exists("g:Perl_Ctrl_j") && g:Perl_Ctrl_j != 'off' ) nnoremap i=Perl_JumpCtrlJ() inoremap =Perl_JumpCtrlJ() endif " "------------------------------------------------------------------------------- " tool box "------------------------------------------------------------------------------- " if s:Perl_UseToolbox == 'yes' call mmtoolbox#tools#AddMaps ( s:Perl_Toolbox ) endif " "------------------------------------------------------------------------------- " settings - reset local leader "------------------------------------------------------------------------------- if ! empty ( g:Perl_MapLeader ) if exists ( 'll_save' ) let g:maplocalleader = ll_save else unlet g:maplocalleader endif endif " " ---------------------------------------------------------------------------- " Generate (possibly exuberant) Ctags style tags for Perl sourcecode. " Controlled by g:Perl_PerlTags, disabled by default. " ---------------------------------------------------------------------------- if has('perl') && exists("g:Perl_PerlTags") && g:Perl_PerlTags == 'on' if ! exists("s:defined_functions") function s:init_tags() perl < $ENV{PERL_LOCAL_INSTALLATION}; eval { require Perl::Tags::Naive }; if ( $@ ) { # Perl::Tags::Naive not loadable VIM::DoCommand("let g:Perl_PerlTags = 'off'" ); } else { $naive_tagger = Perl::Tags::Naive->new( max_level=>2 ); } EOF endfunction " let vim do the tempfile cleanup and protection let s:tagfile = tempname() call s:init_tags() " only the first time let s:defined_functions = 1 endif call Perl_do_tags( expand('%'), s:tagfile ) augroup perltags au! autocmd BufRead,BufWritePost *.pm,*.pl call Perl_do_tags(expand('%'), s:tagfile) augroup END endif " endfunction " ---------- end of function s:CreateAdditionalMaps ---------- "=============================================================================== " " Plug-in setup: {{{1 " "------------------------------------------------------------------------------ " setup the toolbox "------------------------------------------------------------------------------ " if s:Perl_UseToolbox == 'yes' " let s:Perl_Toolbox = mmtoolbox#tools#NewToolbox ( 'Perl' ) call mmtoolbox#tools#Property ( s:Perl_Toolbox, 'mapleader', g:Perl_MapLeader ) " call mmtoolbox#tools#Load ( s:Perl_Toolbox, s:Perl_ToolboxDir ) " " debugging only: "call mmtoolbox#tools#Info ( s:Perl_Toolbox ) " endif " call Perl_ToolMenu() if s:Perl_LoadMenus == 'yes' && s:Perl_CreateMenusDelayed == 'no' call Perl_CreateGuiMenus() endif "------------------------------------------------------------------------------ " Automated header insertion "------------------------------------------------------------------------------ if has("autocmd") " autocmd FileType * \ if ( &filetype == 'perl' || &filetype == 'pod') | \ if ! exists( 'g:Perl_Templates' ) | \ if s:Perl_LoadMenus == 'yes' | call Perl_CreateGuiMenus () | \ else | call s:Perl_RereadTemplates ('no') | \ endif | \ endif | \ call s:CreateAdditionalMaps() | \ call mmtemplates#core#CreateMaps ( 'g:Perl_Templates', g:Perl_MapLeader ) | \ endif " autocmd BufNewFile,BufRead *.pod setlocal syntax=perl autocmd BufNewFile,BufRead *.t setlocal filetype=perl " if s:Perl_InsertFileHeader == 'yes' autocmd BufNewFile *.pl call mmtemplates#core#InsertTemplate(g:Perl_Templates, 'Comments.file description pl') autocmd BufNewFile *.pm call mmtemplates#core#InsertTemplate(g:Perl_Templates, 'Comments.file description pm') autocmd BufNewFile *.t call mmtemplates#core#InsertTemplate(g:Perl_Templates, 'Comments.file description t') endif autocmd BufNew *.pl,*.pm,*.t,*.pod call Perl_InitializePerlInterface() autocmd BufRead *.pl,*.pm,*.t,*.pod call Perl_HighlightJumpTargets() " " Wrap error descriptions in the quickfix window. autocmd BufReadPost quickfix setlocal wrap | setlocal linebreak " exe 'autocmd BufNewFile,BufReadPost '.s:Perl_PerlModuleList.' setlocal foldmethod=expr | setlocal foldexpr=Perl_ModuleListFold(v:lnum)' " endif " " vim: tabstop=2 shiftwidth=2 foldmethod=marker