Created
January 26, 2018 13:59
-
-
Save paulanthonywilson/7c96bea9dd7aecee1c89e3ee7efa5b1d to your computer and use it in GitHub Desktop.
Added to a Spacemacs layer to `mix format` on save
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; 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