Emacs support for cooklang recipe files (.cook).
The package provides two modes — both are included, and you choose which to use:
cook-mode |
cook-ts-mode |
|
|---|---|---|
| Requires | Any Emacs | Emacs 29.2+ |
| Parsing | Regex font-lock | Tree-sitter |
| Extras | — | Imenu, image overlays, YAML frontmatter |
Example of syntax highlight
If you're running Emacs 30 or newer, install with use-package:
(use-package cook-mode
:vc (:url "https://github.com/cooklang/cook-mode"
:rev :newest
:branch "master"))(straight-use-package
'(cook-mode :type git :host github :repo "cooklang/cook-mode"))Download cook-mode.el and add the following to your .emacs.el or .emacs.d/init.el:
(load "/path/to/install/directory/cook-mode.el")Add the following to your packages.el:
(package! cook-mode
:recipe (:host github
:repo "cooklang/cook-mode"))By default, loading the package activates cook-mode for .cook files. To use cook-ts-mode instead, first install the tree-sitter grammar (see below), then load cook-ts-mode:
(require 'cook-ts-mode)Once loaded, cook-ts-mode registers itself in two ways:
- Automatic upgrade: if
cook-modeis also loaded, any.cookfile that would open incook-modeis transparently redirected tocook-ts-modeviamajor-mode-remap-alist. - Standalone: if only
cook-ts-modeis loaded (withoutcook-mode), it registers directly inauto-mode-alist.
To explicitly opt out of the upgrade and keep cook-mode even with the grammar installed:
(setq major-mode-remap-alist
(assoc-delete-all 'cook-mode major-mode-remap-alist))cook-ts-mode requires the cooklang tree-sitter grammar. The easiest way is to let Emacs download and build it for you. Add this to your config:
(add-to-list 'treesit-language-source-alist
'(cooklang "https://github.com/cooklang/tree-sitter-cooklang"))Then install with:
M-x treesit-install-language-grammar RET cooklang
Note: The key must be
cooklang(notcook) — that is the grammar's internal name, which determines the dylib filename (libtree-sitter-cooklang.dylib).
- Syntax highlighting for all cooklang elements (ingredients, cookware, timers, sections, metadata, notes, comments)
- YAML frontmatter highlighting (when the
yamlgrammar is also installed) C-c i— display ingredient listC-c C-i— toggle inline image display for[- image.png -]block commentsM-;— insert--line commentM-x imenu— navigate to sections
https://www.masteringemacs.org/article/how-to-get-started-tree-sitter https://www.masteringemacs.org/article/lets-write-a-treesitter-major-mode https://batsov.com/articles/2026/02/27/building-emacs-major-modes-with-treesitter-lessons-learned/
