comparison lisp/emacs-lisp/lisp.el @ 6397:70bf65b6aae9

(beginning-of-defun-raw): New function. (end-of-defun): Handle defun-prompt-regexp correctly.
author Karl Heuer <kwzh@gnu.org>
date Fri, 18 Mar 1994 02:21:52 +0000
parents 1740ec160ff8
children 09fadfc6384e
comparison
equal deleted inserted replaced
6396:1740ec160ff8 6397:70bf65b6aae9
133 Returns t unless search stops due to beginning or end of buffer. 133 Returns t unless search stops due to beginning or end of buffer.
134 134
135 Normally a defun starts when there is an char with open-parenthesis 135 Normally a defun starts when there is an char with open-parenthesis
136 syntax at the beginning of a line. If `defun-prompt-regexp' is 136 syntax at the beginning of a line. If `defun-prompt-regexp' is
137 non-nil, then a string which matches that regexp may precede the 137 non-nil, then a string which matches that regexp may precede the
138 open-parenthesis." 138 open-parenthesis, and point ends up at the beginning of the line."
139 (interactive "p")
140 (and (beginning-of-defun-raw arg)
141 (progn (beginning-of-line) t)))
142
143 (defun beginning-of-defun-raw (&optional arg)
144 "Move point to the character that starts a defun.
145 This is identical to beginning-of-defun, except that point does not move
146 to the beginning of the line when `defun-prompt-regexp' is non-nil."
139 (interactive "p") 147 (interactive "p")
140 (and arg (< arg 0) (forward-char 1)) 148 (and arg (< arg 0) (forward-char 1))
141 (and (re-search-backward (if defun-prompt-regexp 149 (and (re-search-backward (if defun-prompt-regexp
142 (concat "^\\s(\\|" 150 (concat "^\\s(\\|"
143 "\\(" defun-prompt-regexp "\\)\\s(") 151 "\\(" defun-prompt-regexp "\\)\\s(")
144 "^\\s(") 152 "^\\s(")
145 nil 'move (or arg 1)) 153 nil 'move (or arg 1))
146 (progn (beginning-of-line) t))) 154 (progn (goto-char (1- (match-end 0)))) t))
147 155
148 (defun buffer-end (arg) 156 (defun buffer-end (arg)
149 (if (> arg 0) (point-max) (point-min))) 157 (if (> arg 0) (point-max) (point-min)))
150 158
151 (defun end-of-defun (&optional arg) 159 (defun end-of-defun (&optional arg)
160 (while (and (> arg 0) (< (point) (point-max))) 168 (while (and (> arg 0) (< (point) (point-max)))
161 (let ((pos (point)) npos) 169 (let ((pos (point)) npos)
162 (while (progn 170 (while (progn
163 (if (and first 171 (if (and first
164 (progn 172 (progn
165 (forward-char 1) 173 (end-of-line 1)
166 (beginning-of-defun 1))) 174 (beginning-of-defun-raw 1)))
167 nil 175 nil
168 (or (bobp) (forward-char -1)) 176 (or (bobp) (forward-char -1))
169 (beginning-of-defun -1)) 177 (beginning-of-defun-raw -1))
170 (setq first nil) 178 (setq first nil)
171 (forward-list 1) 179 (forward-list 1)
172 (skip-chars-forward " \t") 180 (skip-chars-forward " \t")
173 (if (looking-at "\\s<\\|\n") 181 (if (looking-at "\\s<\\|\n")
174 (forward-line 1)) 182 (forward-line 1))
175 (<= (point) pos)))) 183 (<= (point) pos))))
176 (setq arg (1- arg))) 184 (setq arg (1- arg)))
177 (while (< arg 0) 185 (while (< arg 0)
178 (let ((pos (point))) 186 (let ((pos (point)))
179 (beginning-of-defun 1) 187 (beginning-of-defun-raw 1)
180 (forward-sexp 1) 188 (forward-sexp 1)
181 (forward-line 1) 189 (forward-line 1)
182 (if (>= (point) pos) 190 (if (>= (point) pos)
183 (if (beginning-of-defun 2) 191 (if (beginning-of-defun-raw 2)
184 (progn 192 (progn
185 (forward-list 1) 193 (forward-list 1)
186 (skip-chars-forward " \t") 194 (skip-chars-forward " \t")
187 (if (looking-at "\\s<\\|\n") 195 (if (looking-at "\\s<\\|\n")
188 (forward-line 1))) 196 (forward-line 1)))