# HG changeset patch # User Stefan Monnier # Date 1195769542 0 # Node ID 480a058ecb2f5e76c41b2ef1a92e6563beb7f844 # Parent 8121805fdbcb870ad07c64cdbe4d57183643bd44 (beginning-of-defun-raw): Pass `arg' down to beginning-of-defun-function. diff -r 8121805fdbcb -r 480a058ecb2f etc/NEWS --- a/etc/NEWS Thu Nov 22 21:12:54 2007 +0000 +++ b/etc/NEWS Thu Nov 22 22:12:22 2007 +0000 @@ -383,6 +383,9 @@ * Lisp Changes in Emacs 23.1 +** `beginning-of-defun-function' now takes one argument, the count + given to `beginning-of-defun'. + +++ ** New function `match-substitute-replacement' returns the result of `replace-match' without actually using it in the buffer. diff -r 8121805fdbcb -r 480a058ecb2f lisp/ChangeLog --- a/lisp/ChangeLog Thu Nov 22 21:12:54 2007 +0000 +++ b/lisp/ChangeLog Thu Nov 22 22:12:22 2007 +0000 @@ -1,3 +1,8 @@ +2007-11-22 Stefan Monnier + + * emacs-lisp/lisp.el (beginning-of-defun-raw): Pass `arg' down to + beginning-of-defun-function. + 2007-11-22 Reiner Steib * mail/hashcash.el: Move from ../gnus. Add hashcash payments to email. diff -r 8121805fdbcb -r 480a058ecb2f lisp/emacs-lisp/lisp.el --- a/lisp/emacs-lisp/lisp.el Thu Nov 22 21:12:54 2007 +0000 +++ b/lisp/emacs-lisp/lisp.el Thu Nov 22 22:12:22 2007 +0000 @@ -175,9 +175,10 @@ if defining `defun-prompt-regexp' is not sufficient to handle the mode's needs. -The function (of no args) should go to the line on which the current -defun starts, and return non-nil, or should return nil if it can't -find the beginning.") +The function takes the same argument as `beginning-of-defun' and should +behave similarly, returning non-nil if it found the beginning of a defun. +Ideally it should move to a point right before an open-paren which encloses +the body of the defun.") (defun beginning-of-defun (&optional arg) "Move backward to the beginning of a defun. @@ -218,12 +219,22 @@ (unless arg (setq arg 1)) (cond (beginning-of-defun-function - (if (> arg 0) - (dotimes (i arg) - (funcall beginning-of-defun-function)) - ;; Better not call end-of-defun-function directly, in case - ;; it's not defined. - (end-of-defun (- arg)))) + (condition-case nil + (funcall beginning-of-defun-function arg) + ;; We used to define beginning-of-defun-function as taking no argument + ;; but that makes it impossible to implement correct forward motion: + ;; we used to use end-of-defun for that, but it's not supposed to do + ;; the same thing (it moves to the end of a defun not to the beginning + ;; of the next). + ;; In case the beginning-of-defun-function uses the old calling + ;; convention, fallback on the old implementation. + (wrong-number-of-arguments + (if (> arg 0) + (dotimes (i arg) + (funcall beginning-of-defun-function)) + ;; Better not call end-of-defun-function directly, in case + ;; it's not defined. + (end-of-defun (- arg)))))) ((or defun-prompt-regexp open-paren-in-column-0-is-defun-start) (and (< arg 0) (not (eobp)) (forward-char 1))