comparison lisp/emacs-lisp/lisp.el @ 73832:adc185200028

2006-11-08 Alan Mackenzie <acm@muc.de> * emacs-lisp/lisp.el (beginning-of-defun-raw): Code up the case (eq open-paren-in-column-0-is-defun-start nil) by searching for least nested open-paren.
author Alan Mackenzie <acm@muc.de>
date Wed, 08 Nov 2006 19:19:52 +0000
parents 067115a6e738
children 1d4b1a32fd66 dbe3f29e61d6
comparison
equal deleted inserted replaced
73831:b3f1247fc5c6 73832:adc185200028
206 does not move to the beginning of the line when `defun-prompt-regexp' 206 does not move to the beginning of the line when `defun-prompt-regexp'
207 is non-nil. 207 is non-nil.
208 208
209 If variable `beginning-of-defun-function' is non-nil, its value 209 If variable `beginning-of-defun-function' is non-nil, its value
210 is called as a function to find the defun's beginning." 210 is called as a function to find the defun's beginning."
211 (interactive "p") 211 (interactive "p") ; change this to "P", maybe, if we ever come to pass ARG
212 (if beginning-of-defun-function 212 ; to beginning-of-defun-function.
213 (if (> (setq arg (or arg 1)) 0) 213 (unless arg (setq arg 1)) ; The call might not be interactive.
214 (dotimes (i arg) 214 (cond
215 (funcall beginning-of-defun-function)) 215 (beginning-of-defun-function
216 ;; Better not call end-of-defun-function directly, in case 216 (if (> arg 0)
217 ;; it's not defined. 217 (dotimes (i arg)
218 (end-of-defun (- arg))) 218 (funcall beginning-of-defun-function))
219 (and arg (< arg 0) (not (eobp)) (forward-char 1)) 219 ;; Better not call end-of-defun-function directly, in case
220 ;; it's not defined.
221 (end-of-defun (- arg))))
222
223 ((or defun-prompt-regexp open-paren-in-column-0-is-defun-start)
224 (and (< arg 0) (not (eobp)) (forward-char 1))
220 (and (re-search-backward (if defun-prompt-regexp 225 (and (re-search-backward (if defun-prompt-regexp
221 (concat (if open-paren-in-column-0-is-defun-start 226 (concat (if open-paren-in-column-0-is-defun-start
222 "^\\s(\\|" "") 227 "^\\s(\\|" "")
223 "\\(?:" defun-prompt-regexp "\\)\\s(") 228 "\\(?:" defun-prompt-regexp "\\)\\s(")
224 "^\\s(") 229 "^\\s(")
225 nil 'move (or arg 1)) 230 nil 'move arg)
226 (progn (goto-char (1- (match-end 0)))) t))) 231 (progn (goto-char (1- (match-end 0)))) t))
232
233 (t
234 ;; Column 0 has no significance - so scan forward from BOB to see how
235 ;; nested point is, then carry on from there.
236 (let* ((floor (point-min))
237 (ceiling (point-max))
238 (pps-state (let (syntax-begin-function
239 font-lock-beginning-of-syntax-function)
240 (syntax-ppss)))
241 (nesting-depth (nth 0 pps-state)))
242 (save-restriction
243 (widen)
244 ;; Get outside of any string or comment.
245 (if (nth 8 pps-state)
246 (goto-char (nth 8 pps-state)))
247
248 (cond
249 ((> arg 0)
250 (when (> nesting-depth 0)
251 (up-list (- nesting-depth))
252 (setq arg (1- arg)))
253 ;; We're now outside of any defun.
254 (backward-list arg)
255 (if (< (point) floor) (goto-char floor)))
256
257 ((< arg 0)
258 (cond
259 ((> nesting-depth 0)
260 (up-list nesting-depth)
261 (setq arg (1+ arg)))
262 ((not (looking-at "\\s("))
263 ;; We're between defuns, and not at the start of one.
264 (setq arg (1+ arg))))
265 (forward-list (- arg))
266 (down-list)
267 (backward-char)
268 (if (> (point) ceiling) (goto-char ceiling)))))))))
227 269
228 (defvar end-of-defun-function nil 270 (defvar end-of-defun-function nil
229 "If non-nil, function for function `end-of-defun' to call. 271 "If non-nil, function for function `end-of-defun' to call.
230 This is used to find the end of the defun instead of using the normal 272 This is used to find the end of the defun instead of using the normal
231 recipe (see `end-of-defun'). Major modes can define this if the 273 recipe (see `end-of-defun'). Major modes can define this if the