scopatz / nanorc

Improved Nano Syntax Highlighting Files
Other
3.03k stars 552 forks source link

Some syntax definitions are inferior to Nano upstream #138

Open pik opened 7 years ago

pik commented 7 years ago

Here is a quick comparison by line number:

NANORC_GIT_DIR = "~/git/nanorc"
NANORC_STD_DIR = "/usr/share/nano"
standard_nanorcs = `ls #{NANORC_STD_DIR} | xargs wc -l`.split("\n").map { |row| lcount, fname = row.lstrip.split(" "); [lcount.to_i, fname]}[0...-1]
standard_nanorcs.each do |lcount, fname|
  `test -e #{NANORC_GIT_DIR}/#{fname}`
  next unless $? == 0
  lcount_new = `wc -l #{NANORC_GIT_DIR}/#{fname}`.split(" ").first.to_i
  if lcount > lcount_new
    puts "Standard syntax definition is more verbose for: #{fname}... #{lcount} vs #{lcount_new}"
  end
end
Standard syntax definition is more verbose for: asm.nanorc... 25 vs 17
Standard syntax definition is more verbose for: awk.nanorc... 37 vs 25
Standard syntax definition is more verbose for: gentoo.nanorc... 68 vs 50
Standard syntax definition is more verbose for: go.nanorc... 46 vs 22
Standard syntax definition is more verbose for: groff.nanorc... 26 vs 24
Standard syntax definition is more verbose for: html.nanorc... 28 vs 11
Standard syntax definition is more verbose for: java.nanorc... 16 vs 13
Standard syntax definition is more verbose for: json.nanorc... 34 vs 11
Standard syntax definition is more verbose for: man.nanorc... 18 vs 9
Standard syntax definition is more verbose for: mutt.nanorc... 9 vs 4
Standard syntax definition is more verbose for: nanorc.nanorc... 29 vs 16
Standard syntax definition is more verbose for: ocaml.nanorc... 29 vs 27
Standard syntax definition is more verbose for: patch.nanorc... 26 vs 10
Standard syntax definition is more verbose for: po.nanorc... 29 vs 8
Standard syntax definition is more verbose for: pov.nanorc... 18 vs 15
Standard syntax definition is more verbose for: ruby.nanorc... 35 vs 34
Standard syntax definition is more verbose for: sh.nanorc... 29 vs 15
Standard syntax definition is more verbose for: xml.nanorc... 21 vs 14

While sometimes the verbose definition might not be superior - it clearly is in a number of cases. For example here is the po.nanorc from the upstream repo:

## Colouring for PO files.

syntax "po" "\.pot?$"
comment "#"

# Comments.
color green "^#.*$"
color yellow "Copyright|\(C\)"
# Header fields.
color brightred "^\"X-Bugs:.*\"$"
color brightmagenta "\<(Project\-Id\-Version|Report\-Msgid\-Bugs\-To|Last\-Translator|Language(\-Team)?|X-Bugs|X-Generator|Plural\-Forms)\>"
color cyan "\<(POT\-Creation\-Date|PO\-Revision\-Date|MIME\-Version|Content\-Type|Content\-Transfer\-Encoding)\>"
# Encodings and numbers.
color yellow "\<(UTF|ISO|Windows|Mac|IBM)\>\-[0-9]"
color yellow "[0-9]|pre[0-9]|[0-9]bit"
# Msgids.
color brightblue "^(msgid|msgid_plural|msgstr)\>"
# Tags.
color red " fuzzy(,|$)"
color yellow " (no-)?[-[:alpha:]]+-format(,|$)"
# Format specifiers.
color brightmagenta "%([1-9]\$)?[a-z]*"
# Quotes and newlines.
color yellow "\""
color cyan "\\n"
# Reminders.
color ,yellow "(FIXME|TODO|XXX)"
# Obsolete strings.
color red "#~.*$"

vs. the one provided by this repo:

syntax "PO" "\.pot?$"

color cyan  "\<(msgid|msgstr)\>"
color yellow ""(\\.|[^"])*"|'(\\.|[^'])*'"
color magenta   "\\.?"
color brightblack "(^|[[:space:]])#([^{].*)?$"
color ,green "[[:space:]]+$"

I'd recommend remove syntax definitions which already exist upstream, or to add a note in the README regarding the ones which may be out-dated.

scopatz commented 7 years ago

Please feel free to put in a PR to either update existing definitions or add a note to this effect.

davidhcefx commented 3 months ago

@pik Great analysis! By the way, in order for your ruby script to work from other directory, I'll recommend to change line 3 to: cd #{NANORC_STD_DIR}; ls

NANORC_GIT_DIR = "~/git/nanorc"
NANORC_STD_DIR = "/usr/share/nano"
standard_nanorcs = `cd #{NANORC_STD_DIR}; ls | xargs wc -l`.split("\n").map { |row| lcount, fname = row.lstrip.split(" "); [lcount.to_i, fname]}[0...-1]
standard_nanorcs.each do |lcount, fname|
  `test -e #{NANORC_GIT_DIR}/#{fname}`
  next unless $? == 0
  lcount_new = `wc -l #{NANORC_GIT_DIR}/#{fname}`.split(" ").first.to_i
  if lcount > lcount_new
    puts "Standard syntax definition is more verbose for: #{fname}... #{lcount} vs #{lcount_new}"
  end
end