diff options
author | Stefan Monnier <monnier@iro.umontreal.ca> | 2014-05-20 14:55:41 -0400 |
---|---|---|
committer | Stefan Monnier <monnier@iro.umontreal.ca> | 2014-05-20 14:55:41 -0400 |
commit | 7b952d6142f5c611312761c0ad853deb453bbe88 (patch) | |
tree | 887222c16090a7dedcf8895e400f877f1aae29b3 /lisp/emacs-lisp | |
parent | ebdc80316a464f7e6f827f8b79570e47a8ef4812 (diff) | |
download | emacs-7b952d6142f5c611312761c0ad853deb453bbe88.tar.gz emacs-7b952d6142f5c611312761c0ad853deb453bbe88.tar.bz2 emacs-7b952d6142f5c611312761c0ad853deb453bbe88.zip |
* lisp/emacs-lisp/lisp.el (end-of-defun): Ensure we move.
Fixes: debbugs:17274
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r-- | lisp/emacs-lisp/lisp.el | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/lisp/emacs-lisp/lisp.el b/lisp/emacs-lisp/lisp.el index 0487515a142..80366db33d5 100644 --- a/lisp/emacs-lisp/lisp.el +++ b/lisp/emacs-lisp/lisp.el @@ -373,16 +373,18 @@ is called as a function to find the defun's end." (push-mark)) (if (or (null arg) (= arg 0)) (setq arg 1)) (let ((pos (point)) - (beg (progn (end-of-line 1) (beginning-of-defun-raw 1) (point)))) + (beg (progn (end-of-line 1) (beginning-of-defun-raw 1) (point))) + (skip (lambda () + ;; When comparing point against pos, we want to consider that if + ;; point was right after the end of the function, it's still + ;; considered as "in that function". + ;; E.g. `eval-defun' from right after the last close-paren. + (unless (bolp) + (skip-chars-forward " \t") + (if (looking-at "\\s<\\|\n") + (forward-line 1)))))) (funcall end-of-defun-function) - ;; When comparing point against pos, we want to consider that if - ;; point was right after the end of the function, it's still - ;; considered as "in that function". - ;; E.g. `eval-defun' from right after the last close-paren. - (unless (bolp) - (skip-chars-forward " \t") - (if (looking-at "\\s<\\|\n") - (forward-line 1))) + (funcall skip) (cond ((> arg 0) ;; Moving forward. @@ -405,11 +407,19 @@ is called as a function to find the defun's end." (goto-char beg)) (unless (zerop arg) (beginning-of-defun-raw (- arg)) + (setq beg (point)) (funcall end-of-defun-function)))) - (unless (bolp) - (skip-chars-forward " \t") - (if (looking-at "\\s<\\|\n") - (forward-line 1))))) + (funcall skip) + (while (and (< arg 0) (>= (point) pos)) + ;; We intended to move backward, but this ended up not doing so: + ;; Try harder! + (goto-char beg) + (beginning-of-defun-raw (- arg)) + (if (>= (point) beg) + (setq arg 0) + (setq beg (point)) + (funcall end-of-defun-function) + (funcall skip))))) (defun mark-defun (&optional allow-extend) "Put mark at end of this defun, point at beginning. |