7

Recently I discover a power of MC to view/edit certain types of file. For example this:

shell/.class
    View=%view{ascii} tmp=%p; javap -c ${tmp%%.class}

from ~/.mc/bindings take me brief look for Java class methods/fields by pressing F3. But it is hard to look when all code use same colors. I would like to see keywords and types highlighted in some form.

Is it possible (and how) make user customization for syntax highlighting in build-in Midnight Commander editor/viewer (by regex)?

gavenkoa
  • 1,906
  • 5
  • 31
  • 38

2 Answers2

10

Syntax related files are stored in /usr/share/mc/syntax. These files are provided by the package management system. They could be edited as root, and it should work, but this would be a hack.

The correct solution is to copy /usr/share/mc/syntax/Syntax to your home directory: ~/.config/mc/mcedit/Syntax. (Note: old version could use other path e.g: ~/.mc/cedit) This file defines file types associations, and if it is present in your home directory, then it will override the default one. So it could be edited now.

For example if you want to add a syntax file for qwe extensions you should add these lines:

file ..\*\\.qwe$ qwe\sFile
include /home/username/.config/mc/mcedit/qwe.syntax

Note that include needs an absolute path, if the file is not located in /usr/share/mc/syntax (or also ~/.local/share/mc/mcedit in the newer versions). After that you should create and edit your qwe.syntax file based on the other ones.

szkj
  • 591
  • 5
  • 9
  • 2
    Useful to [add "mjs" to the JavaScript line until MC does so upstream](https://midnight-commander.org/ticket/3890). – Dan Dascalescu Dec 18 '17 at 07:00
  • Note that even if these files are readable, [MC syntax highlight might still not work](https://midnight-commander.org/ticket/4321). – Dan Dascalescu Dec 07 '21 at 19:01
-1

Can't say anything about colours, but the binding needs to be updated to view class files within a jar:

shell/.class
     View=%view{ascii} tmp=%f; xyxy=${tmp##*/}; javap -classpath ${tmp%/*.class} -c ${xyxy%.class}
Indrek
  • 24,204
  • 14
  • 90
  • 93
Yorsch
  • 1