branch: master
commit f61de0abe6139e10343fc8406d76db121193a283
Author: Paul Nelson <ultr...@gmail.com>
Commit: Arash Esbati <ar...@gnu.org>

    Add section folding commands
    
    * tex-fold.el (TeX-fold-section, TeX-fold-clearout-section):
    New commands.
    (TeX-fold-keymap): Bind them.
    * tex.el (TeX-fold-menu): Add them to the menu.
    * doc/auctex.texi (Folding Macros and Environments): Document
    them.  (bug#70370)
---
 doc/auctex.texi | 12 ++++++++++++
 tex-fold.el     | 23 +++++++++++++++++++++++
 tex.el          |  6 ++++++
 3 files changed, 41 insertions(+)

diff --git a/doc/auctex.texi b/doc/auctex.texi
index 064ba297..066dfbb0 100644
--- a/doc/auctex.texi
+++ b/doc/auctex.texi
@@ -2666,6 +2666,12 @@ default.
 containing point.
 @end deffn
 
+@deffn Command TeX-fold-section
+@kindex C-c C-o C-p
+(@kbd{C-c C-o C-p}) Hide all configured macros in the section
+containing point.
+@end deffn
+
 @deffn Command TeX-fold-macro
 @kindex C-c C-o C-m
 (@kbd{C-c C-o C-m}) Hide the macro on which point currently is located.
@@ -2718,6 +2724,12 @@ marked region.
 paragraph containing point.
 @end deffn
 
+@deffn Command TeX-fold-clearout-section
+@kindex C-c C-o p
+(@kbd{C-c C-o p}) Permanently unfold all macros and environments in the
+section containing point.
+@end deffn
+
 @deffn Command TeX-fold-clearout-item
 @kindex C-c C-o i
 (@kbd{C-c C-o i}) Permanently show the macro or environment on which
diff --git a/tex-fold.el b/tex-fold.el
index 33283204..19e35a2c 100644
--- a/tex-fold.el
+++ b/tex-fold.el
@@ -245,12 +245,14 @@ After that, changing the prefix key requires manipulating 
keymaps."
     (define-key map "\C-b" #'TeX-fold-buffer)
     (define-key map "\C-r" #'TeX-fold-region)
     (define-key map "\C-p" #'TeX-fold-paragraph)
+    (define-key map "\C-s" #'TeX-fold-section)
     (define-key map "\C-m" #'TeX-fold-macro)
     (define-key map "\C-e" #'TeX-fold-env)
     (define-key map "\C-c" #'TeX-fold-comment)
     (define-key map "b"    #'TeX-fold-clearout-buffer)
     (define-key map "r"    #'TeX-fold-clearout-region)
     (define-key map "p"    #'TeX-fold-clearout-paragraph)
+    (define-key map "s"    #'TeX-fold-clearout-section)
     (define-key map "i"    #'TeX-fold-clearout-item)
     map))
 
@@ -324,6 +326,18 @@ and `TeX-fold-math-spec-list', and environments in 
`TeX-fold-env-spec-list'."
       (TeX-fold-clearout-region start end)
       (TeX-fold-region start end))))
 
+(defun TeX-fold-section ()
+  "Hide all configured macros and environments in the current section.
+The relevant macros are specified in the variable `TeX-fold-macro-spec-list'
+and `TeX-fold-math-spec-list', and environments in `TeX-fold-env-spec-list'."
+  (interactive)
+  (save-mark-and-excursion
+    (LaTeX-mark-section)
+    (let ((start (point))
+          (end (mark)))
+      (TeX-fold-clearout-region start end)
+      (TeX-fold-region start end))))
+
 (defcustom TeX-fold-region-functions nil
   "List of additional functions to call when folding a region.
 Each function is called with two arguments, the start and end positions
@@ -742,6 +756,15 @@ breaks will be replaced by spaces."
           (start (progn (LaTeX-backward-paragraph) (point))))
       (TeX-fold-clearout-region start end))))
 
+(defun TeX-fold-clearout-section ()
+  "Permanently show all macros in the section point is located in."
+  (interactive)
+  (save-mark-and-excursion
+    (LaTeX-mark-section)
+    (let ((start (point))
+          (end (mark)))
+      (TeX-fold-clearout-region start end))))
+
 (defun TeX-fold-clearout-region (start end)
   "Permanently show all macros in region starting at START and ending at END."
   (interactive "r")
diff --git a/tex.el b/tex.el
index 20ee691e..18689f40 100644
--- a/tex.el
+++ b/tex.el
@@ -5257,6 +5257,9 @@ Brace insertion is only done if point is in a math 
construct and
     ["Hide All in Current Paragraph" TeX-fold-paragraph
      :active (and (boundp 'TeX-fold-mode) TeX-fold-mode)
      :help "Hide all configured TeX constructs in the paragraph containing 
point"]
+    ["Hide All in Current Section" TeX-fold-section
+     :active (and (boundp 'TeX-fold-mode) TeX-fold-mode)
+     :help "Hide all configured TeX constructs in the section containing 
point"]
     ["Hide Current Macro" TeX-fold-macro
      :active (and (boundp 'TeX-fold-mode) TeX-fold-mode)
      :help "Hide the macro containing point"]
@@ -5277,6 +5280,9 @@ Brace insertion is only done if point is in a math 
construct and
     ["Show All in Current Paragraph" TeX-fold-clearout-paragraph
      :active (and (boundp 'TeX-fold-mode) TeX-fold-mode)
      :help "Permanently show all folded content in paragraph containing point"]
+    ["Show All in Current Section" TeX-fold-clearout-section
+     :active (and (boundp 'TeX-fold-mode) TeX-fold-mode)
+     :help "Permanently show all folded content in section containing point"]
     ["Show Current Item" TeX-fold-clearout-item
      :active (and (boundp 'TeX-fold-mode) TeX-fold-mode)
      :help "Permanently show the item containing point"]

Reply via email to