Skip to content

Commit

Permalink
[Fix #1421] Make the format action in TypeScript code configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
bbatsov committed Jan 23, 2025
1 parent 3caedeb commit a1fcbf2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* Add a F# module.
* Auto-install `use-package`.
* Add `prelude-vertico` module. Vertico a simpler alternative to `ivy-mode` and supersedes Selectrum.
* Make it possible to configure the TypeScript format action using `prelude-ts-format-action`.

### Changes

Expand Down
10 changes: 8 additions & 2 deletions modules/prelude-ts.el
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@

(add-to-list 'auto-mode-alist '("\\.ts\\'" . typescript-mode))

(defcustom prelude-ts-format-action #'tide-format-before-save
"The format function to invoke on save.
Triggered only when `prelude-format-on-save' is enabled."
:package-version '(prelude . "1.2"))

(with-eval-after-load 'typescript-mode
(defun prelude-ts-mode-defaults ()
(interactive)
Expand All @@ -46,8 +52,8 @@
;; formats the buffer before saving
(add-hook 'before-save-hook
(lambda ()
(when prelude-format-on-save
(tide-format-before-save))))
(when (and prelude-format-on-save prelude-ts-format-action)
(funcall prelude-ts-format-action))))

(setq prelude-ts-mode-hook 'prelude-ts-mode-defaults)

Expand Down

0 comments on commit a1fcbf2

Please sign in to comment.