Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/rclarey/deno-emacs

A collection of utilities to allow for development with deno in emacs!
https://github.com/rclarey/deno-emacs

deno emacs emacs-mode formatter

Last synced: 3 months ago
JSON representation

A collection of utilities to allow for development with deno in emacs!

Awesome Lists containing this project

README

        

#+TITLE: deno-emacs

A collection of utilities to allow for development with [[https://deno.land][deno]] in emacs!

This repository contains the following utilities:
- [[deno-fmt.el]]

* deno-fmt.el
~deno-fmt~ is function that formats the current buffer on save with [[https://deno.land/manual/tools/formatter][deno fmt]].
The package also exports a minor mode that applies ~(deno-fmt)~ on save.

** Installation
Feel free to replace ~typescript-mode~ / ~js2-mode~ in the following with your TypeScript/JavaScript mode of choice.

*** Vanilla
[[https://melpa.org/#/getting-started][Configure emacs to use melpa]], and require ~deno-fmt~ in your emacs config
#+BEGIN_SRC elisp
(require 'deno-fmt)
#+END_SRC
then add hooks to automatically enable the minor mode
#+BEGIN_SRC elisp
(add-hook 'typescript-mode-hook 'deno-fmt-mode)
(add-hook 'js2-mode-hook 'deno-fmt-mode)
#+END_SRC

*** use-package
Add the following to your emacs config
#+BEGIN_SRC elisp
(use-package deno-fmt
:ensure t
:hook (js2-mode typescript-mode))
#+END_SRC

*** Doom Emacs
Add ~deno-fmt~ to your ~.doom.d/packages.el~
#+BEGIN_SRC elisp
(package! deno-fmt)
#+END_SRC
then add hooks to ~.doom.d/config.el~
#+BEGIN_SRC elisp
(add-hook 'typescript-mode-hook 'deno-fmt-mode)
(add-hook 'js2-mode-hook 'deno-fmt-mode)
#+END_SRC

*** spacemacs
Add ~deno-fmt~ to ~dotspacemacs-additional-packages~ in your ~.spacemacs~ file:
#+BEGIN_SRC elisp
(defun dotspacemacs/layers ()
(setq-default
;; ...
dotspacemacs-additional-packages '(deno-fmt)))
#+END_SRC
then add hooks in ~dotspacemacs/user-config~
#+BEGIN_SRC elisp
(defun dotspacemacs/user-config ()
;; ...
(add-hook 'typescript-mode-hook 'deno-fmt-mode)
(add-hook 'js2-mode-hook 'deno-fmt-mode))
#+END_SRC

** Only enable ~deno-fmt-mode~ for Deno projects
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:
#+BEGIN_SRC elisp
(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)
#+END_SRC