jorgenschaefer / elpy

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

C-c C-r f is calling (elpy-refactor-extract-function) not (elpy-format-code) #1862

Open whompyjaw opened 3 years ago

whompyjaw commented 3 years ago

Summary

I see that these two keybinds are conflicting in the docs: C-c C-r f (elpy-format-code) (C-c C-r f (elpy-refactor-extract-function)

Am I suppose to change something in my config?

Steps to reproduce

Execute: C-c C-r f... Asks me to create a new function name image (which is similar to elpy-refactor-extract-function

My configuration

OS

Windows

Result of (elpy-config)

Elpy Configuration

Emacs.............: 27.1
Elpy..............: 1.35.0
Virtualenv........: None
Interactive Python: python 3.9.0 (c:/Users/username/AppData/Local/Programs/Python/Python39/python.exe)
RPC virtualenv....: rpc-venv (c:/Users/username/.emacs.d/elpy/rpc-venv)
 Python...........: c:/WINDOWS/py.exe 3.9.0 (c:/WINDOWS/py.exe)
 Jedi.............: 0.17.2
 Rope.............: 0.18.0
 Autopep8.........: 1.5.4
 Yapf.............: 0.30.0
 Black............: 20.8b1
Syntax checker....: flake8.exe (c:/Users/username/AppData/Local/Programs/Python/Python39/Scripts/flake8.exe)

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.

Options

Square brackets indicate 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 init.el

(require 'package)
;; (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
;; Comment/uncomment this line to enable MELPA Stable if desired.  See `package-archive-priorities`
;; and `package-pinned-packages`. Most users will not need or want to do this.
(add-to-list 'package-archives '("melpa-stable" . "https://stable.melpa.org/packages/") t)
(package-initialize)

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(custom-safe-themes
   '("78e9a3e1c519656654044aeb25acb8bec02579508c145b6db158d2cfad87c44e" default))
 '(elpy-formatter 'black)
 '(package-selected-packages '(elpy)))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )

;; Saving backups
(setq version-control t     ;; Use version numbers for backups.
      kept-new-versions 10  ;; Number of newest versions to keep.
      kept-old-versions 0   ;; Number of oldest versions to keep.
      delete-old-versions t ;; Don't ask to delete excess backup versions.
      backup-by-copying t)  ;; Copy all files, don't rename them.
(setq vc-make-backup-files t)

;; Default and per-save backups go here:
(setq backup-directory-alist '(("" . "~/.emacs.d/backup/per-save")))

(defun force-backup-of-buffer ()
  ;; Make a special "per session" backup at the first save of each
  ;; emacs session.
  (when (not buffer-backed-up)
    ;; Override the default parameters for per-session backups.
    (let ((backup-directory-alist '(("" . "~/.emacs.d/backup/per-session")))
          (kept-new-versions 3))
      (backup-buffer)))
  ;; Make a "per save" backup on each save.  The first save results in
  ;; both a per-session and a per-save backup, to keep the numbering
  ;; of per-save backups consistent.
  (let ((buffer-backed-up nil))
    (backup-buffer)))

(add-hook 'before-save-hook  'force-backup-of-buffer)

;; Config
(elpy-enable)
(load-theme 'zenburn)
(setq default-directory "~/")
(setq inhibit-splash-screen t)
(global-display-line-numbers-mode)
(add-hook 'elpy-mode-hook (lambda ()
                            (add-hook 'before-save-hook
                                      'elpy-black-fix-code nil t)))
cooltux008 commented 3 years ago

I made it C-c Cr f work, you could try to edit ~/.emacs.d/elpa/elpy-20201115.1811/elpy.el and add a custom kbdmap, like this

(defvar elpy-refactor-map
  (let ((map (make-sparse-keymap "Refactor")))
    (define-key map (kbd "i") (cons (format "%snline"
                                            (propertize "i" 'face 'bold))
                                    'elpy-refactor-inline))
    (define-key map (kbd "e") (cons (format "function %sxtraction"
                                            (propertize "e" 'face 'bold))
                                    'elpy-refactor-extract-function))
    (define-key map (kbd "f") (cons (format "elpy-%sormat-code"
                                            (propertize "f" 'face 'bold))
                                    'elpy-format-code))
    (define-key map (kbd "v") (cons (format "%sariable extraction"
                                            (propertize "v" 'face 'bold))
                                    'elpy-refactor-extract-variable))
    (define-key map (kbd "r") (cons (format "%sename"
                                            (propertize "r" 'face 'bold))
                                    'elpy-refactor-rename))
    map)
  "Key map for the refactor command.")

Then, when you reopen emacs and activate C-c C-r f, those options jump out.

Refactor: rename, variable extraction, f = elpy-format-code, e = function extraction, inline

My emacs env is below, hope it works.

Elpy Configuration
  Emacs.............: 27.1
  Elpy..............: 1.35.0
  Virtualenv........: 3.9.4-dev (/Users/admin/.pyenv/versions/3.9.4/envs/3.9.4-dev)
  Interactive Python: jupyter 4.7.1 (/Users/admin/.pyenv/shims/jupyter)
  RPC virtualenv....: .pyenv (/Users/admin/.pyenv)
   Python...........: python3 3.9.4 (/Users/admin/.pyenv/shims/python3)
   Jedi.............: 0.18.0
  Rope.............: 0.19.0
  Autopep8.........: 1.5.6
  Yapf.............: 0.31.0
  Black............: 21.4b0
 Syntax checker....: flake8 (/Users/admin/.pyenv/shims/flake8)
NimSed commented 2 years ago

I'd like to vote this up too. The error has even found its way to the documentation: https://elpy.readthedocs.io/en/latest/ide.html