comparison lisp/emacs-lisp/lisp.el @ 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 592ddd618234
children 980615cc9a94
comparison
equal deleted inserted replaced
54875:21c1ccea9533 54876:95ee18354a3a
1 ;;; lisp.el --- Lisp editing commands for Emacs 1 ;;; lisp.el --- Lisp editing commands for Emacs
2 2
3 ;; Copyright (C) 1985, 1986, 1994, 2000 Free Software Foundation, Inc. 3 ;; Copyright (C) 1985, 86, 1994, 2000, 2004 Free Software Foundation, Inc.
4 4
5 ;; Maintainer: FSF 5 ;; Maintainer: FSF
6 ;; Keywords: lisp, languages 6 ;; Keywords: lisp, languages
7 7
8 ;; This file is part of GNU Emacs. 8 ;; This file is part of GNU Emacs.
186 186
187 If variable `beginning-of-defun-function' is non-nil, its value 187 If variable `beginning-of-defun-function' is non-nil, its value
188 is called as a function to find the defun's beginning." 188 is called as a function to find the defun's beginning."
189 (interactive "p") 189 (interactive "p")
190 (if beginning-of-defun-function 190 (if beginning-of-defun-function
191 (dotimes (i (or arg 1)) 191 (if (> (setq arg (or arg 1)) 0)
192 (funcall beginning-of-defun-function)) 192 (dotimes (i arg)
193 (funcall beginning-of-defun-function))
194 ;; Better not call end-of-defun-function directly, in case
195 ;; it's not defined.
196 (end-of-defun (- arg)))
193 (and arg (< arg 0) (not (eobp)) (forward-char 1)) 197 (and arg (< arg 0) (not (eobp)) (forward-char 1))
194 (and (re-search-backward (if defun-prompt-regexp 198 (and (re-search-backward (if defun-prompt-regexp
195 (concat (if open-paren-in-column-0-is-defun-start 199 (concat (if open-paren-in-column-0-is-defun-start
196 "^\\s(\\|" "") 200 "^\\s(\\|" "")
197 "\\(?:" defun-prompt-regexp "\\)\\s(") 201 "\\(?:" defun-prompt-regexp "\\)\\s(")
217 `beginning-of-defun'. 221 `beginning-of-defun'.
218 222
219 If variable `end-of-defun-function' is non-nil, its value 223 If variable `end-of-defun-function' is non-nil, its value
220 is called as a function to find the defun's end." 224 is called as a function to find the defun's end."
221 (interactive "p") 225 (interactive "p")
226 (if (or (null arg) (= arg 0)) (setq arg 1))
222 (if end-of-defun-function 227 (if end-of-defun-function
223 (dotimes (i (or arg 1)) 228 (if (> arg 0)
224 (funcall end-of-defun-function)) 229 (dotimes (i arg)
225 (if (or (null arg) (= arg 0)) (setq arg 1)) 230 (funcall end-of-defun-function))
231 ;; Better not call beginning-of-defun-function
232 ;; directly, in case it's not defined.
233 (beginning-of-defun (- arg)))
226 (let ((first t)) 234 (let ((first t))
227 (while (and (> arg 0) (< (point) (point-max))) 235 (while (and (> arg 0) (< (point) (point-max)))
228 (let ((pos (point)) npos) 236 (let ((pos (point)))
229 (while (progn 237 (while (progn
230 (if (and first 238 (if (and first
231 (progn 239 (progn
232 (end-of-line 1) 240 (end-of-line 1)
233 (beginning-of-defun-raw 1))) 241 (beginning-of-defun-raw 1)))