aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/emacs-lisp/lisp.el61
1 files changed, 46 insertions, 15 deletions
diff --git a/lisp/emacs-lisp/lisp.el b/lisp/emacs-lisp/lisp.el
index 8fe839b474d..53b9e7507ef 100644
--- a/lisp/emacs-lisp/lisp.el
+++ b/lisp/emacs-lisp/lisp.el
@@ -281,15 +281,31 @@ already marked."
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.
@@ -298,13 +314,28 @@ 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.