Skip to content

Instantly share code, notes, and snippets.

@AloisJanicek
Created May 16, 2018 13:36
Show Gist options
  • Save AloisJanicek/2b47dbfa4e73540d86fa8dbc6e490f93 to your computer and use it in GitHub Desktop.
Save AloisJanicek/2b47dbfa4e73540d86fa8dbc6e490f93 to your computer and use it in GitHub Desktop.
Run `html-beautify on html file opened in Emacs buffer when saving it
(defun beautify-html-file-and-revert ()
"Beautify file with html-beautify and only if major mode is web-mode"
(interactive)
(when (eq major-mode 'web-mode)
(message "html-beautify taking care of your markup" (buffer-file-name))
(shell-command (concat "html-beautify --quiet --replace -s 2 -I -E \"\" --max-preserve-newlines 0 -f " (buffer-file-name)))
(revert-buffer t t)))
(add-hook 'after-save-hook #'beautify-html-file-and-revert)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment