paetzke / py-autopep8.el

py-autopep8.el integrates autopep8 into Emacs.
GNU General Public License v3.0
79 stars 21 forks source link

Would like to disable the hook on a per buffer basis #21

Open jerryasher opened 7 years ago

jerryasher commented 7 years ago

When editing other people's code, I would like to disable the hook on a per buffer basis so I don't change their whitespace or other aspects of their code.

Are you open to a change like this in py-autopep8.el?

;;;###autoload
(defun py-autopep8-enable-on-save ()
  "Pre-save hook to be used before running autopep8."
  (interactive)
  (if current-prefix-arg
      (progn
        (remove-hook 'before-save-hook 'py-autopep8-buffer t)
        (message "py-autopep8-buffer removed"))
    (add-hook 'before-save-hook 'py-autopep8-buffer nil t)))

I can create a pull request if so, otherwise, I am open to your preferences...

Thanks

chongchonghe commented 7 years ago

I'm in great demand of this feature as well. I wish there is a way to disable py-autopep8 for the current buffer.

jerryasher commented 7 years ago

Pull request #23 should address this.

ideasman42 commented 2 years ago

Melpa now points to a fork of this package maintained here: https://github.com/ideasman42/emacs-py-autopep8

Formatting on save first calls py-autopep8-on-save-p which you can configure to a function (defaulting to 'always). There is an included function 'py-autopep8-check-pyproject-exists-with-autopep8 that only auto-formats when you have autopep8 configured for the project. But if you want to check something else you can set this to your own function.