editor/format: add +format-with option

+ A formatter can now be specified explicitly buffer-locally by setting
  +format-with to a symbol representing the name of the
  formatter (accepts any key of format-all-format-table)
+ Passing C-u to any of +format/buffer, +format/region or
  +format/region-or-buffer will now prompt you to select a formatter.
+ Revise docstring for +format-on-save-enabled-modes
This commit is contained in:
Henrik Lissner 2018-09-08 23:36:24 -04:00
parent 46083ed398
commit 8480f52081
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 39 additions and 15 deletions

View file

@ -3,14 +3,17 @@
(defvar +format-on-save-enabled-modes
'(not emacs-lisp-mode ; elisp's mechanisms are good enough
sql-mode) ; sqlformat is currently broken
"A list of major modes in which to enable `format-all-mode'.
This mode will auto-format buffers when you save them.
"A list of major modes in which to reformat the buffer upon saving.
If this list begins with `not', then it negates the list.
If it is `t', it is enabled in all modes.
If nil, it is disabled in all modes, the same as if the +onsave flag wasn't
used at all.")
used at all.
Irrelevant if you do not have the +onsave flag enabled for this module.")
(defvar-local +format-with nil "Set this to explicitly use a certain formatter
for the current buffer.")
;;
@ -32,3 +35,11 @@ This is controlled by `+format-on-save-enabled-modes'."
(when (featurep! +onsave)
(add-hook 'after-change-major-mode-hook #'+format|enable-on-save-maybe))
;;
;; Hacks
;; Allow a specific formatter to be used by setting `+format-with', either
;; buffer-locally or let-bound.
(advice-add #'format-all-probe :around #'+format*probe)