281 |
(end-of-defun) |
(end-of-defun) |
282 |
(point)))) |
(point)))) |
283 |
(t |
(t |
284 |
;; Do it in this order for the sake of languages with nested |
(let ((opoint (point)) |
285 |
;; functions where several can end at the same place as with |
beg end) |
286 |
;; the offside rule, e.g. Python. |
(push-mark opoint) |
287 |
(push-mark (point)) |
;; Try first in this order for the sake of languages with nested |
288 |
(beginning-of-defun) |
;; functions where several can end at the same place as with |
289 |
(push-mark (point) nil t) |
;; the offside rule, e.g. Python. |
290 |
(end-of-defun) |
(beginning-of-defun) |
291 |
(exchange-point-and-mark) |
(setq beg (point)) |
292 |
(re-search-backward "^\n" (- (point) 1) t)))) |
(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))))) |
309 |
|
|
310 |
(defun narrow-to-defun (&optional arg) |
(defun narrow-to-defun (&optional arg) |
311 |
"Make text outside current defun invisible. |
"Make text outside current defun invisible. |
314 |
(interactive) |
(interactive) |
315 |
(save-excursion |
(save-excursion |
316 |
(widen) |
(widen) |
317 |
;; Do it in this order for the sake of languages with nested |
(let ((opoint (point)) |
318 |
;; functions where several can end at the same place as with the |
beg end) |
319 |
;; offside rule, e.g. Python. |
;; Try first in this order for the sake of languages with nested |
320 |
(beginning-of-defun) |
;; functions where several can end at the same place as with |
321 |
(let ((beg (point))) |
;; the offside rule, e.g. Python. |
322 |
|
(beginning-of-defun) |
323 |
|
(setq beg (point)) |
324 |
(end-of-defun) |
(end-of-defun) |
325 |
(narrow-to-region beg (point))))) |
(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)))) |
339 |
|
|
340 |
(defun insert-pair (arg &optional open close) |
(defun insert-pair (arg &optional open close) |
341 |
"Enclose following ARG sexps in a pair of OPEN and CLOSE characters. |
"Enclose following ARG sexps in a pair of OPEN and CLOSE characters. |