With the recent integration of the HID format into Genode, I’ve found myself working through many HID files, enjoying the clear and digestible syntax. However, when it came to editing those files in my preferred editor, Emacs, it was less pleasant, partly due to the noticeable lack of syntax highlighting. As far as I can tell, the only editor that has any semblance of support for HID files is Vim. As an Emacs user, I couldn’t let that stand, and I decided to write my own Emacs major mode for HID files. This grew into hid-mode, which performs syntax highlighting on HID files and provides a small set of editing conveniences tailored to the format’s structure.
Syntax highlighting is done through Emacs’ traditional, search-based font-lock method. Emacs provides the rx macro for writing readable regexes, and (finally
) I managed to write a regex that catches all disabled x nodes and their children.
Since HID is fluid in its layout and structure, I implemented custom indentation rules to balance flexibility with the format’s natural flow, though there’s certainly room for improvement. I also added a toggle “gutter” function to quickly create a visual link between nodes, which helps with formatting and readability. Currently, the mode has full syntax highlighting, three indentation modes, and an electric indent replacement that keeps the gutter intact, but the smart indentation is still experimental and multiline constructs require full buffer refontification. In the future, I am looking to add support for using HSD files as the basis for indentation and syntax-highlight rules derived from their configs.
If you want to try it out, you can add it via use-package.
(use-package hid-mode
:vc (:url "https://codeberg.org/tickzip/hid-mode"))