]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/emacs-lisp/lisp.el (narrow-to-defun-include-comments): New var.
authorPhil Sainty <psainty@orcon.net.nz>
Fri, 4 Jul 2014 02:00:54 +0000 (22:00 -0400)
committerStefan Monnier <monnier@iro.umontreal.ca>
Fri, 4 Jul 2014 02:00:54 +0000 (22:00 -0400)
(narrow-to-defun): New arg include-comments, defaulting to it.

Fixes: debbugs:16328
lisp/ChangeLog
lisp/emacs-lisp/lisp.el

index c0b50604897be2962971b88c67d4e100c7470eaf..ed9a1100d495f1138d868a3d9ecac76c9dde5eca 100644 (file)
@@ -1,3 +1,9 @@
+2014-07-04  Phil Sainty  <psainty@orcon.net.nz>  (tiny change)
+
+       * emacs-lisp/lisp.el (narrow-to-defun-include-comments): New var.
+       (narrow-to-defun): New arg include-comments, defaulting to it
+       (bug#16328).
+
 2014-07-03  Stefan Monnier  <monnier@iro.umontreal.ca>
 
        * rect.el (rectangle--highlight-for-redisplay): Don't pass `orig' with
index 23b021df1776086ce22de3e75a11f42949876156..30fee64635c13876df4d44bda234a54ff18f2f3b 100644 (file)
@@ -522,11 +522,15 @@ it marks the next defun after the ones already marked."
             (beginning-of-defun))
           (re-search-backward "^\n" (- (point) 1) t)))))
 
-(defun narrow-to-defun (&optional _arg)
+(defvar narrow-to-defun-include-comments nil
+  "If non-nil, `narrow-to-defun' will also show comments preceding the defun.")
+
+(defun narrow-to-defun (&optional include-comments)
   "Make text outside current defun invisible.
-The defun visible is the one that contains point or follows point.
-Optional ARG is ignored."
-  (interactive)
+The current defun is the one that contains point or follows point.
+Preceding comments are included if INCLUDE-COMMENTS is non-nil.
+Interactively, the behavior depends on `narrow-to-defun-include-comments'."
+  (interactive (list narrow-to-defun-include-comments))
   (save-excursion
     (widen)
     (let ((opoint (point))
@@ -562,6 +566,18 @@ Optional ARG is ignored."
        (setq end (point))
        (beginning-of-defun)
        (setq beg (point)))
+      (when include-comments
+       (goto-char beg)
+       ;; Move back past all preceding comments (and whitespace).
+       (when (forward-comment -1)
+         (while (forward-comment -1))
+         ;; Move forwards past any page breaks within these comments.
+         (when (and page-delimiter (not (string= page-delimiter "")))
+           (while (re-search-forward page-delimiter beg t)))
+         ;; Lastly, move past any empty lines.
+         (skip-chars-forward "[:space:]\n")
+         (beginning-of-line)
+         (setq beg (point))))
       (goto-char end)
       (re-search-backward "^\n" (- (point) 1) t)
       (narrow-to-region beg end))))