vim syntax highlighting is messed up after non-standard delimiters in Perl's s/// - perl

When I have something like s#hello#bye#; in my Perl script vim's syntax highlighting is messed up after that line. It only works correctly if I use / as the delimiter, as in s/hello/bye/;. Does anyone know if/how I can fix this?
Thanks a lot in advance for your replies.

My Debian packaged vim 7.1 highlights OK with s#foo#bar#g. The Debian package does not contain vim's perl-specific features.
Also, no problem with RHEL vim 7.0 which has perl features enabled.
I remember seeing this problem with syntax highlighing some time back, so it might be your vim version and/or perl syntax highlighting rules.

"The only thing that can parse Perl is perl."
But seriously, Perl has a massively irregular grammar and it's not surprising that it confuses some syntax highlighters. The most successful one I've seen is CPerl mode for Emacs. But I guess that's not particularly useful for a Vim user.

Related

vim: Interactive search and replace with perl compatible regular expressions

According to this page you can use perl compatible regular expression with
:perldo s/pattern/insert/g.
This works fine.
But, how can I get interactive search and replace with PCRE syntax in vim?
Since this does not work with perldo I search for a different solution.
Till the current release version of vim, there is no way to do :s/[perlRegex]/bar/c
So you are asking for a feature that doesn't exist.
You can do matching with verymagic, however it is not Perl Regex compatible flag. It is still using the vimregex engine, just changed the way of escaping regex patterns.
For example, in perl, you can do lookahead/behind (?<=foo)..., (?=foo), (?!foo).., you can use the handy \K : som.*ing\Kwhatever etc, you cannot use those syntax in vim directly, no matter which 'magic' level you have set. Vim has the same feature, but different syntax:
\#=
\#!
\#<=
and also the \zs \ze are very handy, even more powerful than perl's \K.
Vim is an Editor, with vim regex, you can not only do text matching, but also match base on visual selection, cursor position and so on.
If you really need to do complex pattern matching and really need do them in vim, learn vim regex! It is not difficult for you if you "know pcre very well"
Probably the closest you can get is:
:s/\vfoo/bar/gc
I suggest to try eregex plugin. It maps perl compatible regular expressions to VIM regex syntax.
In your example, s/pattern/insert/g is a perl command, not a Vim command using a perl-compatible regular expression syntax.
If perl doesn't have an equivalent of Vim's /c flag you will need to find an alternate method likeā€¦ writing an actual perl script.

Is it possible to highlight interpolated perl variables in emacs?

Recently I've started using emacs and after overcoming a number of hurdles in making cperl-mode operate in a way that is agreeable I've become stumped by this problem. Currently I have all scalars in regular use being highlighted except for where they are interpolated. Is such syntax highlighting possible under this mode? Currently I'm using emacs 23.1 and jrockway's cperl-mode 5.23
Thanks
It won't highlight interpolated variables in strings, but it will do it in regular expressions. I'll bet that could be adapted by somebody who knows elisp.

What text editor does most accurate job of syntax highlighting Perl

I know I risk asking a speculative question, however, inspired by this recent question I wonder which editor does the best job of syntax highlighting Perl. Being well aware of the difficulties (impossibilities) of parsing Perl I know there will not be a perfect case. Still I wonder if there is a clear leader in faithful representation.
N.B. I use gedit and it works fine, but with known issues.
Komodo Edit does a good job and also scans your modules (including those installed via CPAN) and does well at generating autocomplete data for them.
I'm a loyal vim user and rarely encounter anything odd with the native syntax.vim, except for these cases (I'll edit in more if/when I find them; others please feel free also):
!!expression is better written !!!!expression (everything after two ! is rendered as a comment quoted string; four ! brings everything back to normal)
m## or s### renders everything after the # as a comment; I usually use {} as a delimiter when avoiding / for leaning toothpick syndrome
some edge cases for $hash{key} where key is not a simple alphanumeric string - although it's safer to enclose such key names in '' anyway so as to not have to look up the exact cases for when a bareword is treated as a key name
I haven't used it, but Padre should be good since it's written in Perl. IIRC It uses PPI for parsing
jEdit...with the tweaks that I have amassed over the years. It's got the most customizable syntax highlighting I've ever seen.
I use Emacs in CPerl mode. I think it does a terrific job, although similar to Ether's answer, it's not perfect. What's more, I usually use Htmlize to publish highlighted code to the web. It's kind of annoying to use fancier forums like this one that do their own syntax highlighting, since it's not really any easier and the results aren't as good.

Is there a Perl Syntax Highlighter (outputting to HTML) like PHP's GeSHi?

Most PHP Developers are likely familar with the Syntax Highlighter called "GeSHi", which takes code, highlights it, with the use of HTML and CSS:
include('geshi.php');
$source = 'echo "hello, world!";
$language = 'php';
$path = 'geshi/';
$geshi = new GeSHi($source, $language, $path);
echo $geshi->parse_code();
GeSHi Supports a wide range of languages.
I wonder, is there a similar Module for Perl?
Perl has a port of Kate highlighting system: Syntax::Highlight::Engine::Kate which seems to be somewhat close to what you need. It appears to be part of Padre.
You also have an option of HTML client side highlighters (logic is obviously JS), such as Google's code prettifyer
Two good lists of syntax highlighting engines are:
Wiki syntax highlighting article - among the ones it lists, the Perl ports/APIs seem to exist for Kate and Colorer (Syntax::Highlight::Universal)
This very good review of HTML syntax highlighters, which contains a lot of client-side ones such as SHJS and many others.
Please be aware that NONE of those generic highlighters work "100% correctly", the way the syntax highlighters work in good IDEs, because they use regular expressions for approximate parsing instead of lexers for actual language grammar parsing. More details on the Wiki
You can also consider this for client side syntax highlighting.
http://alexgorbatchev.com/SyntaxHighlighter/
I have had some very good results with the PPI::HTML package. It uses PPI to parse the Perl before converting the text to HTML.
Pure Perl: Syntax::Highlight::Engine::Kate (there is Kate plugin for Padre IDE).
Wrappers for C libraries: Syntax::Highlight::Universal, Syntax::SourceHighlight.
Using external tools: Text::VimColor, Text::EmacsColor.
Also there are many one-language highlighters on CPAN.
You can always write a small php script to make GeSHi usable from command line and then call it within your perl script.
I did this for gitweb so I could leave svn (and websvn) behind for good.
My search brought me here, because I was looking for a 'Perl Syntax Highlighter' like the title said and not an general highlighter implemented in Perl.
To highlight only Perl, perltidy --html can be used. It belongs to the Perl::Tidy distribution the main module can be imported and used without spawning a process.
https://metacpan.org/dist/Perl-Tidy/view/bin/perltidy#HTML-OPTIONS
So not what the OP actually wanted to know, but hopefully of help for others coming here for the same reasons like me ... :)

How to ignore comments in the LaTeX file with ispell (within Emacs if possible)

I'm writing a text with Latex in English but written my comments in Finnish. When I'm running the spell checking with ispell, I got to run through all the comments. Is there a handy way to skip the comments with the ispell? If that could be done with emacs, that would be double handy =)
One way would be to run the ispell within console and process the input with sed, for example, but I'd like to have my changes straight on the file...
(setq ispell-check-comments nil)
You'd have to dig in the code a bit, but when you spell-check a file, it's running the detex tool to strip out the TeX code. You should be able to modify the pipeline to have a sed or perl script strip the comment lines.
I kind of vaguely think AuC-TeX makes this configurable, but 30 seconds looking didn't reveal it.
Adding a modern answer to this old question, because I also had the problem:
Just use aspell, which does this out of the box.