changeset 54876:95ee18354a3a

(beginning-of-defun-raw, end-of-defun): Correctly handle negative arguments when calling hook functions.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Wed, 14 Apr 2004 18:20:23 +0000
parents 21c1ccea9533
children 1bf7ef48f54f
files lisp/emacs-lisp/lisp.el
diffstat 1 files changed, 15 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/emacs-lisp/lisp.el	Wed Apr 14 18:12:05 2004 +0000
+++ b/lisp/emacs-lisp/lisp.el	Wed Apr 14 18:20:23 2004 +0000
@@ -1,6 +1,6 @@
 ;;; lisp.el --- Lisp editing commands for Emacs
 
-;; Copyright (C) 1985, 1986, 1994, 2000 Free Software Foundation, Inc.
+;; Copyright (C) 1985, 86, 1994, 2000, 2004  Free Software Foundation, Inc.
 
 ;; Maintainer: FSF
 ;; Keywords: lisp, languages
@@ -188,8 +188,12 @@
 is called as a function to find the defun's beginning."
   (interactive "p")
   (if beginning-of-defun-function
-      (dotimes (i (or arg 1))
-	(funcall beginning-of-defun-function))
+      (if (> (setq arg (or arg 1)) 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)))
     (and arg (< arg 0) (not (eobp)) (forward-char 1))
     (and (re-search-backward (if defun-prompt-regexp
 				 (concat (if open-paren-in-column-0-is-defun-start
@@ -219,13 +223,17 @@
 If variable `end-of-defun-function' is non-nil, its value
 is called as a function to find the defun's end."
   (interactive "p")
+  (if (or (null arg) (= arg 0)) (setq arg 1))
   (if end-of-defun-function
-      (dotimes (i (or arg 1))
-	(funcall end-of-defun-function))
-    (if (or (null arg) (= arg 0)) (setq arg 1))
+      (if (> arg 0)
+	  (dotimes (i arg)
+	    (funcall end-of-defun-function))
+	;; Better not call beginning-of-defun-function
+	;; directly, in case it's not defined.
+	(beginning-of-defun (- arg)))
     (let ((first t))
       (while (and (> arg 0) (< (point) (point-max)))
-	(let ((pos (point)) npos)
+	(let ((pos (point)))
 	  (while (progn
 		   (if (and first
 			    (progn