In python mode (the one that Emacs uses to open python script by default), can I fold the definition of a function?

How can I quickly select the entire definition of a function? (so that I can copy and paste)

If not, which python package/IDE shall I install in emacs? Thanks.

1 Answer 1


For folding, I use Hideshow mode (built-in) with Hydra like this:

 (kbd "M-F")
 (defhydra hydra-fold (global-map "M-F")
   ("h" hs-hide-all "hide all")
   ("s" hs-show-all "show all")
   ("f" hs-toggle-hiding "toggle")))

To mark the current function, press C-M-h to run mark-defun.

These work for nearly any language.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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