(end-of-defun): Rewrite, to use the ARG argument to beginning-of-defun-raw.

This commit is contained in:
Stefan Monnier 2009-02-12 04:31:01 +00:00
parent 6bffddf43b
commit f9f34ece3d
2 changed files with 33 additions and 44 deletions

View file

@ -1,5 +1,8 @@
2009-02-12 Stefan Monnier <monnier@iro.umontreal.ca> 2009-02-12 Stefan Monnier <monnier@iro.umontreal.ca>
* emacs-lisp/lisp.el (end-of-defun): Rewrite, to use the ARG argument
to beginning-of-defun-raw.
* emacs-lisp/lisp.el (end-of-defun): Don't skip to next line after * emacs-lisp/lisp.el (end-of-defun): Don't skip to next line after
calling end-of-defun-function if it already moved to BOL. calling end-of-defun-function if it already moved to BOL.

View file

@ -341,50 +341,36 @@ is called as a function to find the defun's end."
(and transient-mark-mode mark-active) (and transient-mark-mode mark-active)
(push-mark)) (push-mark))
(if (or (null arg) (= arg 0)) (setq arg 1)) (if (or (null arg) (= arg 0)) (setq arg 1))
(while (> arg 0) (let ((pos (point))
(let ((pos (point)) (beg (progn (end-of-line 1) (beginning-of-defun-raw 1) (point))))
retry-point) (funcall end-of-defun-function)
(end-of-line 1) (cond
(beginning-of-defun-raw 1) ((> arg 0)
(while (unless (eobp) ;; Moving forward.
(funcall end-of-defun-function) (if (> (point) pos)
(unless (bolp) ;; We already moved forward by one because we started from
(skip-chars-forward " \t") ;; within a function.
(if (looking-at "\\s<\\|\n") (setq arg (1- arg))
(forward-line 1))) ;; We started from after the end of the previous function.
;; If we started after the end of the previous (goto-char pos))
;; function, try again with the next one. (unless (zerop arg)
(unless (or (> (point) pos) (beginning-of-defun-raw (- arg))
(eq (point) retry-point)) (funcall end-of-defun-function)))
(or (bobp) (forward-char -1)) ((< arg 0)
(beginning-of-defun-raw -1) ;; Moving backward.
(setq retry-point (point))))) (if (< (point) pos)
;; Ensure that we move forward. ;; We already moved backward because we started from between
(when (< (point) pos) ;; two functions.
(goto-char pos))) (setq arg (1+ arg))
(setq arg (1- arg))) ;; We started from inside a function.
(while (< arg 0) (goto-char beg))
(let ((pos (point))) (unless (zerop arg)
(while (unless (bobp) (beginning-of-defun-raw (- arg))
(beginning-of-line 1) (funcall end-of-defun-function))))
(beginning-of-defun-raw 1) (unless (bolp)
(let ((beg (point)) (skip-chars-forward " \t")
retry-point) (if (looking-at "\\s<\\|\n")
(funcall end-of-defun-function) (forward-line 1)))))
(unless (bolp)
(skip-chars-forward " \t")
(if (looking-at "\\s<\\|\n")
(forward-line 1)))
;; If we started from within the function just found,
;; try again with the previous one.
(unless (or (< (point) pos)
(eq (point) retry-point))
(goto-char beg)
(setq retry-point (point))))))
;; Ensure that we move backward.
(when (> (point) pos)
(goto-char pos)))
(setq arg (1+ arg))))
(defun mark-defun (&optional allow-extend) (defun mark-defun (&optional allow-extend)
"Put mark at end of this defun, point at beginning. "Put mark at end of this defun, point at beginning.