From: [email-masked] (Fabián Ezequiel Gallina)
To: [email-masked]
Date: Wed, 25 Dec 2013 17:07:30 -0300
List-Id: <debbugs-submit.debbugs.gnu.org>

Unfortunately, this seems like intended behavior (and I do agree that I
don't like it either). I suggest you raise this to emacs-devel if you
really want to change default behavior.

Check the `mark-defun' definition at
emacs/trunk/lisp/emacs-lisp/lisp.el:427 and you'll see that it does have
an explicit call to `beginning-of-defun' for "languages with nested
functions... e.g. Python."

A similar approach seems to takes place in `narrow-to-defun' at
emacs/trunk/lisp/emacs-lisp/lisp.el:470 which causes this.

From my side I've been narrowing defuns by calling `end-of-line' first
if I'm looking at it. You could rebind the `narrow-to-defun' command in
the `python-mode-map' to the following command:

    (defun python-narrow-to-defun (&optional _arg)
      "Make text outside current defun invisible.
    The defun visible is the one that contains point or follows
    point.  Optional ARG is ignored."
      (interactive)
      (save-excursion
        (end-of-line 1)
        (narrow-to-defun)))

Regards,
Fabián.