emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] 186/299: Add narrowing commands.


From: Stefan Monnier
Subject: [elpa] 186/299: Add narrowing commands.
Date: Sun, 02 Nov 2014 03:11:19 +0000

monnier pushed a commit to branch externals/auctex
in repository elpa.

commit 20abeb9d9325a61f25424aab29b28cb57df0e440
Author: Mosè Giordano <address@hidden>
Date:   Sat Nov 2 20:21:49 2013 +0100

    Add narrowing commands.
    
    * latex.el (LaTeX-narrow-to-environment): New function, disabled
    by default.
    (LaTeX-common-initialization): Add key binding for
    `LaTeX-narrow-to-environment'.
    
    * tex.el (VirTeX-common-initialization): Add key binding for
    `TeX-narrow-to-group'.
    (TeX-narrow-to-group): New function, disabled by default.
    
    * doc/auctex.texi (Narrowing): Document narrowing commands.
    
    * doc/changes.texi: Mention narrowing commands.
---
 ChangeLog        |   15 +++++++++++++++
 doc/auctex.texi  |   34 ++++++++++++++++++++++++++++++++++
 doc/changes.texi |    4 ++++
 latex.el         |   23 ++++++++++++++++++++++-
 tex.el           |   20 ++++++++++++++++++++
 5 files changed, 95 insertions(+), 1 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 570fafe..b7506f8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2013-11-02  Mos� Giordano  <address@hidden>
+
+       * latex.el (LaTeX-narrow-to-environment): New function, disabled
+       by default.
+       (LaTeX-common-initialization): Add key binding for
+       `LaTeX-narrow-to-environment'.
+
+       * tex.el (VirTeX-common-initialization): Add key binding for
+       `TeX-narrow-to-group'.
+       (TeX-narrow-to-group): New function, disabled by default.
+
+       * doc/auctex.texi (Narrowing): Document narrowing commands.
+
+       * doc/changes.texi: Mention narrowing commands.
+
 2013-10-19  Mos� Giordano  <address@hidden>
 
        * latex.el (TeX-arg-file-name): New function.
diff --git a/doc/auctex.texi b/doc/auctex.texi
index f3b6b41..1af8cdb 100644
--- a/doc/auctex.texi
+++ b/doc/auctex.texi
@@ -163,6 +163,7 @@ Controlling Screen Display
 * Font Locking::                Font Locking
 * Folding::                     Folding Macros and Environments
 * Outline::                     Outlining the Document
+* Narrowing::                   Restricting display and editing to a portion 
of the buffer
 
 Font Locking
 
@@ -1677,10 +1678,15 @@ for Emacs' outline mode which lets you narrow the 
buffer content to
 certain sections of your text by hiding the parts not belonging to these
 sections.
 
+Moreover, you can focus in a specific portion of the code by narrowing
+the buffer to the desired region.  @AUCTeX{} provides also functions to
+narrow the buffer to the current group and to @LaTeX{} environments.
+
 @menu
 * Font Locking::                Font Locking
 * Folding::                     Folding Macros and Environments
 * Outline::                     Outlining the Document
+* Narrowing::                   Restricting display and editing to a portion 
of the buffer
 @end menu
 
 @node Font Locking
@@ -2405,6 +2411,34 @@ You may want to check out the unbundled @file{out-xtra} 
package for even
 better outline support.  It is available from your favorite emacs lisp
 archive.
 
address@hidden Narrowing
address@hidden Narrowing
+
+Sometimes you want to focus your attention to a limited region of the
+code.  You can do that by restricting the text addressable by editing
+commands and hiding the rest of the buffer with the narrowing functions,
address@hidden,,,emacs,GNU Emacs Manual}.  In addition, AUCTeX
+provides a couple of other commands to narrow the buffer to a group,
+i.e. a region enclosed in a pair of curly braces, and to @LaTeX{}
+environments.
+
address@hidden Command TeX-narrow-to-group
address@hidden C-x n g
+(@kbd{C-x n g}) Make text outside current group invisible.
address@hidden deffn
+
address@hidden Command LaTeX-narrow-to-environment @var{count}
address@hidden C-x n e
+(@kbd{C-x n e}) Make text outside current environment invisible.  With
+optional argument @var{count} keep visible that number of enclosing
+environmens.
address@hidden deffn
+
+Like other standard narrowing functions, the above commands are
+disabled.  Attempting to use them asks for confirmation and gives you
+the option of enabling them; if you enable the commands, confirmation
+will no longer be required for them.
+
 @node Processing
 @chapter Starting Processors, Viewers and Other Programs
 
diff --git a/doc/changes.texi b/doc/changes.texi
index 7242382..949b2e9 100644
--- a/doc/changes.texi
+++ b/doc/changes.texi
@@ -73,6 +73,10 @@ Tabular-like environments (tabular, tabular*, tabularx, 
tabulary, array,
 align, ...) are indented in a nicer and more informative way when the
 column values of a table line are written across multiple lines in the
 tex file.
+
address@hidden
+Commands for narrowing to a group (@code{TeX-narrow-to-group}) and to
address@hidden environments (@code{LaTeX-narrow-to-environment}) were added.
 @end itemize
 
 @heading News since 11.87
diff --git a/latex.el b/latex.el
index 98d15a0..95b6ab6 100644
--- a/latex.el
+++ b/latex.el
@@ -5017,6 +5017,25 @@ commands are defined:
                        (repeat :tag "Math Macros" (string))))
   :group 'TeX-fold)
 
+;;; Narrowing
+
+(defun LaTeX-narrow-to-environment (&optional count)
+  "Make text outside current environment invisible.
+With optional COUNT keep visible that number of enclosing
+environmens."
+  (interactive "p")
+  (setq count (if count (abs count) 1))
+  (save-excursion
+    (widen)
+    (let ((opoint (point))
+         beg end)
+      (dotimes (c count) (LaTeX-find-matching-end))
+      (setq end (point))
+      (goto-char opoint)
+      (dotimes (c count) (LaTeX-find-matching-begin))
+      (setq beg (point))
+      (narrow-to-region beg end))))
+(put 'LaTeX-narrow-to-environment 'disabled t)
 
 ;;; Keymap
 
@@ -5989,7 +6008,9 @@ i.e. you do _not_ have to cater for this yourself by 
adding \\\\' or $."
   ;; late in mode initialization to assure that all relevant variables
   ;; are properly initialized before style files try to alter them.
   (easy-menu-add LaTeX-mode-menu LaTeX-mode-map)
-  (easy-menu-add LaTeX-mode-command-menu LaTeX-mode-map))
+  (easy-menu-add LaTeX-mode-command-menu LaTeX-mode-map)
+
+  (define-key narrow-map "e" 'LaTeX-narrow-to-environment))
 
 (defun LaTeX-imenu-create-index-function ()
   "Imenu support function for LaTeX."
diff --git a/tex.el b/tex.el
index 443cf25..17c8a4f 100644
--- a/tex.el
+++ b/tex.el
@@ -3087,6 +3087,8 @@ The algorithm is as follows:
   (make-local-variable 'TeX-auto-update)
   (setq TeX-auto-update t)
 
+  (define-key narrow-map "g" 'TeX-narrow-to-group)
+
   ;; Minor modes
   (when TeX-source-correlate-mode
     (TeX-source-correlate-mode 1))
@@ -3944,6 +3946,24 @@ If optional argument STRIP is non-nil, remove file 
extension."
                                               dir) t)))))
            (append local-files (TeX-search-files dirs exts nodir strip)))))))
 
+;;; Narrowing
+
+(defun TeX-narrow-to-group ()
+  "Make text outside current group invisible."
+  (interactive)
+  (save-excursion
+    (widen)
+    (let ((opoint (point))
+         beg end)
+      (if (null (search-backward "{" nil t))
+         (message "Nothing to be narrowed here.")
+       (setq beg (point))
+       (forward-sexp)
+       (setq end (point))
+       (if (< end opoint)
+           (message "Nothing to be narrowed here.")
+         (narrow-to-region beg end))))))
+(put 'TeX-narrow-to-group 'disabled t)
 
 ;;; Utilities
 ;;



reply via email to

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