summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/org-export-config.el2
-rw-r--r--modules/prog-json.el60
-rw-r--r--modules/prog-webdev.el8
-rw-r--r--modules/prog-yaml.el44
4 files changed, 98 insertions, 16 deletions
diff --git a/modules/org-export-config.el b/modules/org-export-config.el
index 4451eddd..688d8f99 100644
--- a/modules/org-export-config.el
+++ b/modules/org-export-config.el
@@ -49,7 +49,7 @@
(setq org-export-with-tasks '("TODO")) ;; export with tasks by default
(setq org-export-with-tasks nil) ;; export WITHOUT tasks by default
(setq org-export-with-toc t) ;; export WITH table of contents by default
- (setq org-export-initial-scope 'subtree) ;; 'buffer is your other choice
+ (setq org-export-initial-scope 'buffer) ;; 'subtree is your other choice
(setq org-export-with-author nil)) ;; export without author by default
(use-package ox-html
diff --git a/modules/prog-json.el b/modules/prog-json.el
new file mode 100644
index 00000000..6dba6dee
--- /dev/null
+++ b/modules/prog-json.el
@@ -0,0 +1,60 @@
+;;; prog-json.el --- JSON Editing, Formatting, and jq Integration -*- lexical-binding: t; coding: utf-8; -*-
+;; Author: Craig Jennings <c@cjennings.net>
+
+;;; Commentary:
+;; JSON editing with tree-sitter highlighting, one-key formatting, and
+;; interactive jq queries against the current buffer.
+;;
+;; Features:
+;; - Tree-sitter: Better syntax highlighting and structural navigation
+;; - Formatting: Pretty-print with sorted keys via C-; f
+;; - jq: Interactive jq REPL against current JSON buffer
+;;
+;; Workflow:
+;; 1. Open .json file → json-ts-mode with tree-sitter highlighting
+;; 2. C-; f → Format/pretty-print the buffer
+;; 3. C-c C-q → Open jq interactive buffer to query/transform JSON
+
+;;; Code:
+
+(defvar json-ts-mode-map)
+
+;; -------------------------------- JSON Mode ----------------------------------
+;; tree-sitter mode for JSON files (built-in, Emacs 29+)
+;; NOTE: No :mode directive here — treesit-auto (in prog-general.el) handles
+;; the auto-mode-alist mapping and auto-installs the grammar on first use.
+
+(use-package json-ts-mode
+ :ensure nil
+ :defer t)
+
+;; -------------------------------- Formatting ---------------------------------
+;; pretty-print with sorted keys, bound to standard format key
+
+(defun cj/json-format-buffer ()
+ "Format the current JSON buffer with sorted keys.
+Uses jq if available for reliable formatting, otherwise falls
+back to the built-in `json-pretty-print-buffer-ordered'."
+ (interactive)
+ (if (executable-find "jq")
+ (let ((point (point)))
+ (shell-command-on-region (point-min) (point-max) "jq --sort-keys ." nil t)
+ (goto-char (min point (point-max))))
+ (json-pretty-print-buffer-ordered)))
+
+(defun cj/json-setup ()
+ "Set up JSON buffer keybindings."
+ (local-set-key (kbd "C-; f") #'cj/json-format-buffer))
+
+(add-hook 'json-ts-mode-hook #'cj/json-setup)
+
+;; --------------------------------- jq Mode -----------------------------------
+;; interactive jq queries against JSON buffers
+
+(use-package jq-mode
+ :defer t
+ :bind (:map json-ts-mode-map
+ ("C-c C-q" . jq-interactively)))
+
+(provide 'prog-json)
+;;; prog-json.el ends here.
diff --git a/modules/prog-webdev.el b/modules/prog-webdev.el
index a45bd376..c0a5980b 100644
--- a/modules/prog-webdev.el
+++ b/modules/prog-webdev.el
@@ -3,7 +3,6 @@
;;
;;; Commentary:
;; Open a project file and Emacs selects the right helper:
-;; - *.json buffers drop into json-mode for quick structural edits.
;; - *.js buffers jump into js2-mode for linty feedback.
;; - Mixed HTML templates land in web-mode which chains Tide and CSS Eldoc.
;;
@@ -17,13 +16,6 @@
;;; Code:
-;; --------------------------------- JSON Mode ---------------------------------
-;; mode for editing JavaScript Object Notation (JSON) data files
-
-(use-package json-mode
- :mode ("\\.json\\'" . json-mode)
- :defer .5)
-
;; ---------------------------------- JS2 Mode ---------------------------------
;; javascript editing mode
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