0

I would like to navigate quickly between classes in Python code. I'm looking for a command to go to the next / previous class so I can bind that to a key sequence. This question is not about graphical navigation tools like treemacs.

It might be interesting to hear about things like hydras too, but that's also not the focus of this question.

1

What I found so far and use to navigate between classes in python-mode:

First C-M-u which runs the command python-nav-backward-up-list to navigate up to class definition. After that C-M-a (beginning-of-defun) and C-M-e (end-of-defun) to navigate to previous and next class definition respectively.

| improve this answer | |
0

Based on @muffinmad's answer:

(defun my/python-navigate-up-to-class-statement ()
  (interactive)
  (let ((pos nil))
    (while (not (equal pos (point)))
      (setf pos (point))
      (python-nav-backward-up-list))))

(defun my/python-navigate-to-next-python-class ()
  (interactive)
  (my/python-navigate-up-to-class-statement)
  (end-of-defun)
  (end-of-defun)
  (my/python-navigate-up-to-class-statement))

(defun my/python-navigate-to-previous-python-class ()
  (interactive)
  (my/python-navigate-up-to-class-statement)
  (beginning-of-defun))
| improve this answer | |

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.