comparison lisp/emacs-lisp/lisp.el @ 90732:bc10a33dd40b

Merge from emacs--devo--0 Patches applied: * emacs--devo--0 (patch 563-582) - Update from CVS - Merge from gnus--rel--5.10 * gnus--rel--5.10 (patch 177-185) - Merge from emacs--devo--0 - Update from CVS Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-158
author Miles Bader <miles@gnu.org>
date Mon, 01 Jan 2007 03:21:06 +0000
parents 6588c6259dfb ba0b39efd315
children 95d0cdf160ea
comparison
equal deleted inserted replaced
90731:a6c97c25a666 90732:bc10a33dd40b
183 "Move backward to the beginning of a defun. 183 "Move backward to the beginning of a defun.
184 With ARG, do it that many times. Negative arg -N 184 With ARG, do it that many times. Negative arg -N
185 means move forward to Nth following beginning of defun. 185 means move forward to Nth following beginning of defun.
186 Returns t unless search stops due to beginning or end of buffer. 186 Returns t unless search stops due to beginning or end of buffer.
187 187
188 Normally a defun starts when there is a char with open-parenthesis
189 syntax at the beginning of a line. If `defun-prompt-regexp' is
190 non-nil, then a string which matches that regexp may precede the
191 open-parenthesis, and point ends up at the beginning of the line.
192
193 If variable `beginning-of-defun-function' is non-nil, its value 188 If variable `beginning-of-defun-function' is non-nil, its value
194 is called as a function to find the defun's beginning." 189 is called as a function to find the defun's beginning.
190
191 Normally a defun is assumed to start where there is a char with
192 open-parenthesis syntax at the beginning of a line. If
193 `defun-prompt-regexp' is non-nil, then a string which matches
194 that regexp may precede the open-parenthesis, and point ends up
195 at the beginning of the line.
196
197 If `defun-prompt-regexp' and `open-paren-in-column-0-is-defun-start'
198 are both nil, the function instead finds an open-paren at the
199 outermost level."
195 (interactive "p") 200 (interactive "p")
196 (or (not (eq this-command 'beginning-of-defun)) 201 (or (not (eq this-command 'beginning-of-defun))
197 (eq last-command 'beginning-of-defun) 202 (eq last-command 'beginning-of-defun)
198 (and transient-mark-mode mark-active) 203 (and transient-mark-mode mark-active)
199 (push-mark)) 204 (push-mark))
206 does not move to the beginning of the line when `defun-prompt-regexp' 211 does not move to the beginning of the line when `defun-prompt-regexp'
207 is non-nil. 212 is non-nil.
208 213
209 If variable `beginning-of-defun-function' is non-nil, its value 214 If variable `beginning-of-defun-function' is non-nil, its value
210 is called as a function to find the defun's beginning." 215 is called as a function to find the defun's beginning."
211 (interactive "p") ; change this to "P", maybe, if we ever come to pass ARG 216 (interactive "p") ; change this to "P", maybe, if we ever come to pass ARG
212 ; to beginning-of-defun-function. 217 ; to beginning-of-defun-function.
213 (unless arg (setq arg 1)) ; The call might not be interactive. 218 (unless arg (setq arg 1))
214 (cond 219 (cond
215 (beginning-of-defun-function 220 (beginning-of-defun-function
216 (if (> arg 0) 221 (if (> arg 0)
217 (dotimes (i arg) 222 (dotimes (i arg)
218 (funcall beginning-of-defun-function)) 223 (funcall beginning-of-defun-function))
228 "\\(?:" defun-prompt-regexp "\\)\\s(") 233 "\\(?:" defun-prompt-regexp "\\)\\s(")
229 "^\\s(") 234 "^\\s(")
230 nil 'move arg) 235 nil 'move arg)
231 (progn (goto-char (1- (match-end 0)))) t)) 236 (progn (goto-char (1- (match-end 0)))) t))
232 237
238 ;; If open-paren-in-column-0-is-defun-start and defun-prompt-regexp
239 ;; are both nil, column 0 has no significance - so scan forward
240 ;; from BOB to see how nested point is, then carry on from there.
241 ;;
242 ;; It is generally not a good idea to land up here, because the
243 ;; call to scan-lists below can be extremely slow. This is because
244 ;; back_comment in syntax.c may have to scan from bob to find the
245 ;; beginning of each comment. Fixing this is not trivial -- cyd.
246
247 ((eq arg 0))
233 (t 248 (t
234 ;; Column 0 has no significance - so scan forward from BOB to see how 249 (let ((floor (point-min))
235 ;; nested point is, then carry on from there. 250 (ceiling (point-max))
236 (let* ((floor (point-min)) 251 (arg-+ve (> arg 0)))
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 252 (save-restriction
243 (widen) 253 (widen)
244 ;; Get outside of any string or comment. 254 (let ((ppss (let (syntax-begin-function
245 (if (nth 8 pps-state) 255 font-lock-beginning-of-syntax-function)
246 (goto-char (nth 8 pps-state))) 256 (syntax-ppss)))
247 257 ;; position of least enclosing paren, or nil.
248 (cond 258 encl-pos)
249 ((> arg 0) 259 ;; Back out of any comment/string, so that encl-pos will always
250 (when (> nesting-depth 0) 260 ;; become nil if we're at top-level.
251 (up-list (- nesting-depth)) 261 (when (nth 8 ppss)
252 (setq arg (1- arg))) 262 (goto-char (nth 8 ppss))
253 ;; We're now outside of any defun. 263 (setq ppss (syntax-ppss))) ; should be fast, due to cache.
254 (backward-list arg) 264 (setq encl-pos (syntax-ppss-toplevel-pos ppss))
255 (if (< (point) floor) (goto-char floor))) 265 (if encl-pos (goto-char encl-pos))
256 266
257 ((< arg 0) 267 (and encl-pos arg-+ve (setq arg (1- arg)))
258 (cond 268 (and (not encl-pos) (not arg-+ve) (not (looking-at "\\s("))
259 ((> nesting-depth 0) 269 (setq arg (1+ arg)))
260 (up-list nesting-depth) 270
261 (setq arg (1+ arg))) 271 (condition-case nil ; to catch crazy parens.
262 ((not (looking-at "\\s(")) 272 (progn
263 ;; We're between defuns, and not at the start of one. 273 (goto-char (scan-lists (point) (- arg) 0))
264 (setq arg (1+ arg)))) 274 (if arg-+ve
265 (forward-list (- arg)) 275 (if (>= (point) floor)
266 (down-list) 276 t
267 (backward-char) 277 (goto-char floor)
268 (if (> (point) ceiling) (goto-char ceiling))))))))) 278 nil)
279 ;; forward to next (, or trigger the c-c
280 (goto-char (1- (scan-lists (point) 1 -1)))
281 (if (<= (point) ceiling)
282 t
283 (goto-char ceiling)
284 nil)))
285 (error
286 (goto-char (if arg-+ve floor ceiling))
287 nil))))))))
269 288
270 (defvar end-of-defun-function nil 289 (defvar end-of-defun-function nil
271 "If non-nil, function for function `end-of-defun' to call. 290 "If non-nil, function for function `end-of-defun' to call.
272 This is used to find the end of the defun instead of using the normal 291 This is used to find the end of the defun instead of using the normal
273 recipe (see `end-of-defun'). Major modes can define this if the 292 recipe (see `end-of-defun'). Major modes can define this if the