From 050cc68b402f5998193a6026d0eeeecb9d2cb9c4 Mon Sep 17 00:00:00 2001 From: Lennart Borgman Date: Wed, 11 Apr 2012 04:12:20 +0200 Subject: [PATCH] `narrow-to-defun' fixup * emacs-lisp/lisp.el (narrow-to-defun): `beginning-of-defun' goes to previous function when point is on the first character of a function. Take care of that in `narrow-to-defun'. Fixes: debbugs:6157 --- lisp/ChangeLog | 6 ++++++ lisp/emacs-lisp/lisp.el | 16 +++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 37e014751d7..51afe08d9a4 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,9 @@ +2012-04-11 Lennart Borgman + + * emacs-lisp/lisp.el (narrow-to-defun): `beginning-of-defun' goes + to previous function when point is on the first character of a + function. Take care of that in `narrow-to-defun' (bug#6157). + 2012-04-11 Glenn Morris * vc/vc-bzr.el (vc-bzr-status): Handle all errors, diff --git a/lisp/emacs-lisp/lisp.el b/lisp/emacs-lisp/lisp.el index 4efdc3240cd..bcb7fab026b 100644 --- a/lisp/emacs-lisp/lisp.el +++ b/lisp/emacs-lisp/lisp.el @@ -447,7 +447,21 @@ Optional ARG is ignored." ;; Try first in this order for the sake of languages with nested ;; functions where several can end at the same place as with ;; the offside rule, e.g. Python. - (beginning-of-defun) + + ;; Finding the start of the function is a bit problematic since + ;; `beginning-of-defun' when we are on the first character of + ;; the function might go to the previous function. + ;; + ;; Therefore we first move one character forward and then call + ;; `beginning-of-defun'. However now we must check that we did + ;; not move into the next function. + (let ((here (point))) + (unless (eolp) + (forward-char)) + (beginning-of-defun) + (when (< (point) here) + (goto-char here) + (beginning-of-defun))) (setq beg (point)) (end-of-defun) (setq end (point)) -- 2.11.4.GIT