{
  "id": 16196953,
  "title": "Emacs finally folds to my liking: kirigami, tree-sitter, hide-show, Org, XML",
  "url": "https://urgent.news/2026/10/23/emacs-finally-folds-to-my-liking-kirigami-tree-sitter-hide-show-org",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-10-23T14:38:13.000Z",
  "source": {
    "name": "Lobsters",
    "slug": "lobsters",
    "url": "https://jointhefreeworld.org/blog/articles/emacs/emacs-folding-kirigami/"
  },
  "original_language": "en",
  "account": "After years of experimenting with Emacs configurations, the final piece that made the difference was a unified folding system across all programming languages. Emacs' built-in folding engines, such as Tree-sitter, Hideshow, Outline, and Org, each had their own approach, leading to inconsistent user experiences. To unify them, a new Emacs package called \"kirigami\" was developed. Kirigami maintains a list of folding engines, checks which one is active in the current buffer, and forwards the folding commands to the appropriate engine. This provides a consistent interface for all languages and modes.\n\nThe package includes a set of customizable keys, allowing the same shortcuts to be used across different buffers, whether it be a Kotlin buffer, YAML file, Scheme or ELisp buffer, or an Org file. This consistency eliminates confusion and allows for muscle memory transfer throughout the entire polyglot configuration.\n\nOne challenge was handling the default behavior of Outline minor mode, which appears in most buffers. To address this, the order of kirigami-fold-list was adjusted, ensuring Hideshow took precedence over Outline when deliberately enabled. This way, users could customize their folding experience per buffer without rewriting the entire configuration.\n\nThe performance improvement was particularly noteworthy. The original implementation redrawed indicators after every command, leading to slow performance in large files. In the optimized version, folding changes text properties rather than characters, taking a cheap path. Fold state is read back from Org on each redraw, instead of being remembered, ensuring external folding never leaves stale markers. The configuration choices org-fold-core-style set to text-properties, org-element-use-cache set to on, and Org starting with showeverything further enhance performance. These changes eliminate the need for re-parsing the entire file and significantly speed up folding operations.\n\nThe result is a folding system that is seamless, consistent, and efficient across all programming languages and modes. Indicators are now subtle, resembling brackets, and indicators only appear when needed. The overall folding experience has become enjoyable, with zero pauses even in 3000-line Org files. The code for the engines, indicators, and key bindings is available in dev-folding.el, heks-emacs.el, and org.el, all licensed under GPL-3.0. The comprehensive testing ensures that the package functions as intended, with no unexpected key bindings or misbehaving markers.",
  "summary": null,
  "key_points": [],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}