diff options
| author | Phil Sainty | 2014-07-03 22:00:54 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2014-07-03 22:00:54 -0400 |
| commit | 2b13ca4d11960fe1d8b858a64864d7b74bf60867 (patch) | |
| tree | 7316e1d269426dd3fcf66e4f4ad59dd9d0dcb90a | |
| parent | 9362232cef75b7e0210407259d30818ddc35a112 (diff) | |
| download | emacs-2b13ca4d11960fe1d8b858a64864d7b74bf60867.tar.gz emacs-2b13ca4d11960fe1d8b858a64864d7b74bf60867.zip | |
* lisp/emacs-lisp/lisp.el (narrow-to-defun-include-comments): New var.
(narrow-to-defun): New arg include-comments, defaulting to it.
Fixes: debbugs:16328
| -rw-r--r-- | lisp/ChangeLog | 6 | ||||
| -rw-r--r-- | lisp/emacs-lisp/lisp.el | 24 |
2 files changed, 26 insertions, 4 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index c0b50604897..ed9a1100d49 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2014-07-04 Phil Sainty <psainty@orcon.net.nz> (tiny change) | ||
| 2 | |||
| 3 | * emacs-lisp/lisp.el (narrow-to-defun-include-comments): New var. | ||
| 4 | (narrow-to-defun): New arg include-comments, defaulting to it | ||
| 5 | (bug#16328). | ||
| 6 | |||
| 1 | 2014-07-03 Stefan Monnier <monnier@iro.umontreal.ca> | 7 | 2014-07-03 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 8 | ||
| 3 | * rect.el (rectangle--highlight-for-redisplay): Don't pass `orig' with | 9 | * rect.el (rectangle--highlight-for-redisplay): Don't pass `orig' with |
diff --git a/lisp/emacs-lisp/lisp.el b/lisp/emacs-lisp/lisp.el index 23b021df177..30fee64635c 100644 --- a/lisp/emacs-lisp/lisp.el +++ b/lisp/emacs-lisp/lisp.el | |||
| @@ -522,11 +522,15 @@ it marks the next defun after the ones already marked." | |||
| 522 | (beginning-of-defun)) | 522 | (beginning-of-defun)) |
| 523 | (re-search-backward "^\n" (- (point) 1) t))))) | 523 | (re-search-backward "^\n" (- (point) 1) t))))) |
| 524 | 524 | ||
| 525 | (defun narrow-to-defun (&optional _arg) | 525 | (defvar narrow-to-defun-include-comments nil |
| 526 | "If non-nil, `narrow-to-defun' will also show comments preceding the defun.") | ||
| 527 | |||
| 528 | (defun narrow-to-defun (&optional include-comments) | ||
| 526 | "Make text outside current defun invisible. | 529 | "Make text outside current defun invisible. |
| 527 | The defun visible is the one that contains point or follows point. | 530 | The current defun is the one that contains point or follows point. |
| 528 | Optional ARG is ignored." | 531 | Preceding comments are included if INCLUDE-COMMENTS is non-nil. |
| 529 | (interactive) | 532 | Interactively, the behavior depends on `narrow-to-defun-include-comments'." |
| 533 | (interactive (list narrow-to-defun-include-comments)) | ||
| 530 | (save-excursion | 534 | (save-excursion |
| 531 | (widen) | 535 | (widen) |
| 532 | (let ((opoint (point)) | 536 | (let ((opoint (point)) |
| @@ -562,6 +566,18 @@ Optional ARG is ignored." | |||
| 562 | (setq end (point)) | 566 | (setq end (point)) |
| 563 | (beginning-of-defun) | 567 | (beginning-of-defun) |
| 564 | (setq beg (point))) | 568 | (setq beg (point))) |
| 569 | (when include-comments | ||
| 570 | (goto-char beg) | ||
| 571 | ;; Move back past all preceding comments (and whitespace). | ||
| 572 | (when (forward-comment -1) | ||
| 573 | (while (forward-comment -1)) | ||
| 574 | ;; Move forwards past any page breaks within these comments. | ||
| 575 | (when (and page-delimiter (not (string= page-delimiter ""))) | ||
| 576 | (while (re-search-forward page-delimiter beg t))) | ||
| 577 | ;; Lastly, move past any empty lines. | ||
| 578 | (skip-chars-forward "[:space:]\n") | ||
| 579 | (beginning-of-line) | ||
| 580 | (setq beg (point)))) | ||
| 565 | (goto-char end) | 581 | (goto-char end) |
| 566 | (re-search-backward "^\n" (- (point) 1) t) | 582 | (re-search-backward "^\n" (- (point) 1) t) |
| 567 | (narrow-to-region beg end)))) | 583 | (narrow-to-region beg end)))) |