jorgenschaefer / elpy

Emacs Python Development Environment
GNU General Public License v3.0
1.9k stars 261 forks source link

How to configure to use together with sage-shell-mode? #1992

Open Eloitor opened 2 years ago

Eloitor commented 2 years ago

Summary

I've configured python-mode and sage-mode to use elpy (for folding). When I run M-x sage-mode I get the message:

elpy-mode: Elpy only works with ‘python-mode’

But If I then run python-mode and then sage-mode I get sage-mode and elpy mode to work together. In particular I get better code folding for sage documents. I would like to setup a configuration to handle this automatically.

Steps to reproduce

  1. Install https://github.com/sagemath/sage-shell-mode which provides sage-mode.
  2. Open some *.sage file, a renamed python file will do.
  3. Run M-x sage-mode, M-x elpy-enable, M-x elpy-mode. You will get the mentioned error.
  4. Run M-x python-mode, M-x elpy-mode, M-x sage-mode, to get sage-mode working with elpy-mode.

My configuration

OS

void-linux

Result of (elpy-config)

Elpy Configuration

Emacs.............: 28.1
Elpy..............: 1.35.0
Virtualenv........: None
Interactive Python: python3 3.10.5 (/usr/bin/python3)
RPC virtualenv....: rpc-venv (/home/eloi/.config/emacs/.local/cache/elpy/rpc-venv)
 Python...........: python 3.10.5 (/home/eloi/.config/emacs/.local/cache/elpy/rpc-venv/bin/python)
 Jedi.............: Not found (0.18.1 available)
 Autopep8.........: Not found (1.6.0 available)
 Yapf.............: Not found (0.32.0 available)
 Black............: Not found (22.6.0 available)
Syntax checker....: Not found (flake8)

Warnings

You have not activated a virtual env. It is not mandatory but often a good idea
to work inside a virtual env. You can use `M-x pyvenv-activate` or `M-x
pyvenv-workon` to activate one.

The directory ~/.local/bin/ is not in your PATH. As there is no active
virtualenv, installing Python packages locally will place executables in that
directory, so Emacs won't find them. If you are missing some commands, do add
this directory to your PATH -- and then do `elpy-rpc-restart'.

The Jedi package is not currently installed. This package is needed for code
completion, code navigation and access to documentation.

[Install jedi]

No autoformatting package is currently installed. At least one is needed
(Autopep8, Yapf or Black) to perform autoformatting (`C-c C-r f` in a python
buffer).

[Install autopep8]
[Install yapf]
[Install black]

The configured syntax checker (flake8) could not be found. Elpy uses this
program to provide syntax checks of your code. You can either install it, or
select another one using `elpy-syntax-check-command`.

[Install flake8]

Options

`Raised' text indicates buttons; type RET or click mouse-1 on a button to invoke
its action. Invoke [+] to expand a group, and [-] to collapse an expanded group.
Invoke the [Group], [Face], and [Option] buttons below to edit that item in
another window.

[+]-- Group Elpy
[+]-- Group Python
[+]-- Group Virtual Environments (Pyvenv)
[+]-- Group Completion (Company)
[+]-- Group Call Signatures (ElDoc)
[+]-- Group Inline Errors (Flymake)
[+]-- Group Code folding (hideshow)
[+]-- Group Snippets (YASnippet)
[+]-- Group Directory Grep (rgrep)
[+]-- Group Search as You Type (ido)
[+]-- Group Django extension
[+]-- Group Autodoc extension

Elpy configuration in my packages.el

(package! sage-shell-mode)
(package! elpy)

Elpy configuration in my config.el

(after! python-mode
  (elpy-enable)
  (elpy-mode 1))

(after! sage-shell-mode
  ;; Run SageMath by M-x run-sage instead of M-x sage-shell:run-sage
  (sage-shell:define-alias)

  ;; Turn on eldoc-mode in Sage terminal and in Sage source files
  (add-hook 'sage-shell-mode-hook #'eldoc-mode)
  (add-hook 'sage-shell:sage-mode-hook #'eldoc-mode)

  ;; Run elpy-enable, elpy-mode
  (elpy-enable)
  (elpy-mode 1))

(after! elpy
  (set-company-backend! 'elpy-mode
    '(elpy-company-backend :with company-files company-yasnippet)))
Eloitor commented 2 years ago

I just realized that removing (elpy-mode 1) from my config does what I want. I don't understand why this caused the error message.