Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jordangarrison/8720cf98126a1a64890b2f18c1bc69f5 to your computer and use it in GitHub Desktop.
Save jordangarrison/8720cf98126a1a64890b2f18c1bc69f5 to your computer and use it in GitHub Desktop.
Python Black Formatter with Emacs Doom
;; Python Black Formatter
;; package.el
(package! python-black)
;; config.el
(use-package! python-black
:demand t
:after python)
(add-hook! 'python-mode-hook #'python-black-on-save-mode)
;; Feel free to throw your own personal keybindings here
(map! :leader :desc "Blacken Buffer" "m b b" #'python-black-buffer)
(map! :leader :desc "Blacken Region" "m b r" #'python-black-region)
(map! :leader :desc "Blacken Statement" "m b s" #'python-black-statement)
@dorneanu
Copy link

thanks for sharing!

@roryk
Copy link

roryk commented Apr 12, 2021

Thank you! As a tweak, you can stick the configuration stuff under the :config part of use-package!:

(use-package! python-black
  :demand t
  :after python
  :config
  (add-hook! 'python-mode-hook #'python-black-on-save-mode)
  ;; Feel free to throw your own personal keybindings here
  (map! :leader :desc "Blacken Buffer" "m b b" #'python-black-buffer)
  (map! :leader :desc "Blacken Region" "m b r" #'python-black-region)
  (map! :leader :desc "Blacken Statement" "m b s" #'python-black-statement)
)

@vmiheer
Copy link

vmiheer commented Sep 18, 2022

Thank you @jordangarrison and @roryk. I also needed a doom/reload afterwards.

@Vanderscycle
Copy link

@roryk @jordangarrison thank you for sharing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment