WolfgangMehner / vim-plugins

Vim plug-ins which offer support for various programming languages.
415 stars 96 forks source link

Perl-Support: Improved setup to work with Perlbrew #11

Open glasswalk3r opened 10 years ago

glasswalk3r commented 10 years ago

This is actually a suggestion for improvement.

While using Perlbrew, it would be much better to have the following code in the .vimrc:

" Enable perlbrew path
if has("gui_running") && filereadable($HOME . "/perl5/perlbrew/etc/bashrc")
  let $PATH=system("source " . $HOME . "/perl5/perlbrew/etc/bashrc; echo -n PATH")
endif

This will allow the plugin to identify the correct version of perl as defined by the Perlbrew configuration and, of course, correct identify issues and a syntax check is carried, since different Perlbrew instances may have different Perl modules installed.

glasswalk3r commented 10 years ago

Although this configuration solves the issue regarding the Perl interpreter and @INC configuration, when I used the \rs (check syntax) command I always got something that is missing in the current @INC, for example:

ListEvtLogLvl.pm|3| Can't locate Moose.pm in @INC (@INC contains: /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl /usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/5.8.8 .)
ListEvtLogLvl.pm|3| BEGIN failed--compilation aborted

Since I'm using Perl 5.16, this configuration is wrong. I doubled checked the @INC configuration with this in the .vimrc:

if has("gui_running") && filereadable($HOME . "/perl5/perlbrew/etc/bashrc")
    let $PATH=system("source " . $HOME . "/perl5/perlbrew/etc/bashrc; echo -n $PATH")
    let $test=system("perl -E 'foreach(@INC) { say $_ }'")
    echo $test
endif

And the dialog box showed the correct configuration.

Reviewing the perl-support.vim plugin, I found that the Perl interpreter path being used in hard coded to "/usr/bin/perl" but that does not help with Perlbrew. I added the following (line number included):

 162   let s:Perl_Perl                 = system("/usr/bin/which perl")
 163   let s:Perl_Perl                 = substitute(s:Perl_Perl, '\n$', '', '')

And it seems to be working correctly now when checking syntax,

WolfgangMehner commented 10 years ago

You can actually set the Perl executable in your .vimrc using "g:Perl_Perl", see:

:help perlsupport-perl6

glasswalk3r commented 6 years ago

For some reason that help is not available:

E149: Sorry, no help for perlsupport-perl6

I tried on a CentOS 7, with Vim 7.4.160.

WolfgangMehner commented 6 years ago

The help topic should still be there. But I renamed the setting to g:Perl_Executable.

Try using the map \hp or the menu entry Perl -> Help -> help (Perl-Support), it will generate the helptags for Perl-Support if they are not available.

g-i-o-r-g-i-o commented 6 years ago

This still works: let g:Perl_Executable = 'perl'

ubuntu 17.10 vim 8 perlbrew perl 5.26

WolfgangMehner commented 5 years ago

This is the default as of version 5.4.1, 132828c002d8120b2376f1024bf4d4b0aabee165 : let g:Perl_Executable = 'perl'

Hopefully this will resolve the perlbrew problems and always use the version you use in the shell, by actually choosing the correct executable from $PATH.

glasswalk3r commented 5 years ago

Tried that on Ubuntu 18.04, latest release of perl-support. Setting let g:Perl_Executable = 'perl' on ~/.vimrc works as expected, including for properly locating modules on custom @INC, but not for Gvim: even after repeating the configuration on ~/.gvimrc, the "selected" perl with Perlbrew doesn't work. Double checked by running !perl -v on [G]Vim command mode, and on Gvim the standard perl that comes with Ubuntu is used.

WolfgangMehner commented 5 years ago

OK, good debugging there. Unfortunatly it seems like the problem is not with Perl-Support itself, so it's harder for me to help you. Perl-Support depends on being able to run !perl -v correctly.

Could you compare the output of Vim vs. gVim when you run this on the Vim command line: :echo $PATH

Does it make a difference if you start gVim from a terminal or the desktop (using the Unity-App-Search-And-Starter-Thingy, whatever that's called)?

glasswalk3r commented 4 years ago

Sorry for taking so long to answer. Yes, it does make a difference. I tested calling from the Desktop, it doesn't work but if I open gVim from the terminal, it does work as expected. Tested on CentOS 7.