Not beeing a user of elpy but looking at elpys source code, I would say you have several options to do this (there are proably more).
Calling elpy-goto-definition
results in a call to elpy-goto-location
which at its end calls (recenter 0)
and this 0
is the culprit.
3 completely separate ways to change that:
first
create a new function (my-elpy-goto-definition) which just calls elpy-goto-definition
and then does (recenter)
without that 0
. to use it you always call my-elpy-goto-definition
instead of elpy-goto-definition
(least intrusive solution, Problem: you need to redefine your shortcut keys)
second
copy and paste the whole function elpy-goto-location
then remove the offending 0
and re-eval that defun, effectively replacing the old function with your modified one. (very intrusive solution, Problem: you will never automatically receive code updates/fixes to that function, you have to include them manually)
third
write an advice to either elpy-goto-definition
or elpy-goto-location
(depends on how globaly you want this behavior), which calls an (recenter)
after that function has run. (medium intrusive solution, works automatic, without changing keybindings, I'd probably go with this).
Example code for third (advicing elpy-goto-location
):
(defun my-recenter-elpy-goto (&rest r)
(recenter))
(advice-add #'elpy-goto-location :after #'my-recenter-elpy-goto)