auctex-commit
[Top][All Lists]
Advanced

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

[AUCTeX-commit] Changes to auctex/tex-fold.el,v


From: Ralf Angeli
Subject: [AUCTeX-commit] Changes to auctex/tex-fold.el,v
Date: Fri, 29 Dec 2006 13:40:19 +0000

CVSROOT:        /cvsroot/auctex
Module name:    auctex
Changes by:     Ralf Angeli <angeli>    06/12/29 13:40:19

Index: tex-fold.el
===================================================================
RCS file: /cvsroot/auctex/auctex/tex-fold.el,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -b -r1.53 -r1.54
--- tex-fold.el 25 May 2006 07:50:57 -0000      1.53
+++ tex-fold.el 29 Dec 2006 13:40:19 -0000      1.54
@@ -2,7 +2,7 @@
 
 ;; Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
 
-;; Author: Ralf Angeli <address@hidden>
+;; Author: Ralf Angeli <address@hidden>
 ;; Maintainer: address@hidden
 ;; Created: 2004-07-04
 ;; Keywords: tex, wp
@@ -59,6 +59,15 @@
   "Fold TeX macros."
   :group 'AUCTeX)
 
+(defcustom TeX-fold-type-list '(env macro)
+  "List of item types to consider when folding.
+Valid items are the symbols 'env for environments, 'macro for
+macros and 'comment for comments."
+  :type '(set (const :tag "Environments" env)
+             (const :tag "Macros" macro)
+             (const :tag "Comments" comment))
+  :group 'TeX-fold)
+
 (defcustom TeX-fold-macro-spec-list
   '(("[f]" ("footnote"))
     ("[c]" ("cite"))
@@ -177,6 +186,7 @@
     (define-key map "\C-c\C-o\C-p" 'TeX-fold-paragraph)
     (define-key map "\C-c\C-o\C-m" 'TeX-fold-macro)
     (define-key map "\C-c\C-o\C-e" 'TeX-fold-env)
+    (define-key map "\C-c\C-o\C-c" 'TeX-fold-comment)
     (define-key map "\C-c\C-ob"    'TeX-fold-clearout-buffer)
     (define-key map "\C-c\C-or"    'TeX-fold-clearout-region)
     (define-key map "\C-c\C-op"    'TeX-fold-clearout-paragraph)
@@ -195,7 +205,8 @@
   (cond ((TeX-fold-clearout-item))
        ((TeX-active-mark) (TeX-fold-region (mark) (point)))
        ((TeX-fold-item 'macro))
-       ((TeX-fold-item 'env))))
+       ((TeX-fold-item 'env))
+       ((TeX-fold-comment))))
 
 (defun TeX-fold-buffer ()
   "Hide all configured macros and environments in the current buffer.
@@ -223,19 +234,21 @@
       (TeX-fold-clearout-region start end)
       (TeX-fold-region start end))))
 
-(defun TeX-fold-region (start end &optional type)
-  "Fold all items in region starting at position START and ending at END.
-If optional parameter TYPE is given, fold only items of the
-specified type.  TYPE can be one of the symbols 'env for
-environments or 'macro for macros."
+(defun TeX-fold-region (start end)
+  "Fold all items in region from START to END."
   (interactive "r")
-  (if (null type)
-      (progn
-       (TeX-fold-region start end 'env)
-       (TeX-fold-region start end 'macro))
-    (when (or (and (eq type 'env)
+  (when (and (memq 'env TeX-fold-type-list)
                   (not (eq major-mode 'plain-tex-mode)))
-             (eq type 'macro))
+    (TeX-fold-region-macro-or-env start end 'env))
+  (when (memq 'macro TeX-fold-type-list)
+    (TeX-fold-region-macro-or-env start end 'macro))
+  (when (memq 'comment TeX-fold-type-list)
+    (TeX-fold-region-comment start end)))
+
+(defun TeX-fold-region-macro-or-env (start end type)
+  "Fold all items of type TYPE in region from START to END.
+TYPE can be one of the symbols 'env for environments and 'macro
+for macros."
       (save-excursion
        (let (fold-list item-list regexp)
          (dolist (item (if (eq type 'env)
@@ -289,19 +302,43 @@
                         (item-end (TeX-fold-item-end item-start type))
                         (ov (TeX-fold-make-overlay item-start item-end type
                                                    display-string-spec)))
-                   (TeX-fold-hide-item ov)))))))))))
+               (TeX-fold-hide-item ov)))))))))
+
+(defun TeX-fold-region-comment (start end)
+  "Fold all comments in region from START to END."
+  (save-excursion
+    (goto-char start)
+    (let (beg)
+      (while (setq beg (TeX-search-forward-comment-start end))
+       (goto-char beg)
+       ;; Determine the start of the region to be folded just behind
+       ;; the comment starter.
+       (looking-at TeX-comment-start-regexp)
+       (setq beg (match-end 0))
+       ;; Search for the end of the comment.
+       (while (TeX-comment-forward))
+       (end-of-line 0)
+       ;; Hide the whole region.
+       (TeX-fold-hide-item (TeX-fold-make-overlay beg (point) 'comment
+                                                  TeX-fold-ellipsis))))))
 
 (defun TeX-fold-macro ()
   "Hide the macro on which point currently is located."
   (interactive)
   (unless (TeX-fold-item 'macro)
-    (message "No macro found.")))
+    (message "No macro found")))
 
 (defun TeX-fold-env ()
   "Hide the environment on which point currently is located."
   (interactive)
   (unless (TeX-fold-item 'env)
-    (message "No environment found.")))
+    (message "No environment found")))
+
+(defun TeX-fold-comment ()
+  "Hide the comment on which point currently is located."
+  (interactive)
+  (unless (TeX-fold-comment-do)
+    (message "No comment found")))
 
 (defun TeX-fold-item (type)
   "Hide the item on which point currently is located.
@@ -371,6 +408,27 @@
                                          display-string-spec)))
          (TeX-fold-hide-item ov))))))
 
+(defun TeX-fold-comment-do ()
+  "Hide the comment on which point currently is located.
+This is the function doing the work for `TeX-fold-comment'.  It
+is an internal function communication with return values rather
+than with messages for the user.
+Return non-nil if a comment was found and folded, nil otherwise."
+  (if (and (not (TeX-in-comment)) (not (TeX-in-line-comment)))
+      nil
+    (let (beg)
+      (save-excursion
+       (while (progn
+                (beginning-of-line 0)
+                (TeX-in-line-comment)))
+       (goto-char (TeX-search-forward-comment-start (line-end-position 2)))
+       (looking-at TeX-comment-start-regexp)
+       (setq beg (match-end 0))
+       (while (TeX-comment-forward))
+       (end-of-line 0)
+       (TeX-fold-hide-item (TeX-fold-make-overlay beg (point) 'comment
+                                                  TeX-fold-ellipsis))))))
+
 
 ;;; Utilities
 
@@ -719,10 +777,10 @@
 
 ;;; The mode
 
-;;; This autoload cookie had to be changed because of XEmacs.  This is
-;;; very dissatisfactory, because we now don't have the full doc string
-;;; available to tell people what to expect when using this mode
-;;; before loading it.
+;; This autoload cookie had to be changed because of XEmacs.  This is
+;; very dissatisfactory, because we now don't have the full doc string
+;; available to tell people what to expect when using this mode before
+;; loading it.
 
 ;;;###autoload (autoload 'TeX-fold-mode "tex-fold" "Minor mode for hiding and 
revealing macros and environments." t)
 (define-minor-mode TeX-fold-mode




reply via email to

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