Skip to content

syntax: fix TOML / add Kconfig syntax highlighting#5009

Open
sknaumov wants to merge 3 commits into
MidnightCommander:masterfrom
sknaumov:sknaumov/fix-toml-add-kconfig-syntax
Open

syntax: fix TOML / add Kconfig syntax highlighting#5009
sknaumov wants to merge 3 commits into
MidnightCommander:masterfrom
sknaumov:sknaumov/fix-toml-add-kconfig-syntax

Conversation

@sknaumov
Copy link
Copy Markdown

@sknaumov sknaumov commented Feb 7, 2026

Proposed changes

Improve syntax highlighting:

Highlight Kconfig output files.

Checklist

  • I have referenced the issue(s) resolved by this PR (if any)
  • I have signed-off my contribution with git commit --amend -s
  • Lint and unit tests pass locally with my changes (make indent && make check)
  • I have added tests that prove my fix is effective or that my feature works
  • I have added the necessary documentation (if appropriate)

I've not tried to build / install mc - I tested my changes on existing installation by modifying /usr/share/mc/syntax/* files.

@github-actions github-actions Bot added needs triage Needs triage by maintainers prio: medium Has the potential to affect progress labels Feb 7, 2026
@github-actions github-actions Bot added this to the Future Releases milestone Feb 7, 2026
@sknaumov
Copy link
Copy Markdown
Author

sknaumov commented Feb 7, 2026

Please note that I used / for Kconfig.* files not to treat all files in Kconfig directory as Kconfig files.

It looks like Dockerfile file matching rules are incorrect, as all files in Dockerfile* directory will be treated as docker files.

@sknaumov
Copy link
Copy Markdown
Author

sknaumov commented Feb 8, 2026

BTW, I decided to highlight kconfig output files as Java properties, just because .config - default Kconfig output file, is already highlighted by mc this way, but I'm not sure that it is a right way to go.

.config is quite generic name to treat it exclusively as some Java-related file, and in fact it is an env file in Kconfig case - that could be sourced into any shell script. So probably the right way is to write syntax file for .env files and use it here too instead of relying on some Java-related syntax. Or adjust this syntax to suit both Java properties and env files.

@zyv zyv added area: mcedit mcedit, the built-in text editor and removed needs triage Needs triage by maintainers labels Feb 8, 2026
@zyv
Copy link
Copy Markdown
Member

zyv commented Feb 8, 2026

Please note that I used / for Kconfig.* files not to treat all files in Kconfig directory as Kconfig files.

It looks like Dockerfile file matching rules are incorrect, as all files in Dockerfile* directory will be treated as docker files.

Actually, there are quite a lot of rules (starting from the very first ones) that assume that we match on the filename and not the full path to the file.

@mc-worker, do you know if there is a reason why we actually match on the full path to the file and does it make sense? Maybe we should change this to really only matching on the file name?

% git diff
diff --git a/src/editor/syntax.c b/src/editor/syntax.c
index 9ccef28ae..8da7173d8 100644
--- a/src/editor/syntax.c
+++ b/src/editor/syntax.c
@@ -1555,7 +1555,7 @@ edit_load_syntax (WEdit *edit, GPtrArray *pnames, const char *type)
 
     f = mc_config_get_full_path (EDIT_SYNTAX_FILE);
     if (edit != NULL)
-        r = edit_read_syntax_file (edit, pnames, f, vfs_path_as_str (edit->filename_vpath),
+        r = edit_read_syntax_file (edit, pnames, f, vfs_path_get_last_path_str (edit->filename_vpath),
                                    get_first_editor_line (edit),
                                    auto_syntax ? NULL : edit->syntax_type);
     else

* Fix broken comments handling.
* Support escapes in basic (double-quoted) strings.
* Highlight literal (single-quoted) strings.
* Support multi-line strings.
* Make tables (sections) easily distinguishable from comments.
* Make highlighting of inline tables consistent.
* Unify colors with other syntax files like YAML / C / Shell.

Signed-off-by: Sergey Naumov <sknaumov@gmail.com>
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
@zyv zyv force-pushed the sknaumov/fix-toml-add-kconfig-syntax branch from ab71e52 to 68567d7 Compare May 10, 2026 05:43
@zyv
Copy link
Copy Markdown
Member

zyv commented May 10, 2026

Please note that I used / for Kconfig.* files not to treat all files in Kconfig directory as Kconfig files.
It looks like Dockerfile file matching rules are incorrect, as all files in Dockerfile* directory will be treated as docker files.

Actually, there are quite a lot of rules (starting from the very first ones) that assume that we match on the filename and not the full path to the file.

@KuzinAndrey, since you submitted the Dockerfile rules in #4788, could you please have a look at that and possibly other instances? Actually, I would love to see someone replace ..\* with .\+ for clarity and leave .\* wherever it is really needed. I'm afraid many cases are due to submitters simply not understanding the regex system.

sknaumov added 2 commits May 10, 2026 07:54
* Implement Kconfig specification with Kconfiglib extensions.

* Highlight the following files:
  - Kconfig / Kconfig.* - for Linux kernel, U-Boot, Zephyr
  - Config.in / Config.in.* / Config.src - for Buildroot, Busybox
  - *.kconf / *.kconfig - just alternative extension-based variant

Signed-off-by: Sergey Naumov <sknaumov@gmail.com>
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
* .config is already highlighted as Java properties => reuse it. It is not ideal, but better than nothing.
* Additionally hightlight:
  - .config.* - e.g. .config.old produced by Kconfig.
  - *defconfig - used in Linux kernel, Buildroot, Busybox, U-Boot, Zephyr.
* Kconfig.defconfig should still be treated as Kconfig definition file, not as its output.

Signed-off-by: Sergey Naumov <sknaumov@gmail.com>
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
@zyv zyv force-pushed the sknaumov/fix-toml-add-kconfig-syntax branch from 68567d7 to 09df6e0 Compare May 10, 2026 05:57
Copy link
Copy Markdown
Member

@zyv zyv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I'm sorry for the lack of reaction. I have rebased the PR and updated the patterns to make them more understandable to me. @sknaumov, could you please check this?

I think this should be neither held back by #5067, nor the Dockerfile comment and/or other rule mistakes, of which it seems that we have plenty.

Hopefully, @KuzinAndrey would be interested enough to maybe clean the mistakes up, add case-insensitiveness where it makes sense, and make the patterns more understandable. He's done some valuable contributions in this direction in the past.

In my opinion, we should merge this.

@zyv zyv modified the milestones: Future Releases, 4.9.0 May 10, 2026
@KuzinAndrey
Copy link
Copy Markdown
Contributor

KuzinAndrey commented May 10, 2026

@zyv i don't undestand issue with Dockefile rule.
In my case i have different filenames, for example:

  • Dockerfile
  • Dockerfile.alpine
  • Dockerfile.debian
  • Dockerfile-test1
  • Dockerfile.bak1

And regexp with chars ./*$ at end satisfies all my cases.
If filename treated as full path to file, then path Dockerfile/filename of course be treated as Dockerfile rule by this regexp.
You suggest to change vfs_path_as_str -> vfs_path_get_last_path_str in syntax.c:1558 and i think this really fix the problem.
I don't know where the path could be used, maybe only in the case of creating a syntax file for .git/config, and if you want i can make PR with new regexp ignoring separator char /:

file Dockerfile[^/]\*$ Dockerfile
include dockerfile.syntax

Or you can make these changes yourself.

@sknaumov
Copy link
Copy Markdown
Author

@zyv I used \* instead of ? in patterns for 2 reasons:

  1. There are Kconfig files with multiple extensions in Zephyr, like Kconfig.board.v2, Kconfig.template.log_config.net or Kconfig.defconfig.series. They are no longer highlighted with your changes.
  2. It is always better to still highlight a file if possible if it is renamed with .bak suffix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: mcedit mcedit, the built-in text editor prio: medium Has the potential to affect progress

Development

Successfully merging this pull request may close these issues.

syntax: add highlighting for Kconfig files syntax: multiple issues in syntax highlighting of TOML files

3 participants