Here is a variation of the last patch that behaves better when the point is in empty lines above a defun. Another entirely different approach to solve this issue without redefining mark-defun could be to differentiate: class M: def m(): pass* and class M: def m(): pass * (where * stands for the point) In the second case, C-M-h will select the class, while in the first it will select the method. Then, there would be no need to hack mark-defun. What do you think?