From 2d96cc2586d3f5e1bb7017d355c562a7991cf6d5 Mon Sep 17 00:00:00 2001 From: Jeremy Dormitzer Date: Mon, 4 Nov 2019 17:09:01 -0500 Subject: [PATCH] Add function to run black on buffer/region --- emacs/init.org | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/emacs/init.org b/emacs/init.org index 3aaf0d3..9dd2fea 100755 --- a/emacs/init.org +++ b/emacs/init.org @@ -1354,6 +1354,17 @@ A function to run a pipenv-aware python repl: (run-python nil nil t)) #+END_SRC +Run black on the current buffer: +#+BEGIN_SRC emacs-lisp + (defun blacken () + (interactive) + (let ((start (if (use-region-p) (region-beginning) (point-min))) + (end (if (use-region-p) (region-end) (point-max)))) + (shell-command-on-region start end "black -q -" nil t))) + + (general-def 'normal python-mode-map "C-M-\\" #'blacken) +#+END_SRC + * Hy Python but Lispy!