Skip to content

Instantly share code, notes, and snippets.

@andrzejsliwa
Created October 25, 2012 17:54
Show Gist options
  • Save andrzejsliwa/3954316 to your computer and use it in GitHub Desktop.
Save andrzejsliwa/3954316 to your computer and use it in GitHub Desktop.
erlang emacs-style formatting for vim
#!/usr/bin/env bash
emacs --batch --eval "
(progn (find-file \"$1\")
(if (string-equal \"darwin\" (symbol-name system-type))
(setq erlang-root-dir (car (file-expand-wildcards \"/usr/local/Cellar/erlang/R*\")))
(setq erlang-root-dir \"/usr/lib/erlang/\"))
(setq load-path (cons (car (file-expand-wildcards (concat erlang-root-dir \"/lib/erlang/lib/tools-*/emacs\"))) load-path))
(require 'erlang-start)
(erlang-mode)
(untabify (point-min) (point-max))
(delete-trailing-whitespace)
(erlang-indent-current-buffer)
(save-buffer)
(save-buffers-kill-emacs))" > /dev/null 2>&1
let s:emacs_indenter = expand('<sfile>:p:h') . '/emacs_indent.sh'
function! IndentErlangWithEmacs()
exec ':w'
silent! exec '!' . s:emacs_indenter . ' ' . expand('%:p')
exec ':e ' . expand('%:p')
redraw!
endfunction
command! IndentErl call IndentErlangWithEmacs()
silent! nmap <silent> <Leader>f :IndentErl<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment