Skip to content

Instantly share code, notes, and snippets.

@paulanthonywilson
Created January 26, 2018 13:59
Show Gist options
  • Save paulanthonywilson/7c96bea9dd7aecee1c89e3ee7efa5b1d to your computer and use it in GitHub Desktop.
Save paulanthonywilson/7c96bea9dd7aecee1c89e3ee7efa5b1d to your computer and use it in GitHub Desktop.
Added to a Spacemacs layer to `mix format` on save
;;; Mostly nicked from https://github.com/jasongoodwin/emacs-elixir-formatter/blob/master/elixir-formatter.el
;;; I followed instructions from http://www.cultivatehq.com/posts/spacemacs-shared-config/ to add a Spacemacs
;;; layer, and just added this as a funcs.el file.
;;;
;;; (I still don't know what I'm doing.)
(defcustom
mix-location
"~/.asdf/shims/mix"
"Location of mix binary (must be elixir 1.6 or later)"
:type 'string
:group 'mix-format
)
(defcustom
elixir-location
"~/.asdf/shims/elixir"
"Location of elixir binary (must be elixir 1.6 or later)"
:type 'string
:group 'mix-format
)
(defun
elixir-format-current-file
()
"Saves the file and then calls out to mix to format the code."
(interactive)
(save-buffer)
(defvar current-file (buffer-file-name))
(shell-command (concat elixir-location " " mix-location " format " current-file)))
(defun
elixir-no-save-format-current-file
()
"Saves the file and then calls out to mix to format the code."
(defvar current-file (buffer-file-name))
(shell-command (concat elixir-location " " mix-location " format " current-file)))
;; elixir-mode hook
(add-hook 'elixir-mode-hook
(lambda () (add-hook 'after-save-hook 'elixir-no-save-format-current-file)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment