Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Enable nano syntax highlighting
View unanswered posts
View posts from last 24 hours

Goto page 1, 2, 3  Next  
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
wdreinhart
Guru
Guru


Joined: 11 Jun 2003
Posts: 569
Location: 4QFJ12345678

PostPosted: Thu Sep 18, 2003 11:00 pm    Post subject: Enable nano syntax highlighting Reply with quote

Not everyone knows it, but Gentoo's favorite edito, nano, supports syntax hilighting. To enable it, you will need to gunzip /usr/doc/nano-1.2.2/nanorc.sample.gz and name it "~/.nanorc". Then all you have to do is open it (in nano, of course!) and uncomment the syntax blocks for files you want to enable syntax hilighting in.

I have a very basic .ebuild syntax block here if anyone is interested in that. Please post udated versions if you improve on it.
Code:

 syntax "ebuild" "\.ebuild$"
 color brightcyan "^ *eclass\>" "^ *inherit\>"
 color brightwhite "^ *src [^ ]*"
 color brightblue "src_compile\>" "src_unpack\>" "src_install\>" "^ *einfo\>" "$ color yellow "^ *export\>"
 color magenta "\<(if|then|fi)\>"
 color green "#.*$"
Back to top
View user's profile Send private message
marshall_j
Tux's lil' helper
Tux's lil' helper


Joined: 22 Jan 2003
Posts: 98
Location: NZ

PostPosted: Fri Sep 19, 2003 1:24 am    Post subject: Reply with quote

This came up in a earlier thread but it started off about vim or something so I think lots of people could have missed it. Nano should come out of the box like this!

This is one that will just highlight all comments in blue. I find it handy for all the misc files just so you can see what should be edited and what should be read:
Code:

syntax "default" ".*"
color blue "^#.*"


Make sure you put it first if you add it to your nanorc file tho as the entries at the bottom overwrite the ones at the top.
Back to top
View user's profile Send private message
meowsqueak
Veteran
Veteran


Joined: 26 Aug 2003
Posts: 1549
Location: New Zealand

PostPosted: Fri Sep 19, 2003 2:08 am    Post subject: Reply with quote

And for editing your .emacs file (but why you'd do this in nano and not emacs is another question entirely):

Code:
syntax "dotemacs" "^.emacs$"
color green  "^;.*"


It's simple but hopefully as more people read this thread and get the 'idea' we'll see more complex ones :)
Back to top
View user's profile Send private message
fca
Guru
Guru


Joined: 22 Feb 2003
Posts: 345
Location: Germany

PostPosted: Sat Sep 20, 2003 11:15 pm    Post subject: Reply with quote

Some more ebuild high-lighting:
Code:

syntax "ebuild" "\.ebuild$"
color brightcyan "^ *eclass\>" "^ *inherit\>"
color brightwhite "^ *src [^ ]*"
color brightblue "src_compile\>" "src_unpack\>" "src_install\>" "e(info|begin|end|warn|error|patch)\>" "^ *die\>"
color brightmagenta "use\>" "^ *IUSE\>" "^ *(filter|strip|allowed)-flags\>"
color cyan "^ *keepdir\>" "^ *dodir\>" "^ *doman\>"
color yellow "^ *export\>"
color magenta "\<(if|then|else|fi)\>"
color brightgreen "\$\{(.|([A-Z_]*))\}"
color green "#.*$"
Back to top
View user's profile Send private message
duende
n00b
n00b


Joined: 05 Oct 2003
Posts: 21

PostPosted: Wed Oct 15, 2003 5:46 pm    Post subject: Reply with quote

Does anyone have an entry to enable PHP syntax highlighting?
Back to top
View user's profile Send private message
neenee
Veteran
Veteran


Joined: 20 Jul 2003
Posts: 1786

PostPosted: Wed Oct 15, 2003 6:38 pm    Post subject: Reply with quote

i'd just like to say that i love this thread.
_________________
proud to be a scout and a chronic penguin hugger
Legion of Lore - site
Back to top
View user's profile Send private message
morb
n00b
n00b


Joined: 29 Oct 2003
Posts: 1

PostPosted: Wed Oct 29, 2003 6:35 am    Post subject: php syntax highlighting Reply with quote

heres the php syntax you asked for duende, please post any updates if needed!

Code:
syntax "php" ".php"
color brightblue "(.*)\("

color blue "\$[a-zA-Z_0-9$]*|=*|=*|<|>|!"

color green "(var|class|function|echo|case|break|default|exit|switch|if|else|elseif|@|while) "
color green "[.,{}();]"

color red "('.*')|(\".*\")"

color brightyellow "#.*|//.*"
color brightyellow start="/\*" end="\*/"

color brightblue "(<\?php|\?>)"
Back to top
View user's profile Send private message
Mafteah
Apprentice
Apprentice


Joined: 30 May 2003
Posts: 265
Location: IL

PostPosted: Wed Oct 29, 2003 7:33 pm    Post subject: Reply with quote

Someone have entry for c/cpp/h etc. files?
_________________
http://www.mafteah.co.il
Back to top
View user's profile Send private message
Loke
Apprentice
Apprentice


Joined: 25 May 2002
Posts: 274
Location: Norway

PostPosted: Fri Oct 31, 2003 4:04 am    Post subject: Reply with quote

Mafteah wrote:
Someone have entry for c/cpp/h etc. files?


Already present in the sample .nanorc file
_________________
I'm not saying there should be capital punishment for stupidity, I'm saying why don't we take the warning labels off of everything, and let the problem take care of itself?
Back to top
View user's profile Send private message
roofy
Tux's lil' helper
Tux's lil' helper


Joined: 01 Sep 2003
Posts: 86
Location: miami

PostPosted: Fri Nov 07, 2003 5:12 pm    Post subject: bash? Reply with quote

can anyone whip up some bash highlighting?
_________________
/* event horizon */
Athlon XP 2100+ (o/c'ed to 2.1ghz)
LanParty NForce2 Ultra
80GB Maxtor HD
48x CD-RW
ATI 9700 Pro
Back to top
View user's profile Send private message
neenee
Veteran
Veteran


Joined: 20 Jul 2003
Posts: 1786

PostPosted: Fri Nov 07, 2003 5:44 pm    Post subject: Reply with quote

please search for bash colors/modifications using google.com/linux
or on these forums. to start you off a bit, my personal favourite is
vico's.
_________________
proud to be a scout and a chronic penguin hugger
Legion of Lore - site
Back to top
View user's profile Send private message
Snake007uk
Apprentice
Apprentice


Joined: 12 Jan 2003
Posts: 198
Location: London, UK

PostPosted: Thu Mar 18, 2004 10:46 pm    Post subject: Reply with quote

why not just make an ebuild called gentoo colour which does this ???
_________________
Snake :)

Dual AMD MP 2800+, Asus A7M266-D, 1GB Ram, 18.1GB u160 HD, ATI Radeon 9600 Pro, Creative Audigy ZS, Intel SRCU31A, Linksys NIC, iiyama 18.1 4637bk lcd
Back to top
View user's profile Send private message
stahlsau
Guru
Guru


Joined: 09 Jan 2004
Posts: 565
Location: WildWestwoods

PostPosted: Fri Mar 19, 2004 7:28 am    Post subject: Reply with quote

Quote:
This is one that will just highlight all comments in blue. I find it handy for all the misc files just so you can see what should be edited and what should be read:
Code:
syntax "default" ".*"
color blue "^#.*"


I love you guys....thx!
_________________
Join the adopt an unanswered post initiative today
Back to top
View user's profile Send private message
meowsqueak
Veteran
Veteran


Joined: 26 Aug 2003
Posts: 1549
Location: New Zealand

PostPosted: Fri Mar 19, 2004 8:38 am    Post subject: Reply with quote

You can extend this slightly to catch indented comments, which are present in some sorts of files:

Code:
syntax "default" ".*"
color blue "^[ \t]*#.*
Back to top
View user's profile Send private message
neenee
Veteran
Veteran


Joined: 20 Jul 2003
Posts: 1786

PostPosted: Fri Mar 19, 2004 12:40 pm    Post subject: Reply with quote

thanks :wink:

(this post also serves as a bump since i'd like
to see more ideas people have had)
_________________
proud to be a scout and a chronic penguin hugger
Legion of Lore - site
Back to top
View user's profile Send private message
jhgz1
Retired Dev
Retired Dev


Joined: 16 Dec 2003
Posts: 115
Location: Gainesville

PostPosted: Mon Mar 22, 2004 6:29 pm    Post subject: Reply with quote

the blue coloring of the comments looks really great!

great job man! :D
Back to top
View user's profile Send private message
Chrisje
n00b
n00b


Joined: 07 Jun 2003
Posts: 33
Location: The Netherlands

PostPosted: Tue Mar 23, 2004 8:13 pm    Post subject: Reply with quote

ow yeah.. sweet!

thx!
Back to top
View user's profile Send private message
Cid
Apprentice
Apprentice


Joined: 19 Dec 2003
Posts: 155
Location: New York

PostPosted: Fri Apr 23, 2004 2:53 pm    Post subject: python coloring Reply with quote

hi, can anyone help with python syntax coloring? i found this:
Code:

syntax "python" "\.py$"
color red "[\[\](){}:]"
color brightblue "\<__dict__\>"
color green "#.*"
color cyan "([\"']).*?[^\\]\1"
# this is kludge to avoid the line for the example C syntax marked "this is wastefu$color cyan "\"\"" "''"
color cyan start="\"\"\"" end="\"\"\""


but i'm getting an error on the color red "[\[\](){}:]" line saying:

Code:

Error in /home/chris/.nanorc on line 275: Bad regex "[\[\](){}:]": Invalid content of \{\}


also, is there a way to make it so any characters after a # is the comment color? it's only working for comments that start at the beginning. thanks a lot
_________________
Spiral out. Keep going...
Back to top
View user's profile Send private message
meowsqueak
Veteran
Veteran


Joined: 26 Aug 2003
Posts: 1549
Location: New Zealand

PostPosted: Fri Apr 23, 2004 11:48 pm    Post subject: Reply with quote

I imagine you'll need to escape () too. I.e. \(\).

Anything after a hash:

Code:
color blue "#.*"


I realise you've already got this - but it works for me...
Back to top
View user's profile Send private message
Cid
Apprentice
Apprentice


Joined: 19 Dec 2003
Posts: 155
Location: New York

PostPosted: Sat Apr 24, 2004 1:06 am    Post subject: Reply with quote

i tried putting those escapes, but it still didn't work. and the comment one i have is the same as yours but mine only colors the comments that start on the beginning of the line.
_________________
Spiral out. Keep going...
Back to top
View user's profile Send private message
singular
n00b
n00b


Joined: 07 Jun 2003
Posts: 54

PostPosted: Sat Apr 24, 2004 7:46 pm    Post subject: Reply with quote

For python highlighting, here is the one I came up with.
I used the same sequence for strings that you have since it works better than the one I first used.
Code:
syntax "python" "\.py$"
color brightblue "def [a-zA-Z_0-9]+"
color brightcyan "\<(and|assert|break|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|map|not|or|pass|print|raise|return|try|while)\>"
color brightgreen "([\"']).*?[^\\]\1"
color brightgreen start="\"\"\"" end="\"\"\""
color brightred "#.*$"


Note that there isn't supposed to be a line break after brightcyan. But I can't seem to prevent it from getting posted that way.
Back to top
View user's profile Send private message
LeTene
Guru
Guru


Joined: 02 Mar 2004
Posts: 348
Location: Ah'll glass ye!

PostPosted: Sat Jul 10, 2004 7:16 pm    Post subject: Reply with quote

Bumpity for this cool thread - now I can do my PHP coding over SSH without bitching & griping 8) .
_________________
Docs, Tips & Tricks at the Gentoo Wiki page.
Back to top
View user's profile Send private message
allucid
Veteran
Veteran


Joined: 02 Nov 2002
Posts: 1314
Location: atlanta

PostPosted: Sat Jul 10, 2004 7:50 pm    Post subject: Re: Enable nano syntax highlighting Reply with quote

wdreinhart wrote:
Not everyone knows it, but Gentoo's favorite edito, nano, supports syntax hilighting. To enable it, you will need to gunzip /usr/doc/nano-1.2.2/nanorc.sample.gz and name it "~/.nanorc". Then all you have to do is open it (in nano, of course!) and uncomment the syntax blocks for files you want to enable syntax hilighting in.

I have a very basic .ebuild syntax block here if anyone is interested in that. Please post udated versions if you improve on it.
Code:

 syntax "ebuild" "\.ebuild$"
 color brightcyan "^ *eclass\>" "^ *inherit\>"
 color brightwhite "^ *src [^ ]*"
 color brightblue "src_compile\>" "src_unpack\>" "src_install\>" "^ *einfo\>" "$ color yellow "^ *export\>"
 color magenta "\<(if|then|fi)\>"
 color green "#.*$"


also check out /etc/nanorc (which is kept up-to-date by portage)
Back to top
View user's profile Send private message
Xk2c
Apprentice
Apprentice


Joined: 17 Jul 2004
Posts: 240

PostPosted: Tue Jul 20, 2004 5:50 pm    Post subject: hightlighting with Nano in "normal Config" files Reply with quote

Hello

I´ve done my own nanorc with hightlight for perhaps 90% of the Configurationfiles .

Please have a look here :

http://article.gmane.org/gmane.linux.gentoo.user.german/9565

This post is in German, but there are two nanorc in the end.
One for white and one for black background.

Do you have Ideas to get it even better ?

I think it would be great to have something like this to come per default with nano.

I´ve thought about to create a bug to enhance nano with that.
Ist that the right way ?
Is someone responsible for nano here ?

bye Thilo

PS. mail if you are interested in this nanorc
_________________
useful Xterm, Aterm and RXVT-Unicode features


Last edited by Xk2c on Mon Aug 30, 2004 10:58 am; edited 1 time in total
Back to top
View user's profile Send private message
Xk2c
Apprentice
Apprentice


Joined: 17 Jul 2004
Posts: 240

PostPosted: Tue Jul 27, 2004 12:44 pm    Post subject: Re: hightlighting with Nano in "normal Config" fil Reply with quote

Hi

Xk2c wrote:
I´ve done my own nanorc with hightlight for perhaps 90% of the Configurationfiles .

now I´ve created a enhancement Bug.

Please have a look here #58477:
https://bugs.gentoo.org/show_bug.cgi?id=58477


If you would like to get my nanorc for white background:
https://bugs.gentoo.org/attachment.cgi?id=36233&action=view

..or the nanorc for black background:
https://bugs.gentoo.org/attachment.cgi?id=36234&action=view

bye folks
_________________
useful Xterm, Aterm and RXVT-Unicode features
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum