comparison lisp/emacs-lisp/lisp.el @ 53752:592ddd618234

(beginning-of-defun-raw, end-of-defun): Iterate the hook function if arg is given. (mark-defun, narrow-to-defun): Change order of finding the limits.
author Richard M. Stallman <rms@gnu.org>
date Thu, 29 Jan 2004 17:56:42 +0000
parents 695cf19ef79e
children 95ee18354a3a
comparison
equal deleted inserted replaced
53751:e7725f50a432 53752:592ddd618234
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 (funcall beginning-of-defun-function) 191 (dotimes (i (or arg 1))
192 (funcall beginning-of-defun-function))
192 (and arg (< arg 0) (not (eobp)) (forward-char 1)) 193 (and arg (< arg 0) (not (eobp)) (forward-char 1))
193 (and (re-search-backward (if defun-prompt-regexp 194 (and (re-search-backward (if defun-prompt-regexp
194 (concat (if open-paren-in-column-0-is-defun-start 195 (concat (if open-paren-in-column-0-is-defun-start
195 "^\\s(\\|" "") 196 "^\\s(\\|" "")
196 "\\(?:" defun-prompt-regexp "\\)\\s(") 197 "\\(?:" defun-prompt-regexp "\\)\\s(")
217 218
218 If variable `end-of-defun-function' is non-nil, its value 219 If variable `end-of-defun-function' is non-nil, its value
219 is called as a function to find the defun's end." 220 is called as a function to find the defun's end."
220 (interactive "p") 221 (interactive "p")
221 (if end-of-defun-function 222 (if end-of-defun-function
222 (funcall end-of-defun-function) 223 (dotimes (i (or arg 1))
224 (funcall end-of-defun-function))
223 (if (or (null arg) (= arg 0)) (setq arg 1)) 225 (if (or (null arg) (= arg 0)) (setq arg 1))
224 (let ((first t)) 226 (let ((first t))
225 (while (and (> arg 0) (< (point) (point-max))) 227 (while (and (> arg 0) (< (point) (point-max)))
226 (let ((pos (point)) npos) 228 (let ((pos (point)) npos)
227 (while (progn 229 (while (progn
265 (save-excursion 267 (save-excursion
266 (goto-char (mark)) 268 (goto-char (mark))
267 (end-of-defun) 269 (end-of-defun)
268 (point)))) 270 (point))))
269 (t 271 (t
272 ;; Do it in this order for the sake of languages with nested
273 ;; functions where several can end at the same place as with
274 ;; the offside rule, e.g. Python.
270 (push-mark (point)) 275 (push-mark (point))
276 (beginning-of-defun)
277 (push-mark (point) nil t)
271 (end-of-defun) 278 (end-of-defun)
272 (push-mark (point) nil t) 279 (exchange-point-and-mark)
273 (beginning-of-defun)
274 (re-search-backward "^\n" (- (point) 1) t)))) 280 (re-search-backward "^\n" (- (point) 1) t))))
275 281
276 (defun narrow-to-defun (&optional arg) 282 (defun narrow-to-defun (&optional arg)
277 "Make text outside current defun invisible. 283 "Make text outside current defun invisible.
278 The defun visible is the one that contains point or follows point. 284 The defun visible is the one that contains point or follows point.
279 Optional ARG is ignored." 285 Optional ARG is ignored."
280 (interactive) 286 (interactive)
281 (save-excursion 287 (save-excursion
282 (widen) 288 (widen)
283 (end-of-defun) 289 ;; Do it in this order for the sake of languages with nested
284 (let ((end (point))) 290 ;; functions where several can end at the same place as with the
285 (beginning-of-defun) 291 ;; offside rule, e.g. Python.
286 (narrow-to-region (point) end)))) 292 (beginning-of-defun)
293 (let ((beg (point)))
294 (end-of-defun)
295 (narrow-to-region beg (point)))))
287 296
288 (defun insert-parentheses (arg) 297 (defun insert-parentheses (arg)
289 "Enclose following ARG sexps in parentheses. Leave point after open-paren. 298 "Enclose following ARG sexps in parentheses. Leave point after open-paren.
290 A negative ARG encloses the preceding ARG sexps instead. 299 A negative ARG encloses the preceding ARG sexps instead.
291 No argument is equivalent to zero: just insert `()' and leave point between. 300 No argument is equivalent to zero: just insert `()' and leave point between.