comparison lisp/lisp.el @ 4696:ecc468b62551

funcall beginning-of-defun-function arg
author andreas.roehler@online.de
date Mon, 21 Sep 2009 21:40:35 +0200
parents c136144fe765
children 7b90173970ad
comparison
equal deleted inserted replaced
4695:fee33ab25966 4696:ecc468b62551
153 With argument, kill that many sexps before the cursor. 153 With argument, kill that many sexps before the cursor.
154 Negative arg -N means kill N sexps after the cursor." 154 Negative arg -N means kill N sexps after the cursor."
155 (interactive "p") 155 (interactive "p")
156 (kill-sexp (- (or arg 1)))) 156 (kill-sexp (- (or arg 1))))
157 157
158
159 ;; derived stuff from GNU Emacs
160 (defvar beginning-of-defun-function nil
161 "If non-nil, function for `beginning-of-defun-raw' to call.
162 This is used to find the beginning of the defun instead of using the
163 normal recipe (see `beginning-of-defun'). Modes can define this
164 if defining `defun-prompt-regexp' is not sufficient to handle the mode's
165 needs.")
166
167 (defvar end-of-defun-function nil
168 "If non-nil, function for `end-of-defun' to call.
169 This is used to find the end of the defun instead of using the normal
170 recipe (see `end-of-defun'). Modes can define this if the
171 normal method is not appropriate.")
172
158 (defun beginning-of-defun (&optional arg) 173 (defun beginning-of-defun (&optional arg)
159 "Move backward to the beginning of a defun. 174 "Move backward to the beginning of a defun.
160 With argument, do it that many times. Negative arg -N 175 With argument, do it that many times. Negative arg -N
161 means move forward to Nth following beginning of defun. 176 means move forward to Nth following beginning of defun.
162 Returns t unless search stops due to beginning or end of buffer. 177 Returns t unless search stops due to beginning or end of buffer.
173 (defun beginning-of-defun-raw (&optional arg) 188 (defun beginning-of-defun-raw (&optional arg)
174 "Move point to the character that starts a defun. 189 "Move point to the character that starts a defun.
175 This is identical to beginning-of-defun, except that point does not move 190 This is identical to beginning-of-defun, except that point does not move
176 to the beginning of the line when `defun-prompt-regexp' is non-nil." 191 to the beginning of the line when `defun-prompt-regexp' is non-nil."
177 (interactive "p") 192 (interactive "p")
178 (and arg (< arg 0) (not (eobp)) (forward-char 1)) 193 ;; (and arg (< arg 0) (not (eobp)) (forward-char 1))
179 (and (re-search-backward (if defun-prompt-regexp 194 (unless arg (setq arg 1))
180 (concat "^\\s(\\|" 195 (cond
181 "\\(" defun-prompt-regexp "\\)\\s(") 196 (beginning-of-defun-function
182 "^\\s(") 197 (funcall beginning-of-defun-function arg))
183 nil 'move (or arg 1)) 198 (t (re-search-backward (if defun-prompt-regexp
184 (progn (goto-char (1- (match-end 0)))) t)) 199 (concat "^\\s(\\|"
200 "\\(" defun-prompt-regexp "\\)\\s(")
201 "^\\s(")
202 nil 'move (or arg 1))
203 (progn (goto-char (1- (match-end 0)))) t)))
185 204
186 ;; XEmacs change (optional buffer parameter) 205 ;; XEmacs change (optional buffer parameter)
187 (defun buffer-end (arg &optional buffer) 206 (defun buffer-end (arg &optional buffer)
188 "Return `point-max' of BUFFER if ARG is > 0; return `point-min' otherwise. 207 "Return `point-max' of BUFFER if ARG is > 0; return `point-min' otherwise.
189 BUFFER defaults to the current buffer if omitted." 208 BUFFER defaults to the current buffer if omitted."
196 An end of a defun occurs right after the close-parenthesis that matches 215 An end of a defun occurs right after the close-parenthesis that matches
197 the open-parenthesis that starts a defun; see `beginning-of-defun'." 216 the open-parenthesis that starts a defun; see `beginning-of-defun'."
198 ;; XEmacs change (for zmacs regions) 217 ;; XEmacs change (for zmacs regions)
199 (interactive "_p") 218 (interactive "_p")
200 (if (or (null arg) (= arg 0)) (setq arg 1)) 219 (if (or (null arg) (= arg 0)) (setq arg 1))
220 (if end-of-defun-function
221 (if (> arg 0)
222 (dotimes (i arg)
223 (funcall end-of-defun-function)))
201 (let ((first t)) 224 (let ((first t))
202 (while (and (> arg 0) (< (point) (point-max))) 225 (while (and (> arg 0) (< (point) (point-max)))
203 (let ((pos (point))) ; XEmacs -- remove unused npos. 226 (let ((pos (point))) ; XEmacs -- remove unused npos.
204 (while (progn 227 (while (progn
205 (if (and first 228 (if (and first
227 (forward-list 1) 250 (forward-list 1)
228 (skip-chars-forward " \t") 251 (skip-chars-forward " \t")
229 (if (looking-at "\\s<\\|\n") 252 (if (looking-at "\\s<\\|\n")
230 (forward-line 1))) 253 (forward-line 1)))
231 (goto-char (point-min))))) 254 (goto-char (point-min)))))
232 (setq arg (1+ arg))))) 255 (setq arg (1+ arg))))))
233 256
234 (defun mark-defun () 257 (defun mark-defun ()
235 "Put mark at end of this defun, point at beginning. 258 "Put mark at end of this defun, point at beginning.
236 The defun marked is the one that contains point or follows point." 259 The defun marked is the one that contains point or follows point."
237 (interactive) 260 (interactive)