Mercurial > emacs
comparison lisp/emacs-lisp/lisp.el @ 55727:babf5161afd4
(mark-defun, narrow-to-defun): If moving back then fwd gets a defun
that ends before point, try again moving fwd then back.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sat, 22 May 2004 07:41:55 +0000 |
parents | 980615cc9a94 |
children | eb9d99ced391 |
comparison
equal
deleted
inserted
replaced
55726:9dbff3d047a0 | 55727:babf5161afd4 |
---|---|
279 (save-excursion | 279 (save-excursion |
280 (goto-char (mark)) | 280 (goto-char (mark)) |
281 (end-of-defun) | 281 (end-of-defun) |
282 (point)))) | 282 (point)))) |
283 (t | 283 (t |
284 ;; Do it in this order for the sake of languages with nested | 284 (let ((opoint (point)) |
285 ;; functions where several can end at the same place as with | 285 beg end) |
286 ;; the offside rule, e.g. Python. | 286 (push-mark opoint) |
287 (push-mark (point)) | 287 ;; Try first in this order for the sake of languages with nested |
288 (beginning-of-defun) | 288 ;; functions where several can end at the same place as with |
289 (push-mark (point) nil t) | 289 ;; the offside rule, e.g. Python. |
290 (end-of-defun) | 290 (beginning-of-defun) |
291 (exchange-point-and-mark) | 291 (setq beg (point)) |
292 (re-search-backward "^\n" (- (point) 1) t)))) | 292 (end-of-defun) |
293 (setq end (point)) | |
294 (while (looking-at "^\n") | |
295 (forward-line 1)) | |
296 (if (> (point) opoint) | |
297 (progn | |
298 ;; We got the right defun. | |
299 (push-mark beg nil t) | |
300 (goto-char end) | |
301 (exchange-point-and-mark)) | |
302 ;; beginning-of-defun moved back one defun | |
303 ;; so we got the wrong one. | |
304 (goto-char opoint) | |
305 (end-of-defun) | |
306 (push-mark (point) nil t) | |
307 (beginning-of-defun)) | |
308 (re-search-backward "^\n" (- (point) 1) t))))) | |
293 | 309 |
294 (defun narrow-to-defun (&optional arg) | 310 (defun narrow-to-defun (&optional arg) |
295 "Make text outside current defun invisible. | 311 "Make text outside current defun invisible. |
296 The defun visible is the one that contains point or follows point. | 312 The defun visible is the one that contains point or follows point. |
297 Optional ARG is ignored." | 313 Optional ARG is ignored." |
298 (interactive) | 314 (interactive) |
299 (save-excursion | 315 (save-excursion |
300 (widen) | 316 (widen) |
301 ;; Do it in this order for the sake of languages with nested | 317 (let ((opoint (point)) |
302 ;; functions where several can end at the same place as with the | 318 beg end) |
303 ;; offside rule, e.g. Python. | 319 ;; Try first in this order for the sake of languages with nested |
304 (beginning-of-defun) | 320 ;; functions where several can end at the same place as with |
305 (let ((beg (point))) | 321 ;; the offside rule, e.g. Python. |
322 (beginning-of-defun) | |
323 (setq beg (point)) | |
306 (end-of-defun) | 324 (end-of-defun) |
307 (narrow-to-region beg (point))))) | 325 (setq end (point)) |
326 (while (looking-at "^\n") | |
327 (forward-line 1)) | |
328 (unless (> (point) opoint) | |
329 ;; beginning-of-defun moved back one defun | |
330 ;; so we got the wrong one. | |
331 (goto-char opoint) | |
332 (end-of-defun) | |
333 (setq end (point)) | |
334 (beginning-of-defun) | |
335 (setq beg (point))) | |
336 (goto-char end) | |
337 (re-search-backward "^\n" (- (point) 1) t) | |
338 (narrow-to-region beg end)))) | |
308 | 339 |
309 (defun insert-pair (arg &optional open close) | 340 (defun insert-pair (arg &optional open close) |
310 "Enclose following ARG sexps in a pair of OPEN and CLOSE characters. | 341 "Enclose following ARG sexps in a pair of OPEN and CLOSE characters. |
311 Leave point after the first character. | 342 Leave point after the first character. |
312 A negative ARG encloses the preceding ARG sexps instead. | 343 A negative ARG encloses the preceding ARG sexps instead. |