aboutsummaryrefslogtreecommitdiff
path: root/modules/prog-webdev.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-06-20 12:53:33 -0400
committerCraig Jennings <c@cjennings.net>2026-06-20 12:53:33 -0400
commit955357251d84a31c39cf18583393935369049f32 (patch)
tree0d78a84c36ed50fbefe3d232b4973718681dbfa1 /modules/prog-webdev.el
parent4f088c3930ee8ee2ee58796f0634d90b76b50526 (diff)
downloaddotemacs-955357251d84a31c39cf18583393935369049f32.tar.gz
dotemacs-955357251d84a31c39cf18583393935369049f32.zip
refactor(prog-webdev): use the shared format-region helper
prog-webdev carried cj/--webdev-format-region, a third byte-identical copy of the format-region helper already extracted to system-lib in the prog-json/prog-yaml dedup. Drop it and call cj/format-region-with-program (system-lib is already required). Behavior unchanged; the existing format tests cover it.
Diffstat (limited to 'modules/prog-webdev.el')
-rw-r--r--modules/prog-webdev.el27
1 files changed, 1 insertions, 26 deletions
diff --git a/modules/prog-webdev.el b/modules/prog-webdev.el
index 8832446ac..b228d0cc8 100644
--- a/modules/prog-webdev.el
+++ b/modules/prog-webdev.el
@@ -82,37 +82,12 @@ via `call-process-region', so FILE can contain spaces or shell
metacharacters without risk."
(list "--stdin-filepath" file))
-(defun cj/--webdev-format-region (program &rest args)
- "Replace the buffer with PROGRAM ARGS run over its contents, via argv.
-Runs PROGRAM (with ARGS) on the whole buffer through
-`call-process-region' — no shell, so no quoting or word-splitting.
-The buffer is replaced only when PROGRAM exits zero; on a non-zero
-exit the buffer is left untouched and an error is signalled with
-the program's stderr text. Point is preserved as closely as the
-reformatted size allows. Returns t on success."
- (let* ((point (point))
- (src (current-buffer))
- (out (generate-new-buffer " *webdev-format-out*"))
- (status (apply #'call-process-region
- (point-min) (point-max) program
- nil out nil args)))
- (unwind-protect
- (if (and (integerp status) (zerop status))
- (progn
- (with-current-buffer src
- (replace-buffer-contents out)
- (goto-char (min point (point-max))))
- t)
- (user-error "%s failed: %s" program
- (string-trim (with-current-buffer out (buffer-string)))))
- (kill-buffer out))))
-
(defun cj/webdev-format-buffer ()
"Format the current buffer with prettier.
Detects the file type automatically from the filename."
(interactive)
(if (executable-find prettier-path)
- (apply #'cj/--webdev-format-region prettier-path
+ (apply #'cj/format-region-with-program prettier-path
(cj/--webdev-format-args (or buffer-file-name "file.ts")))
(user-error "prettier not found; install with: sudo pacman -S prettier")))