From 7226716739e332efe27eb9de2bf2abfd30755b7e Mon Sep 17 00:00:00 2001 From: Manoel Vilela Date: Wed, 7 Oct 2020 04:21:20 -0300 Subject: [PATCH] Add prelude-python-mode-set-encoding-automatically defcustom (#1293) - if it is nil (default) does nothing - if non-nil insert '# coding: utf-8' on top of python buffers --- CHANGELOG.md | 1 + doc/modules/python.md | 13 +++++++++++++ modules/prelude-python.el | 8 +++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba0053b..f5ed719 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ ### Changes +* [#1292](https://github.com/bbatsov/prelude/issues/1292): Add `prelude-python-mode-set-encoding-automatically` defcustom on prelude-python.el module with nil default value. * [#1278](https://github.com/bbatsov/prelude/issues/1278): Don't disable `menu-bar-mode` unless `prelude-minimalistic-ui` is enabled. * [#1277](https://github.com/bbatsov/prelude/issues/1277): Make it possible to disable the creation of `Super`-based keybindings via `prelude-super-keybindings`. * Removed deprecated alias `prelude-ensure-module-deps`. diff --git a/doc/modules/python.md b/doc/modules/python.md index 414f87d..cad83d3 100644 --- a/doc/modules/python.md +++ b/doc/modules/python.md @@ -20,3 +20,16 @@ syntax checkers, [Pylint](http://www.pylint.org/) and order to have Flycheck support on the fly syntax checking for Python you need to have either of these installed and accessible to Emacs. In order to manually choose a checker run `C-c ! s`. + + +## Automatic insertion of # coding: utf-8 + +Previously `prelude-python` had this feature enabled by default, but +that is only necessary on Python2, because Python3 already use utf-8 +as default encoding. In 2020, python2 becames deprecated, so that +functionallity becames a annoying side-effect for some users. If you +wish to enable this, add this to your config file: + +```emacs-lisp +(setq prelude-python-mode-set-encoding-automatically t) +``` diff --git a/modules/prelude-python.el b/modules/prelude-python.el index 735b9d5..fee733d 100644 --- a/modules/prelude-python.el +++ b/modules/prelude-python.el @@ -31,6 +31,11 @@ ;;; Code: +(defcustom prelude-python-mode-set-encoding-automatically nil + "Non-nil values enable auto insertion of '# coding: utf-8' on python buffers." + :type 'boolean + :group 'prelude) + (prelude-require-package 'anaconda-mode) (when (boundp 'company-backends) @@ -97,7 +102,8 @@ #'python-imenu-create-flat-index)) (add-hook 'post-self-insert-hook #'electric-layout-post-self-insert-function nil 'local) - (add-hook 'after-save-hook 'prelude-python-mode-set-encoding nil 'local)) + (when prelude-python-mode-set-encoding-automatically + (add-hook 'after-save-hook 'prelude-python-mode-set-encoding nil 'local))) (setq prelude-python-mode-hook 'prelude-python-mode-defaults)