diff options
| author | Craig Jennings <c@cjennings.net> | 2026-03-02 19:46:38 -0600 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-03-02 19:46:38 -0600 |
| commit | b5cae72d8f824f235f351821f7d7052b66bc2513 (patch) | |
| tree | 264261c26ec5a6c721e5dbd83e93237e842e53b5 /modules/prog-yaml.el | |
| parent | a46f8af939b112b603a2c95b2e83a1932b208e20 (diff) | |
feat(json,yaml): add tree-sitter modes, formatting, and jq integration
New prog-json module: json-ts-mode with jq formatting (C-; f) and
jq-interactively (C-c C-q). Upgraded prog-yaml to yaml-ts-mode with
prettier formatting. Both use treesit-auto for grammar management.
Includes 18 new tests (10 JSON, 8 YAML), 185/185 passing.
Diffstat (limited to 'modules/prog-yaml.el')
| -rw-r--r-- | modules/prog-yaml.el | 44 |
1 files changed, 37 insertions, 7 deletions
diff --git a/modules/prog-yaml.el b/modules/prog-yaml.el index 1a970313..8411f04c 100644 --- a/modules/prog-yaml.el +++ b/modules/prog-yaml.el @@ -2,17 +2,47 @@ ;; author: Craig Jennings <c@cjennings.net> ;;; Commentary: +;; YAML editing with tree-sitter highlighting and one-key formatting. +;; +;; Features: +;; - Tree-sitter: Syntax highlighting and structural navigation +;; - Formatting: Normalize indentation and style via C-; f +;; +;; Workflow: +;; 1. Open .yml/.yaml file → yaml-ts-mode with tree-sitter highlighting +;; 2. C-; f → Format buffer with prettier ;;; Code: -(use-package yaml-mode - :defer .5 - :commands (yaml-mode) - :config - (add-to-list 'auto-mode-alist '("\\.yml\\'" . yaml-mode)) - (add-to-list 'auto-mode-alist '("\\.yaml\\'" . yaml-mode))) +;; -------------------------------- YAML Mode ---------------------------------- +;; tree-sitter mode for YAML files (built-in, Emacs 29+) +;; NOTE: No :mode directive — treesit-auto (in prog-general.el) handles +;; the auto-mode-alist mapping and auto-installs the grammar on first use. -(add-hook 'yaml-mode-hook ' flycheck-mode-hook) +(use-package yaml-ts-mode + :ensure nil + :defer t) + +;; -------------------------------- Formatting --------------------------------- +;; normalize indentation and style, bound to standard format key + +(defun cj/yaml-format-buffer () + "Format the current YAML buffer with prettier. +Preserves point position as closely as possible." + (interactive) + (if (executable-find "prettier") + (let ((point (point))) + (shell-command-on-region (point-min) (point-max) + "prettier --parser yaml" nil t) + (goto-char (min point (point-max)))) + (user-error "prettier not found; install with: npm install -g prettier"))) + +(defun cj/yaml-setup () + "Set up YAML buffer keybindings and linting." + (local-set-key (kbd "C-; f") #'cj/yaml-format-buffer) + (flycheck-mode 1)) + +(add-hook 'yaml-ts-mode-hook #'cj/yaml-setup) (provide 'prog-yaml) ;;; prog-yaml.el ends here |
