Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add prelude-python-mode-set-encoding-automatically defcustom #1293

Merged
merged 3 commits into from
Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
13 changes: 13 additions & 0 deletions doc/modules/python.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```
8 changes: 7 additions & 1 deletion modules/prelude-python.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down