aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/ChangeLog3
-rw-r--r--lisp/emacs-lisp/lisp.el74
2 files changed, 33 insertions, 44 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 73f01a0daa6..614644b4940 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,8 @@
12009-02-12 Stefan Monnier <monnier@iro.umontreal.ca> 12009-02-12 Stefan Monnier <monnier@iro.umontreal.ca>
2 2
3 * emacs-lisp/lisp.el (end-of-defun): Rewrite, to use the ARG argument
4 to beginning-of-defun-raw.
5
3 * emacs-lisp/lisp.el (end-of-defun): Don't skip to next line after 6 * emacs-lisp/lisp.el (end-of-defun): Don't skip to next line after
4 calling end-of-defun-function if it already moved to BOL. 7 calling end-of-defun-function if it already moved to BOL.
5 8
diff --git a/lisp/emacs-lisp/lisp.el b/lisp/emacs-lisp/lisp.el
index b53c98acb7e..8c263881499 100644
--- a/lisp/emacs-lisp/lisp.el
+++ b/lisp/emacs-lisp/lisp.el
@@ -341,50 +341,36 @@ is called as a function to find the defun's end."
341 (and transient-mark-mode mark-active) 341 (and transient-mark-mode mark-active)
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 (let ((pos (point))
345 (let ((pos (point)) 345 (beg (progn (end-of-line 1) (beginning-of-defun-raw 1) (point))))
346 retry-point) 346 (funcall end-of-defun-function)
347 (end-of-line 1) 347 (cond
348 (beginning-of-defun-raw 1) 348 ((> arg 0)
349 (while (unless (eobp) 349 ;; Moving forward.
350 (funcall end-of-defun-function) 350 (if (> (point) pos)
351 (unless (bolp) 351 ;; We already moved forward by one because we started from
352 (skip-chars-forward " \t") 352 ;; within a function.
353 (if (looking-at "\\s<\\|\n") 353 (setq arg (1- arg))
354 (forward-line 1))) 354 ;; We started from after the end of the previous function.
355 ;; If we started after the end of the previous 355 (goto-char pos))
356 ;; function, try again with the next one. 356 (unless (zerop arg)
357 (unless (or (> (point) pos) 357 (beginning-of-defun-raw (- arg))
358 (eq (point) retry-point)) 358 (funcall end-of-defun-function)))
359 (or (bobp) (forward-char -1)) 359 ((< arg 0)
360 (beginning-of-defun-raw -1) 360 ;; Moving backward.
361 (setq retry-point (point))))) 361 (if (< (point) pos)
362 ;; Ensure that we move forward. 362 ;; We already moved backward because we started from between
363 (when (< (point) pos) 363 ;; two functions.
364 (goto-char pos))) 364 (setq arg (1+ arg))
365 (setq arg (1- arg))) 365 ;; We started from inside a function.
366 (while (< arg 0) 366 (goto-char beg))
367 (let ((pos (point))) 367 (unless (zerop arg)
368 (while (unless (bobp) 368 (beginning-of-defun-raw (- arg))
369 (beginning-of-line 1) 369 (funcall end-of-defun-function))))
370 (beginning-of-defun-raw 1) 370 (unless (bolp)
371 (let ((beg (point)) 371 (skip-chars-forward " \t")
372 retry-point) 372 (if (looking-at "\\s<\\|\n")
373 (funcall end-of-defun-function) 373 (forward-line 1)))))
374 (unless (bolp)
375 (skip-chars-forward " \t")
376 (if (looking-at "\\s<\\|\n")
377 (forward-line 1)))
378 ;; If we started from within the function just found,
379 ;; try again with the previous one.
380 (unless (or (< (point) pos)
381 (eq (point) retry-point))
382 (goto-char beg)
383 (setq retry-point (point))))))
384 ;; Ensure that we move backward.
385 (when (> (point) pos)
386 (goto-char pos)))
387 (setq arg (1+ arg))))
388 374
389(defun mark-defun (&optional allow-extend) 375(defun mark-defun (&optional allow-extend)
390 "Put mark at end of this defun, point at beginning. 376 "Put mark at end of this defun, point at beginning.