help-nano
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-nano] Bash syntax highlighting: Quoted text in comments


From: Benno Schulenberg
Subject: Re: [Help-nano] Bash syntax highlighting: Quoted text in comments
Date: Sun, 18 Feb 2018 11:11:30 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0

Hello Michael,

Op 17-02-18 om 04:29 schreef Michael Siegel:
> I've found that nano has kind of an annoying way of highlighting quoted
> text within comments in Bash scripts.
> 
> While the comments themselves are colored in cyan, quoted text within
> them will be given the standard string color, which is bright yellow.
> 
> For example, try this:
> 
>   #!/bin/bash
> 
>   # Let's see if this won't happen.
> 
> What you'll get is "# Let" in cyan, "'s see if this won'" in yellow and
> the rest in cyan again.
> 
> I suppose this is a known issue. Maybe it has already been fixed in
> versions newer than the one I'm using (2.7.4). If not, what's the
> problem and is someone trying to fix it?

Thanks for pointing this out.

In general, it cannot be fixed.  Nano does not do a full parse of the
script -- it simply uses regexes to color certain patterns.  This means
that either you get quoted things in comments highlighted as strings,
or you get the part of a string after " #" highlighted as a comment.
The first option has been chosen.

You could change the order of the Comments and Strings commands
("color cyan" and "color brightyellow") in /usr/share/nano/sh.nanorc.
But that has the disadvantage of getting overwritten upon the next
update of nano.

Better would be to add in your nanorc file:

  extendsyntax sh color cyan "(^|[[:space:]])#.*$"

That will make sure that comments are always colored in cyan.

But... maybe a point could be made that quotes in comments are more
common than space plus hash in strings?  What do you think?  Do you
have a large set of scripts that you can grep?

(I now see that the order of comment and string highlighting was
changed in the beginning of 2014, from nano-2.3.2 onwards.  Maybe
that swap should be turned back?)

Benno

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]