diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-12 18:00:50 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-12 18:00:50 -0500 |
| commit | e20d1bf71aac0f7bf4b7b21786c94bf221cfa25a (patch) | |
| tree | c0ff3a5ce83dbb2b0f4c01243b7714656c7fe683 | |
| parent | c111f35a53912886cef0baeb7f8463b6ce63c014 (diff) | |
| download | dotemacs-e20d1bf71aac0f7bf4b7b21786c94bf221cfa25a.tar.gz dotemacs-e20d1bf71aac0f7bf4b7b21786c94bf221cfa25a.zip | |
refactor(prog-webdev): extract the prettier format-command builder
I pulled the prettier command-string construction out of `cj/webdev-format-buffer` into `cj/--webdev-format-command`. The wrapper stays thin: resolve `(or buffer-file-name "file.ts")`, hand the command to `shell-command-on-region`, clamp point. With the command shape in a pure helper I can unit-test it directly.
| -rw-r--r-- | modules/prog-webdev.el | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/modules/prog-webdev.el b/modules/prog-webdev.el index 4b0333f2..2b66f2ec 100644 --- a/modules/prog-webdev.el +++ b/modules/prog-webdev.el @@ -58,6 +58,10 @@ Install with: sudo pacman -S prettier") (executable-find ts-language-server-path)) (lsp-deferred))) +(defun cj/--webdev-format-command (file) + "Return the prettier command that formats FILE's contents on stdin." + (format "prettier --stdin-filepath %s" (shell-quote-argument file))) + (defun cj/webdev-format-buffer () "Format the current buffer with prettier. Detects the file type automatically from the filename." @@ -65,10 +69,9 @@ Detects the file type automatically from the filename." (if (executable-find prettier-path) (let ((point (point))) (shell-command-on-region (point-min) (point-max) - (format "prettier --stdin-filepath %s" - (shell-quote-argument - (or buffer-file-name "file.ts"))) - nil t) + (cj/--webdev-format-command + (or buffer-file-name "file.ts")) + nil t) (goto-char (min point (point-max)))) (user-error "prettier not found; install with: sudo pacman -S prettier"))) |
