Created
June 5, 2012 14:58
-
-
Save somian/2875504 to your computer and use it in GitHub Desktop.
Trace execution of (eval'd) perl code in Vim scripts we write
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" First created: 2012-06-05 UTC-04:00 | |
" Last modified: 2012-06-05T10:54:59 UTC-04:00 | |
if str2nr(v:version) < 700 |finish|endi | |
let s:base_sfile = fnamemodify(expand('<sfile>'), ':t') | |
let s:ltest = 'g:loaded_' .tolower(fnamemodify(expand('<sfile>'), ':p:t:r')) | |
if exists(s:ltest) | |
unlet s:ltest | |
" finish for ordinary plugins only. | |
endi | |
funct! s:BabyGotMods() | |
let b:perlisok = '' | |
if has('perl') | |
perl << EOHEREDOC | |
BEGIN { use FindBin q[$RealScript]; } | |
%::all_ok = ( | |
'File::Spec::Unix' => eval q(require File::Spec::Unix) && !$@, | |
'Path::Class' => eval q(require Path::Class) && !$@, | |
'File::Save::Home' => eval q(require File::Save::Home) && !$@, | |
# 'No::Such::Module' => eval q(require No::Such::Module) && !$@, # | |
); | |
my @valsucc = VIM::DoCommand('let b:perlisok = '. 1 * (!grep { ! $_ } values %all_ok)); | |
EOHEREDOC | |
endi | |
return b:perlisok | |
endfu | |
funct! s:PerlFReport() | |
let outstr = '' | |
perl << DONENOW | |
use Data::Dumper ('Dumper'); | |
my $dump = join q[ ]=> (split /\s+/,Dumper( \%::all_ok )); | |
$dump =~s{'} {}g; # ' | |
$dump =~s# \s*[{}]\s* ##xg; | |
$dump = substr($dump, 7); | |
VIM::DoCommand(q[let outstr = ']. "\n".$dump .q[']); | |
DONENOW | |
return outstr | |
endfu | |
funct! s:PerlVReport() | |
let outstr = '' | |
perl << DONENOW | |
VIM::DoCommand(q[let outstr = ']. substr($^V,1) .q[']); | |
DONENOW | |
return outstr | |
endfu | |
funct! s:PerlSReport() | |
let outstr = '' | |
perl << DONENOW | |
VIM::DoCommand( q/let l:vval = expand('<sfile>')/ ); | |
# "function <SNR>\n\n_" ...might need to use a regexp subst instead. | |
my $vfunctn = substr VIM::Eval( 'l:vval' ), 17; | |
my $vscript = VIM::Eval( 's:base_sfile' ); # Line 5 | |
my $fmsg = sprintf( 'function "%s" in file "%s"'=> $vfunctn,$vscript ); | |
VIM::DoCommand(q[let outstr = ']. $fmsg .q[']); | |
DONENOW | |
return outstr | |
endfu | |
funct! s:PerlTReport() | |
let outstr = '' | |
perl << DONENOW | |
my $fmsg = sprintf( 'from package "%s" in file "%s" at line "%u"'=> caller ); | |
VIM::DoCommand(q[let outstr = ']. $fmsg .q[']); | |
DONENOW | |
return outstr | |
endfu | |
if ! s:BabyGotMods() | |
call confirm( | |
\ printf( | |
\ 'We are aborting: Perl "%s" running %s was unable to "require()' . | |
\ "one or more files:%s\n ...Perl saw called code %s\n", | |
\ s:PerlVReport(), s:PerlSReport(), s:PerlFReport(), s:PerlTReport() | |
\ ), 'Ok', 'Ok', 'Warning') | |
finish | |
else | |
call confirm( | |
\ printf( | |
\ 'We are ok: Perl "%s" running code in %s was able to load' . | |
\ "one or more files:%s\n ...Perl saw called code %s\n", | |
\ s:PerlVReport(), s:PerlSReport(), s:PerlFReport(), s:PerlTReport() | |
\ ), 'Ok', 'Ok', 'Info') | |
endi | |
" Author: Sören Andersen | |
" FileName: PerlCodeBeduggin.vim |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment