emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] trunk r117475: * lisp/emacs-lisp/lisp.el (narrow-to-defun-


From: Stefan Monnier
Subject: [Emacs-diffs] trunk r117475: * lisp/emacs-lisp/lisp.el (narrow-to-defun-include-comments): New var.
Date: Fri, 04 Jul 2014 02:01:14 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 117475
revision-id: address@hidden
parent: address@hidden
fixes bug: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16328
author: Phil Sainty <address@hidden>
committer: Stefan Monnier <address@hidden>
branch nick: trunk
timestamp: Thu 2014-07-03 22:00:54 -0400
message:
  * lisp/emacs-lisp/lisp.el (narrow-to-defun-include-comments): New var.
  (narrow-to-defun): New arg include-comments, defaulting to it.
modified:
  lisp/ChangeLog                 changelog-20091113204419-o5vbwnq5f7feedwu-1432
  lisp/emacs-lisp/lisp.el        lisp.el-20091113204419-o5vbwnq5f7feedwu-131
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2014-07-03 22:22:42 +0000
+++ b/lisp/ChangeLog    2014-07-04 02:00:54 +0000
@@ -1,3 +1,9 @@
+2014-07-04  Phil Sainty  <address@hidden>  (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  <address@hidden>
 
        * rect.el (rectangle--highlight-for-redisplay): Don't pass `orig' with

=== modified file 'lisp/emacs-lisp/lisp.el'
--- a/lisp/emacs-lisp/lisp.el   2014-05-26 02:28:09 +0000
+++ b/lisp/emacs-lisp/lisp.el   2014-07-04 02:00:54 +0000
@@ -522,11 +522,15 @@
             (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 @@
        (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))))


reply via email to

[Prev in Thread] Current Thread [Next in Thread]