Skip to content

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

License

Notifications You must be signed in to change notification settings

rclarey/deno-emacs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 

Repository files navigation

deno-emacs

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

This repository contains the following utilities:

deno-fmt.el

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.

Installation

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

Vanilla

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)

use-package

Add the following to your emacs config

(use-package deno-fmt
  :ensure t
  :hook (js2-mode typescript-mode))

Doom Emacs

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)

spacemacs

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))

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:

(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)

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published