Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code between { } of a map/grep doesn't get hilighted #7

Open
ghost opened this issue Oct 27, 2012 · 6 comments
Open

Code between { } of a map/grep doesn't get hilighted #7

ghost opened this issue Oct 27, 2012 · 6 comments

Comments

@ghost
Copy link

ghost commented Oct 27, 2012

Anything between map/grep's curly brackets is not properly hilighted (no colour at all).
E.g.: grep { /$this_does_not_get_hilighted/i } @array;

@yko
Copy link
Owner

yko commented Oct 28, 2012

@emanrsu thanks for this report.
I think this was a compromise, or you may call it a workaround, I did long time ago solving some problems with double-included perl.vim syntax file.

At the moment you have to choose between highlighted DATA content for Mojolicious apps and highlighted grep/map blocks.

You may find the following line in your .vimrc:

let mojo_highlight_data = 1 

And remove it. DATA section won't be highlighted anymore, but grep/map blocks would.

If this really annoys you, feel free to investigate and fix it.
Otherwise I'll take look at it closer when I have some free time.
Hovewer, it doesn't likely to happen in this century.

Luck

@rshadow
Copy link

rshadow commented Sep 30, 2013

This code in test.hrml.ep not proper highlighted too:

% if(1) {
 <tr class="<%= join ' ', @class %>" >
            <td>
% }

@yko
Copy link
Owner

yko commented Sep 30, 2013

@rshadow that's not related to #7
Feel free to open a separate issue (or I'll do it later myself)

Thank you

@yko
Copy link
Owner

yko commented Sep 30, 2013

@rshadow

  1. Are you using mojo.vim from trunk?
  2. Are you using vim-solarized color scheme? If yes, please try with latest solarized.
    Thanks

@jberger
Copy link

jberger commented Jan 17, 2017

I experience a seemingly related problem (and I assume so because removing the mojo_highlight_data fixes it). The problem is seen in pure perl code (i.e. before the __DATA__ section, not in a template) especially around constructs like %{ $href_or_undef || {} }. In this case the last closing curly brace seems to be ignored for highlighting purposes; it isn't highlighted itself and the highlighter seems to have missed that the block has ended. The problem persists for the remainder of the file.

screen shot 2017-01-17 at 4 30 13 pm

As seen in the picture, the first method is fine, the second has the problem curly braces (twice actually though once is enough), and the third method continues with broken highlighting.

@hoelzro
Copy link

hoelzro commented Oct 24, 2017

I did some tinkering about with this last night and this morning - I managed to generate the following patch to solve the issue on a stupid little Mojolicious::Lite example:

diff --git after/syntax/perl/MojoliciousLite.vim after/syntax/perl/MojoliciousLite.vim
index e1748e0..6ac761d 100644
--- after/syntax/perl/MojoliciousLite.vim
+++ after/syntax/perl/MojoliciousLite.vim
@@ -21,15 +21,6 @@ if !exists("mojo_highlight_data")
     finish
 endif
 
-if !exists("b:current_syntax")
-  echoerr "MojolisiousTemplate can only be included in existing syntax"
-  finish
-endif
-
-" Store current syntax name
-let cs = b:current_syntax
-unlet b:current_syntax
-
 if !exists("mojo_disable_html")
   unlet! b:current_syntax
   syn include @Html syntax/html.vim
@@ -45,6 +36,3 @@ syn region MojoFileName start=/@@/ end="$" keepend contains=MojoFileNameStart co
 
 " Push Template sections and HTML syntax into @perlDATA cluster
 syn cluster perlDATA add=@Html,MojoFileContainer
-
-" Revert current syntax name
-let b:current_syntax = cs
diff --git syntax/epl.vim syntax/epl.vim
index 4d69546..9534e53 100644
--- syntax/epl.vim
+++ syntax/epl.vim
@@ -7,25 +7,9 @@
 " License:     Artistic 2.0
 " Original version: vti <vti@cpan.org>
 
-if exists("perl_fold")
-   let b:bfold = perl_fold
-   unlet perl_fold
-endif
-
 " Clear previous syntax name
 unlet! b:current_syntax
 
-" Include Perl syntax intp @Perl cluster
-syntax include @Perl syntax/perl.vim
-
-" This groups are broken when included
-syn cluster Perl remove=perlFunctionName,perlElseIfError
-
-if exists("b:bfold")
-    let perl_fold = b:bfold
-    unlet b:bfold
-endif
-
 " Begin and end of code blocks
 syn match MojoStart /<%=\{0,2}/ contained
 syn match MojoSingleStart /^\s*%=\{0,2}/  contained
@@ -34,8 +18,8 @@ syn match MojoEnd /=\{0,1}%>/ contained
 syn cluster Mojo contains=MojoStart,MojoEnd
 
 " Highlight code blocks
-syn region PerlInside keepend start=+<%=\{0,2}+hs=s end=+=\{0,1}%>+he=s-1,me=s-1 contains=MojoStart,@Perl nextgroup=MojoEnd
-syn region PerlInside keepend start=+^\s*%=\{0,2}+hs=s end=+$+ contains=MojoSingleStart,@Perl
+syn region PerlInside keepend start=+<%=\{0,2}+hs=s end=+=\{0,1}%>+he=s-1,me=s-1 contains=MojoStart,@perlTop nextgroup=MojoEnd
+syn region PerlInside keepend start=+^\s*%=\{0,2}+hs=s end=+$+ contains=MojoSingleStart,@perlTop
 
 if !exists("mojo_no_helpers")

Please give this a try and let me know if it works for other, larger codebases!

I think the problem was because all the action is happening in an after/ file, which then loads a syntax file that reloads syntax/perl.vim, and Vim gets super confused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants