aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2009-01-31 16:19:46 +0000
committerChong Yidong2009-01-31 16:19:46 +0000
commit45545d6875b5aabef18b62dac9fe7f87cd70528a (patch)
tree595b84cd5736c1cf2955f72c34e2142667860ceb
parenta1f062078e9e69390d006a75555200a537a0dc05 (diff)
downloademacs-45545d6875b5aabef18b62dac9fe7f87cd70528a.tar.gz
emacs-45545d6875b5aabef18b62dac9fe7f87cd70528a.zip
(end-of-defun): Protect against infloops (Bug#2106).
-rw-r--r--lisp/emacs-lisp/lisp.el32
1 files changed, 21 insertions, 11 deletions
diff --git a/lisp/emacs-lisp/lisp.el b/lisp/emacs-lisp/lisp.el
index beb0d85d74a..76141c56274 100644
--- a/lisp/emacs-lisp/lisp.el
+++ b/lisp/emacs-lisp/lisp.el
@@ -342,7 +342,8 @@ is called as a function to find the defun's end."
342 (push-mark)) 342 (push-mark))
343 (if (or (null arg) (= arg 0)) (setq arg 1)) 343 (if (or (null arg) (= arg 0)) (setq arg 1))
344 (while (> arg 0) 344 (while (> arg 0)
345 (let ((pos (point))) 345 (let ((pos (point))
346 retry-point)
346 (end-of-line 1) 347 (end-of-line 1)
347 (beginning-of-defun-raw 1) 348 (beginning-of-defun-raw 1)
348 (while (unless (eobp) 349 (while (unless (eobp)
@@ -350,28 +351,37 @@ is called as a function to find the defun's end."
350 (skip-chars-forward " \t") 351 (skip-chars-forward " \t")
351 (if (looking-at "\\s<\\|\n") 352 (if (looking-at "\\s<\\|\n")
352 (forward-line 1)) 353 (forward-line 1))
353 ;; If we started after the end of the previous function, then 354 ;; If we started after the end of the previous
354 ;; try again with the next one. 355 ;; function, try again with the next one.
355 (when (<= (point) pos) 356 (unless (or (> (point) pos)
356 (or (bobp) (forward-char -1)) 357 (eq (point) retry-point))
357 (beginning-of-defun-raw -1) 358 (or (bobp) (forward-char -1))
358 'try-again)))) 359 (beginning-of-defun-raw -1)
360 (setq retry-point (point)))))
361 ;; Ensure that we move forward.
362 (when (< (point) pos)
363 (goto-char pos)))
359 (setq arg (1- arg))) 364 (setq arg (1- arg)))
360 (while (< arg 0) 365 (while (< arg 0)
361 (let ((pos (point))) 366 (let ((pos (point)))
362 (while (unless (bobp) 367 (while (unless (bobp)
363 (beginning-of-line 1) 368 (beginning-of-line 1)
364 (beginning-of-defun-raw 1) 369 (beginning-of-defun-raw 1)
365 (let ((beg (point))) 370 (let ((beg (point))
371 retry-point)
366 (funcall end-of-defun-function) 372 (funcall end-of-defun-function)
367 (skip-chars-forward " \t") 373 (skip-chars-forward " \t")
368 (if (looking-at "\\s<\\|\n") 374 (if (looking-at "\\s<\\|\n")
369 (forward-line 1)) 375 (forward-line 1))
370 ;; If we started from within the function just found, then 376 ;; If we started from within the function just found,
371 ;; try again with the previous one. 377 ;; try again with the previous one.
372 (when (>= (point) pos) 378 (unless (or (< (point) pos)
379 (eq (point) retry-point))
373 (goto-char beg) 380 (goto-char beg)
374 'try-again))))) 381 (setq retry-point (point))))))
382 ;; Ensure that we move backward.
383 (when (> (point) pos)
384 (goto-char pos)))
375 (setq arg (1+ arg)))) 385 (setq arg (1+ arg))))
376 386
377(defun mark-defun (&optional allow-extend) 387(defun mark-defun (&optional allow-extend)