Mercurial > emacs
comparison lisp/emacs-lisp/lisp.el @ 89909:68c22ea6027c
Sync to HEAD
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Fri, 16 Apr 2004 12:51:06 +0000 |
parents | 375f2633d815 |
children | 4c90ffeb71c5 |
comparison
equal
deleted
inserted
replaced
89908:ee1402f7b568 | 89909:68c22ea6027c |
---|---|
1 ;;; lisp.el --- Lisp editing commands for Emacs | 1 ;;; lisp.el --- Lisp editing commands for Emacs |
2 | 2 |
3 ;; Copyright (C) 1985, 1986, 1994, 2000 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1985, 86, 1994, 2000, 2004 Free Software Foundation, Inc. |
4 | 4 |
5 ;; Maintainer: FSF | 5 ;; Maintainer: FSF |
6 ;; Keywords: lisp, languages | 6 ;; Keywords: lisp, languages |
7 | 7 |
8 ;; This file is part of GNU Emacs. | 8 ;; This file is part of GNU Emacs. |
155 This is used to find the beginning of the defun instead of using the | 155 This is used to find the beginning of the defun instead of using the |
156 normal recipe (see `beginning-of-defun'). Major modes can define this | 156 normal recipe (see `beginning-of-defun'). Major modes can define this |
157 if defining `defun-prompt-regexp' is not sufficient to handle the mode's | 157 if defining `defun-prompt-regexp' is not sufficient to handle the mode's |
158 needs. | 158 needs. |
159 | 159 |
160 The function should go to the line on which the current defun starts, | 160 The function (of no args) should go to the line on which the current |
161 and return non-nil, or should return nil if it can't find the beginning.") | 161 defun starts, and return non-nil, or should return nil if it can't |
162 find the beginning.") | |
162 | 163 |
163 (defun beginning-of-defun (&optional arg) | 164 (defun beginning-of-defun (&optional arg) |
164 "Move backward to the beginning of a defun. | 165 "Move backward to the beginning of a defun. |
165 With ARG, do it that many times. Negative arg -N | 166 With ARG, do it that many times. Negative arg -N |
166 means move forward to Nth following beginning of defun. | 167 means move forward to Nth following beginning of defun. |
185 | 186 |
186 If variable `beginning-of-defun-function' is non-nil, its value | 187 If variable `beginning-of-defun-function' is non-nil, its value |
187 is called as a function to find the defun's beginning." | 188 is called as a function to find the defun's beginning." |
188 (interactive "p") | 189 (interactive "p") |
189 (if beginning-of-defun-function | 190 (if beginning-of-defun-function |
190 (funcall beginning-of-defun-function) | 191 (if (> (setq arg (or arg 1)) 0) |
192 (dotimes (i arg) | |
193 (funcall beginning-of-defun-function)) | |
194 ;; Better not call end-of-defun-function directly, in case | |
195 ;; it's not defined. | |
196 (end-of-defun (- arg))) | |
191 (and arg (< arg 0) (not (eobp)) (forward-char 1)) | 197 (and arg (< arg 0) (not (eobp)) (forward-char 1)) |
192 (and (re-search-backward (if defun-prompt-regexp | 198 (and (re-search-backward (if defun-prompt-regexp |
193 (concat (if open-paren-in-column-0-is-defun-start | 199 (concat (if open-paren-in-column-0-is-defun-start |
194 "^\\s(\\|" "") | 200 "^\\s(\\|" "") |
195 "\\(?:" defun-prompt-regexp "\\)\\s(") | 201 "\\(?:" defun-prompt-regexp "\\)\\s(") |
215 `beginning-of-defun'. | 221 `beginning-of-defun'. |
216 | 222 |
217 If variable `end-of-defun-function' is non-nil, its value | 223 If variable `end-of-defun-function' is non-nil, its value |
218 is called as a function to find the defun's end." | 224 is called as a function to find the defun's end." |
219 (interactive "p") | 225 (interactive "p") |
226 (if (or (null arg) (= arg 0)) (setq arg 1)) | |
220 (if end-of-defun-function | 227 (if end-of-defun-function |
221 (funcall end-of-defun-function) | 228 (if (> arg 0) |
222 (if (or (null arg) (= arg 0)) (setq arg 1)) | 229 (dotimes (i arg) |
230 (funcall end-of-defun-function)) | |
231 ;; Better not call beginning-of-defun-function | |
232 ;; directly, in case it's not defined. | |
233 (beginning-of-defun (- arg))) | |
223 (let ((first t)) | 234 (let ((first t)) |
224 (while (and (> arg 0) (< (point) (point-max))) | 235 (while (and (> arg 0) (< (point) (point-max))) |
225 (let ((pos (point)) npos) | 236 (let ((pos (point))) |
226 (while (progn | 237 (while (progn |
227 (if (and first | 238 (if (and first |
228 (progn | 239 (progn |
229 (end-of-line 1) | 240 (end-of-line 1) |
230 (beginning-of-defun-raw 1))) | 241 (beginning-of-defun-raw 1))) |
264 (save-excursion | 275 (save-excursion |
265 (goto-char (mark)) | 276 (goto-char (mark)) |
266 (end-of-defun) | 277 (end-of-defun) |
267 (point)))) | 278 (point)))) |
268 (t | 279 (t |
280 ;; Do it in this order for the sake of languages with nested | |
281 ;; functions where several can end at the same place as with | |
282 ;; the offside rule, e.g. Python. | |
269 (push-mark (point)) | 283 (push-mark (point)) |
284 (beginning-of-defun) | |
285 (push-mark (point) nil t) | |
270 (end-of-defun) | 286 (end-of-defun) |
271 (push-mark (point) nil t) | 287 (exchange-point-and-mark) |
272 (beginning-of-defun) | |
273 (re-search-backward "^\n" (- (point) 1) t)))) | 288 (re-search-backward "^\n" (- (point) 1) t)))) |
274 | 289 |
275 (defun narrow-to-defun (&optional arg) | 290 (defun narrow-to-defun (&optional arg) |
276 "Make text outside current defun invisible. | 291 "Make text outside current defun invisible. |
277 The defun visible is the one that contains point or follows point. | 292 The defun visible is the one that contains point or follows point. |
278 Optional ARG is ignored." | 293 Optional ARG is ignored." |
279 (interactive) | 294 (interactive) |
280 (save-excursion | 295 (save-excursion |
281 (widen) | 296 (widen) |
282 (end-of-defun) | 297 ;; Do it in this order for the sake of languages with nested |
283 (let ((end (point))) | 298 ;; functions where several can end at the same place as with the |
284 (beginning-of-defun) | 299 ;; offside rule, e.g. Python. |
285 (narrow-to-region (point) end)))) | 300 (beginning-of-defun) |
301 (let ((beg (point))) | |
302 (end-of-defun) | |
303 (narrow-to-region beg (point))))) | |
286 | 304 |
287 (defun insert-parentheses (arg) | 305 (defun insert-parentheses (arg) |
288 "Enclose following ARG sexps in parentheses. Leave point after open-paren. | 306 "Enclose following ARG sexps in parentheses. Leave point after open-paren. |
289 A negative ARG encloses the preceding ARG sexps instead. | 307 A negative ARG encloses the preceding ARG sexps instead. |
290 No argument is equivalent to zero: just insert `()' and leave point between. | 308 No argument is equivalent to zero: just insert `()' and leave point between. |
443 (setq list (nreverse new)))) | 461 (setq list (nreverse new)))) |
444 (with-output-to-temp-buffer "*Completions*" | 462 (with-output-to-temp-buffer "*Completions*" |
445 (display-completion-list list))) | 463 (display-completion-list list))) |
446 (message "Making completion list...%s" "done"))))))) | 464 (message "Making completion list...%s" "done"))))))) |
447 | 465 |
466 ;;; arch-tag: aa7fa8a4-2e6f-4e9b-9cd9-fef06340e67e | |
448 ;;; lisp.el ends here | 467 ;;; lisp.el ends here |