Incorrect syntax highlight of things like '\r' within EOF block in bash script

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Incorrect syntax highlight of things like '\r' within EOF block in bash script

Peng Yu
Hi,

vim can not syntax highlight the following script correctly. Does
anybody know a better highlight plugin that can correct highlight it?
Thanks.

~/linux/test/latex/tex/bin$ cat main.sh
#!/usr/bin/env bash

tex <<EOF
\relax
Hello?
\end
EOF

--
Regards,
Peng

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.


Reply | Threaded
Open this post in threaded view
|

Re: Incorrect syntax highlight of things like '\r' within EOF block in bash script

Adnan Zafar
On Wed, Jul 17, 2013 at 4:02 PM, Peng Yu <[hidden email]> wrote:

> Hi,
>
> vim can not syntax highlight the following script correctly. Does
> anybody know a better highlight plugin that can correct highlight it?
> Thanks.
>
> ~/linux/test/latex/tex/bin$ cat main.sh
> #!/usr/bin/env bash
>
> tex <<EOF
> \relax
> Hello?
> \end
> EOF
>
> --
> Regards,
> Peng

Inside of heredocs, bash (and other shells) can do certain expansions
and substutions, so the Vim syntax highlights for those. However if
the delimiter word (here EOF) is quoted in some way, like \EOF then
those expansions and substitutions are disabled, and Vim's syntax
adjusts accordingly.

In short either escape backslashes inside the heredoc or simply use

tex << \EOF
\relax
Hello?
\end
EOF

--Adnan

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.


Reply | Threaded
Open this post in threaded view
|

Re: Incorrect syntax highlight of things like '\r' within EOF block in bash script

Peng Yu
On Wed, Jul 17, 2013 at 3:09 PM, Adnan Zafar <[hidden email]> wrote:

> On Wed, Jul 17, 2013 at 4:02 PM, Peng Yu <[hidden email]> wrote:
>> Hi,
>>
>> vim can not syntax highlight the following script correctly. Does
>> anybody know a better highlight plugin that can correct highlight it?
>> Thanks.
>>
>> ~/linux/test/latex/tex/bin$ cat main.sh
>> #!/usr/bin/env bash
>>
>> tex <<EOF
>> \relax
>> Hello?
>> \end
>> EOF
>>
>> --
>> Regards,
>> Peng
>
> Inside of heredocs, bash (and other shells) can do certain expansions
> and substutions, so the Vim syntax highlights for those. However if
> the delimiter word (here EOF) is quoted in some way, like \EOF then
> those expansions and substitutions are disabled, and Vim's syntax
> adjusts accordingly.
>
> In short either escape backslashes inside the heredoc or simply use
>
> tex << \EOF
> \relax
> Hello?
> \end
> EOF

The following is the document from bash. I don't see the usage of
\EOF. Do you know where it is documented? I tried both \EOF and EOF,
both of them generate the same dvi file. So it seems \r and \e are
take literally by tex (i.e., a backslash and 'r', a backslash and
'e'). Is it so?

   Here Documents
       This type of redirection instructs the shell to  read  input  from  the
       current source until a line containing only delimiter (with no trailing
       blanks) is seen.  All of the lines read up to that point are then  used
       as the standard input for a command.

       The format of here-documents is:

              <<[-]word
                      here-document
              delimiter

       No  parameter expansion, command substitution, arithmetic expansion, or
       pathname expansion is performed on word.  If any characters in word are
       quoted,  the  delimiter is the result of quote removal on word, and the
       lines in the here-document are not expanded.  If word is unquoted,  all
       lines  of  the here-document are subjected to parameter expansion, com-
       mand substitution, and arithmetic expansion.  In the latter  case,  the
       character  sequence  \<newline> is ignored, and \ must be used to quote
       the characters \, $, and `.

       If the redirection operator is <<-, then all leading tab characters are
       stripped  from  input  lines  and  the line containing delimiter.  This
       allows here-documents within shell scripts to be indented in a  natural
       fashion.


--
Regards,
Peng

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.


Reply | Threaded
Open this post in threaded view
|

Re: Incorrect syntax highlight of things like '\r' within EOF block in bash script

Gary Johnson-4
In reply to this post by Adnan Zafar
On 2013-07-17, Adnan Zafar wrote:

> On Wed, Jul 17, 2013 at 4:02 PM, Peng Yu wrote:
> > Hi,
> >
> > vim can not syntax highlight the following script correctly. Does
> > anybody know a better highlight plugin that can correct highlight it?
> > Thanks.
> >
> > ~/linux/test/latex/tex/bin$ cat main.sh
> > #!/usr/bin/env bash
> >
> > tex <<EOF
> > \relax
> > Hello?
> > \end
> > EOF
> >
> > --
> > Regards,
> > Peng
>
> Inside of heredocs, bash (and other shells) can do certain expansions
> and substutions, so the Vim syntax highlights for those. However if
> the delimiter word (here EOF) is quoted in some way, like \EOF then
> those expansions and substitutions are disabled, and Vim's syntax
> adjusts accordingly.
>
> In short either escape backslashes inside the heredoc or simply use
>
> tex << \EOF
> \relax
> Hello?
> \end
> EOF

Except that bash does not expand \r or \e in Peng's context.


$ od -bc <<EOF
\relax
Hello?
\end
EOF

0000000 134 162 145 154 141 170 012 110 145 154 154 157 077 012 134 145
          \   r   e   l   a   x  \n   H   e   l   l   o   ?  \n   \   e
0000020 156 144 012
          n   d  \n
0000023


Regards,
Gary

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.


Reply | Threaded
Open this post in threaded view
|

Re: Incorrect syntax highlight of things like '\r' within EOF block in bash script

Adnan Zafar
In reply to this post by Peng Yu
On Wed, Jul 17, 2013 at 4:22 PM, Peng Yu <[hidden email]> wrote:

> On Wed, Jul 17, 2013 at 3:09 PM, Adnan Zafar <[hidden email]> wrote:
>> On Wed, Jul 17, 2013 at 4:02 PM, Peng Yu <[hidden email]> wrote:
>>> Hi,
>>>
>>> vim can not syntax highlight the following script correctly. Does
>>> anybody know a better highlight plugin that can correct highlight it?
>>> Thanks.
>>>
>>> ~/linux/test/latex/tex/bin$ cat main.sh
>>> #!/usr/bin/env bash
>>>
>>> tex <<EOF
>>> \relax
>>> Hello?
>>> \end
>>> EOF
>>>
>>> --
>>> Regards,
>>> Peng
>>
>> Inside of heredocs, bash (and other shells) can do certain expansions
>> and substutions, so the Vim syntax highlights for those. However if
>> the delimiter word (here EOF) is quoted in some way, like \EOF then
>> those expansions and substitutions are disabled, and Vim's syntax
>> adjusts accordingly.
>>
>> In short either escape backslashes inside the heredoc or simply use
>>
>> tex << \EOF
>> \relax
>> Hello?
>> \end
>> EOF
>
> The following is the document from bash. I don't see the usage of
> \EOF. Do you know where it is documented? I tried both \EOF and EOF,
> both of them generate the same dvi file. So it seems \r and \e are
> take literally by tex (i.e., a backslash and 'r', a backslash and
> 'e'). Is it so?

The use of \EOF is mentioned in the following paragraph, specifically
"If any characters in word are quoted". Although the docs says that
backslashes must be escaped if the word is unquoted, I guess bash
leaves them alone in some circumstances The way Vim's syntax works
will cause the escape sequences to be highlighted unless you quote a
character in the word though, and Vim's syntax seems to only recognize
when the first character is quoted.

>        No  parameter expansion, command substitution, arithmetic expansion, or
>        pathname expansion is performed on word.  If any characters in word are
>        quoted,  the  delimiter is the result of quote removal on word, and the
>        lines in the here-document are not expanded.  If word is unquoted,  all
>        lines  of  the here-document are subjected to parameter expansion, com-
>        mand substitution, and arithmetic expansion.  In the latter  case,  the
>        character  sequence  \<newline> is ignored, and \ must be used to quote
>        the characters \, $, and `.

--Adnan

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.


Reply | Threaded
Open this post in threaded view
|

Re: Incorrect syntax highlight of things like '\r' within EOF block in bash script

John Little-4
In reply to this post by Peng Yu
On Thursday, 18 July 2013 08:02:02 UTC+12, Peng Yu  wrote:
>
> vim can not syntax highlight the following script correctly...

Are you asking how to apply tex syntax highlighting to a script embedded in a bash script?  Perhaps:

http://vim.wikia.com/wiki/Different_syntax_highlighting_within_regions_of_a_file

can help, or, more likely, the TeX and LaTex people will help; I suggest putting "TeX" in the subject would have been a good idea.

Regards, John Little

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.


Reply | Threaded
Open this post in threaded view
|

Re: Incorrect syntax highlight of things like '\r' within EOF block in bash script

Charles E Campbell Jr
In reply to this post by Peng Yu
Peng Yu wrote:
> Hi,
>
> vim can not syntax highlight the following script correctly. Does
> anybody know a better highlight plugin that can correct highlight it?
>
May I suggest that you..

Read  :help sh-embed

Modify the example to do LaTeX:

" TEX Embedding: {{{1
" ==============
" Shamelessly ripped from aspperl.vim by Aaron Hope.
if exists("b:current_syntax")
   unlet b:current_syntax
endif
syn include @TEXScript syntax/tex.vim
syn region TEXScriptCode matchgroup=TEXCommand start=+[=\\]\@<!'+
skip=+\\'+ end=+'+ contains=@TEXScript contained
syn region TEXScriptEmbedded matchgroup=TEXCommand start=+\<tex\>+
skip=+\\$+ end=+[=\\]\@<!'+me=e-1 contains=@shIdList,@shExprList2
nextgroup=TEXScriptCode
syn cluster shCommandSubList add=TEXScriptEmbedded
hi def link TEXCommand Type
syn region shHereDoc matchgroup=shRedir20 start="<<\s*\\\=\z([^
\t|]*\)"        matchgroup=shRedir20 end="^\z1\s*$"    
contains=@shDblQuoteList,@TEXScript

I identified which shHereDoc to recognize (ie. the one with shRedir20)
by using :HLT! and moving the cursor into the block. :HLT is provided
courtesy of my hilinks.vim plugin, available at my website as:
   http://www.drchip.org/astronaut/vim/index.html#HILINKS

Regards,
Chip Campbell

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.


Reply | Threaded
Open this post in threaded view
|

Re: Incorrect syntax highlight of things like '\r' within EOF block in bash script

Gary Johnson-4
In reply to this post by John Little-4
On 2013-07-18, John Little wrote:
> On Thursday, 18 July 2013 08:02:02 UTC+12, Peng Yu  wrote:
> >
> > vim can not syntax highlight the following script correctly...
>
> Are you asking how to apply tex syntax highlighting to a script
> embedded in a bash script?

That's not the problem, as I understand it.  The problem is that Vim
incorrectly highlights the "\r" and the "\e" differently than the
rest of the here document, suggesting that bash treats them
differently, perhaps as carriage-return and escape, when in fact
bash does not treat those pairs differently than the individual
characters they comprise.

Regards,
Gary

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/groups/opt_out.