dotfiles/emacs/.emacs.d/config/init-yaml.el
Jeremy Dormitzer 3141955f9c Add language detection to YAML scalar editing
Integrated language-detection to automatically detect and set major modes based on buffer/string content. Enhanced YAML editing with language detection for buffer initialization.
2024-07-24 10:26:33 -04:00

33 lines
1.5 KiB
EmacsLisp

;; -*- lexical-binding: t; -*-
;; YAML - literally the worst but still holds an important place in my life
(use-package yaml-ts-mode
:mode ("\\.yaml\\'" "\\.yml\\'")
:config
(add-hook 'yaml-ts-mode-hook #'highlight-indent-guides-mode))
(use-package yaml-pro
:when (treesit-ready-p 'yaml)
:hook (yaml-ts-mode . yaml-pro-ts-mode)
:config
(defun yaml-pro-edit-initialize-buffer-filter-args-advice (args)
(if-let ((mode (language-detection-detect-mode (buffer-string))))
(cl-destructuring-bind (parent-buffer buffer initial-text type initialize path) args
(let ((init-func (lambda ()
(funcall mode)
(when initialize
(call-interactively initialize)))))
(list parent-buffer buffer initial-text type init-func path)))
args))
(advice-add 'yaml-pro-edit-initialize-buffer :filter-args #'yaml-pro-edit-initialize-buffer-filter-args-advice)
:general
(yaml-pro-ts-mode-map [remap evil-backward-section-begin] #'yaml-pro-ts-prev-subtree
[remap evil-forward-section-begin] #'yaml-pro-ts-next-subtree
[remap evil-shift-right] #'yaml-pro-ts-indent-subtree
[remap evil-shift-left] #'yaml-pro-ts-unindent-subtree
"C-c j" #'yaml-pro-ts-move-subtree-down
"C-c k" #'yaml-pro-ts-move-subtree-up
"C-c f" #'yaml-pro-format))
(provide 'init-yaml)