A collection of utilities to allow for development with deno in emacs!
This repository contains the following utilities:
deno-fmt
is function that formats the current buffer on save with deno fmt.
The package also exports a minor mode that applies (deno-fmt)
on save.
Feel free to replace typescript-mode
/ js2-mode
in the following with your TypeScript/JavaScript mode of choice.
Configure emacs to use melpa, and require deno-fmt
in your emacs config
(require 'deno-fmt)
then add hooks to automatically enable the minor mode
(add-hook 'typescript-mode-hook 'deno-fmt-mode)
(add-hook 'js2-mode-hook 'deno-fmt-mode)
Add the following to your emacs config
(use-package deno-fmt
:ensure t
:hook (js2-mode typescript-mode))
Add deno-fmt
to your .doom.d/packages.el
(package! deno-fmt)
then add hooks to .doom.d/config.el
(add-hook 'typescript-mode-hook 'deno-fmt-mode)
(add-hook 'js2-mode-hook 'deno-fmt-mode)
Add deno-fmt
to dotspacemacs-additional-packages
in your .spacemacs
file:
(defun dotspacemacs/layers ()
(setq-default
;; ...
dotspacemacs-additional-packages '(deno-fmt)))
then add hooks in dotspacemacs/user-config
(defun dotspacemacs/user-config ()
;; ...
(add-hook 'typescript-mode-hook 'deno-fmt-mode)
(add-hook 'js2-mode-hook 'deno-fmt-mode))
The most reliable way to do this is to make sure your Deno projects always have a deno.jsonc
or deno.json
file in the root directory, then you can do something like:
(defun deno-project-p ()
(let ((root (projectile-project-root)))
(unless (null root)
(let ((config1 (concat root "deno.jsonc"))
(config2 (concat root "deno.json")))
(or (file-exists-p config1) (file-exists-p config2))))))
(defun fmt-for-deno ()
(if (deno-project-p)
(deno-fmt-mode)))
(add-hook 'typescript-mode-hook #'fmt-for-deno)
(add-hook 'js2-mode-hook #'fmt-for-deno)