Nano on server ignores certain syntax coloring

寵の児 提交于 2019-12-10 08:48:56

问题


I'm using nano on a server via ssh; on that system, nano doesn't have syntax color enabled by default. So I copied these nanosyntax files (for alternative, see also @CraigBarnes' answer) on the server, and had set up ~/.nanorc as:

include "~/nanosyntax/syntax-nanorc/php.nanorc"
include "~/nanosyntax/syntax-nanorc/php2.nanorc"
include "~/nanosyntax/syntax-nanorc/sh.nanorc"
include "~/nanosyntax/syntax-nanorc/python.nanorc"
include "~/nanosyntax/syntax-nanorc/html.nanorc"
include "~/nanosyntax/syntax-nanorc/perl.nanorc"
include "~/nanosyntax/syntax-nanorc/ruby.nanorc"
include "~/nanosyntax/syntax-nanorc/js.nanorc"

Now, this is the thing; if I just call:

nano somefile.php

... no php syntax coloring is done. If I try to force:

nano --syntax=php somefile.php

... still no syntax coloring (shown as plain text). However, if I do:

nano ~/.nanorc

... then I do get syntax coloring (that corresponds to .nanorc type file) ?!

So obviously, syntax coloring as such works (i.e. shell and nano are capable of it) - except, it seems to be ignored for some languages, like in this case php ?!

So, does anyone know what is going on - and how could I get syntax coloring also for php files?

Thanks,
Cheers!


回答1:


I just ran into the same problem, and I fiddled around a bit with the includes to find the error. Surprisingly, turns out that changing the inclusion order fixed the issue:

This works:

include "~/.nano/nanorc.nanorc"
include "~/.nano/sh.nanorc"
# more includes...

This fails to highlight sh files:

include "~/.nano/sh.nanorc"
include "~/.nano/nanorc.nanorc"
# more includes...

So I guess it's probably a bug (in nano 2.2.2; worked fine in nano 2.1.7)




回答2:


Hm... well, it seems there has been an upgrade on that server I was using; originally, nano didn't have syntax coloring by default, which is why I used my own separate ~/.nanorc.

Now, however, on the upgraded server, nano seems to work with php syntax coloring by default - and me having my own separate ~/.nanorc seems to have conflicted; because, once I commented all the entries in the private ~/.nanorc (with an #), php syntax coloring was back!!

Whowouldathunkit ?! :)
Cheers!


EDIT: Just to add a couple of notes about nano:

As noted above, syntax coloring is forced with --syntax switch; to see which syntaxes are available:

grep 'include' /etc/nanorc |       # find lines containing 'include' in nanorc
  grep -v '^#' |                   # don't process lines that start with '#'
    sed 's_.*/\(.*\)\.nanorc"_\1_' # extract plain filenames

Result of this command is something like:

nanorc
c
css
debian
gentoo
html
...

So to force "nanorc" syntax coloring, you use:

nano --syntax=nanorc /usr/share/nano/nanorc.nanorc

.. or forcing "bash" shell script syntax coloring (especially useful with bashrc) would be:

nano --syntax=sh ~/.bashrc



回答3:


Those "nanosyntax" files on Google Code are nearly as bad as ones that come with nano by default.

nano's highlighting engine is more basic than something with nested contexts (e.g. GtkSourceView) but you don't have to settle for crappy highlighting:

https://github.com/craigbarnes/nanorc



来源:https://stackoverflow.com/questions/4744602/nano-on-server-ignores-certain-syntax-coloring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!