summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp/lisp.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/emacs-lisp/lisp.el')
-rw-r--r--lisp/emacs-lisp/lisp.el27
1 files changed, 18 insertions, 9 deletions
diff --git a/lisp/emacs-lisp/lisp.el b/lisp/emacs-lisp/lisp.el
index acae1a0b0a9..c8d05a084bb 100644
--- a/lisp/emacs-lisp/lisp.el
+++ b/lisp/emacs-lisp/lisp.el
@@ -375,7 +375,10 @@ does not move to the beginning of the line when `defun-prompt-regexp'
is non-nil.
If variable `beginning-of-defun-function' is non-nil, its value
-is called as a function to find the defun's beginning."
+is called as a function to find the defun's beginning.
+
+Return non-nil if this function successfully found the beginning
+of a defun, nil if it failed to find one."
(interactive "^p") ; change this to "P", maybe, if we ever come to pass ARG
; to beginning-of-defun-function.
(unless arg (setq arg 1))
@@ -543,6 +546,7 @@ report errors as appropriate for this kind of usage."
(push-mark))
(if (or (null arg) (= arg 0)) (setq arg 1))
(let ((pos (point))
+ (success nil)
(beg (progn (when end-of-defun-moves-to-eol
(end-of-line 1))
(beginning-of-defun-raw 1) (point)))
@@ -567,9 +571,12 @@ report errors as appropriate for this kind of usage."
(setq arg (1- arg))
;; We started from after the end of the previous function.
(goto-char pos))
+ ;; At this point, point either didn't move (because we started
+ ;; in between two defun's), or is at the end of a defun
+ ;; (because we started in the middle of a defun).
(unless (zerop arg)
- (beginning-of-defun-raw (- arg))
- (funcall end-of-defun-function)))
+ (when (setq success (beginning-of-defun-raw (- arg)))
+ (funcall end-of-defun-function))))
((< arg 0)
;; Moving backward.
(if (< (point) pos)
@@ -579,16 +586,18 @@ report errors as appropriate for this kind of usage."
;; We started from inside a function.
(goto-char beg))
(unless (zerop arg)
- (beginning-of-defun-raw (- arg))
- (setq beg (point))
- (funcall end-of-defun-function))))
+ (when (setq success (beginning-of-defun-raw (- arg)))
+ (setq beg (point))
+ (funcall end-of-defun-function)))))
(funcall skip)
- (while (and (< arg 0) (>= (point) pos))
+ (while (and (< arg 0) (>= (point) pos) success)
;; 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 success (beginning-of-defun-raw (- arg)))
+ ;; If we successfully moved pass point, or there is no further
+ ;; defun beginnings anymore, stop.
+ (if (or (>= (point) beg) (not success))
(setq arg 0)
(setq beg (point))
(funcall end-of-defun-function)