I am working with python using Emacs 26.3. My goal is to jump to definition of the function and jump back, for that I am using https://github.com/jacktasia/dumb-jump, which runs elpy-goto-definition on the background.

I am starting emacs on startup using crontab using (&>/dev/null emacsclient -t -q &). On that case, elpy-goto-definition never works. I have to restart emacs. But after the restart, it takes around 30 seconds for elpy to launch, sometimes it does not launch (I do not know why).

  • What may be the main reason that let elpy-goto-definition to fail. Can I force elpy-goto-definition to work if it fails? or restart elpy within emacs if possible?

My setup:

(setq elpy-rpc-backend "jedi")
(add-hook 'elpy-mode-hook (lambda () (highlight-indentation-mode -1)))
(add-hook 'xref-backend-functions #'dumb-jump-xref-activate)

;; https://emacs.stackexchange.com/a/19194/18414
(defun goto-def-or-rgrep ()
  "Go to definition of thing at point or do an rgrep in project if that fails"
  (condition-case nil (elpy-goto-definition)
    (error (elpy-rgrep-symbol (thing-at-point 'symbol)))))

(global-set-key "\C-x\C-j" 'goto-def-or-rgrep)
  • To jump to a definition I simply use M-.and to jump back M-, I have nothing special in my init file. What you do seems very complicated to me. Sorry if I misunderstand your problem. – Raoul HATTERER Feb 12 at 19:00
  • Which function does M-. run in the background? – alper Feb 13 at 13:04
  • M-, runs the command xref-pop-marker-stack (found in global-map), which is an autoloaded interactive compiled Lisp function in ‘xref.el’. It is bound to M-*, M-,, <menu-bar> <edit> <goto> <xref-pop>. (xref-pop-marker-stack) Probably introduced at or before Emacs version 25.1. Pop back to where M-. was last invoked. – Raoul HATTERER Feb 13 at 16:51
  • M-. runs the command xref-find-definitions (found in global-map), which is an autoloaded interactive compiled Lisp function in ‘xref.el’. It is bound to M-., <menu-bar> <edit> <goto> <xref-find-def>. (xref-find-definitions IDENTIFIER) Find the definition of the identifier at point. With prefix argument or when there’s no identifier at point, prompt for it.If sufficient information is available to determine a unique definition for IDENTIFIER, display it in the selected window. Otherwise, display the list of the possible definitions in a buffer where the user can select from the list. – Raoul HATTERER Feb 13 at 16:55
  • xref-find-definitions returns no definition found even the function is defined – alper Feb 13 at 16:58

To jump to a definition I simply use M-.and to jump back M-, In my init file I have that:

 ;; 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.

    (elpy-module-company elpy-module-eldoc elpy-module-pyvenv elpy-module-highlight-indentation elpy-module-yasnippet elpy-module-django elpy-module-sane-defaults)))
 '(elpy-rpc-python-command "python3")
 '(elpy-rpc-virtualenv-path "~/.virtualenvs/python3.8")

In the menu bar > Elpy > Configure

Elpy Configuration

Emacs.............: 27.1
Elpy..............: 1.35.0
Virtualenv........: None
Interactive Python: python 2.7.16 (/usr/bin/python)
RPC virtualenv....: python3.8 (/Users/raoul/.virtualenvs/python3.8)
 Python...........: python3 3.8.1 (/Users/raoul/.virtualenvs/python3.8/bin/python3)
 Jedi.............: 0.16.0 (0.18.0 available)
 Rope.............: Not found (0.18.0 available)
 Autopep8.........: 1.5 (1.5.5 available)
 Yapf.............: 0.29.0 (0.30.0 available)
 Black............: 19.10b0 (20.8b1 available)
Syntax checker....: Not found (flake8)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.