Add cljfmt command

This commit is contained in:
Jeremy Dormitzer 2019-11-10 00:47:34 -05:00
parent 134cec8fba
commit a41ea85b11

View File

@ -1498,6 +1498,34 @@ Enable Org-mode Clojure evaluation:
(setq org-babel-clojure-backend 'cider)
#+END_SRC
Integrate with cljfmt, the Clojure code formatter:
#+BEGIN_SRC emacs-lisp
(defun cljfmt ()
(interactive)
(let* ((start (if (use-region-p) (region-beginning) (point-min)))
(end (if (use-region-p) (region-end) (point-max)))
(text (buffer-substring start end))
(file (make-temp-file "cljfmt"))
(fmted
(with-temp-buffer
(insert text)
(write-file file)
(shell-command
(concat
"clojure "
"-Sdeps "
"'{:aliases {:fmt {:extra-deps {cljfmt {:mvn/version \"0.6.4\"}} :main-opts [\"-m\" \"cljfmt.main\"]}}}' "
"-A:fmt "
"fix "
file))
(revert-buffer nil t)
(buffer-substring (point-min) (point-max)))))
(delete-region start end)
(goto-char start)
(insert fmted)))
(general-def clojure-mode-map "C-M-\\" #'cljfmt)
#+END_SRC
* Scheme
Tell emacs about file extensions which should activate scheme-mode:
#+BEGIN_SRC emacs-lisp