mojo.vim icon indicating copy to clipboard operation
mojo.vim copied to clipboard

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

Open ghost opened this issue 11 years ago • 6 comments

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;

ghost avatar Oct 27 '12 21:10 ghost

@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

yko avatar Oct 28 '12 12:10 yko

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

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

rshadow avatar Sep 30 '13 14:09 rshadow

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

Thank you

yko avatar Sep 30 '13 15:09 yko

@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

yko avatar Sep 30 '13 17:09 yko

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.

jberger avatar Jan 17 '17 22:01 jberger

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 <[email protected]>
 
-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.

hoelzro avatar Oct 24 '17 13:10 hoelzro