help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: State of the art in Emacs outlining?


From: Christian Lemburg
Subject: Re: State of the art in Emacs outlining?
Date: 02 Oct 2002 17:01:41 +0200
User-agent: Gnus/5.0807 (Gnus v5.8.7) XEmacs/21.1 (Channel Islands)

"Stefan Monnier <foo@acm.com>" <monnier+gnu.emacs.help/news/@flint.cs.yale.edu> 
writes:

> The outline.el code in the CVS repository offers such functionality,
> although it might be a bit fragile.  I'd be interested to hear how
> well it works in practice for others than me.

While I am certainly not using many of the advanced features of
outline-mode, I use it nearly daily for write-ups etc., using txt2html
or txt2tex for making pretty output.

I also have noticed that it is very easy to customize outlook-mode
using appropriate regexes for other purposes, like viewing large files
of source code in an organized manner. The main point here is that you
don't have to understand much to get large gains in productivity
(unlike customizing speedbar, the internals of which I don't grok at
all).

Examples:

(defun perl-outline-mode ()
  "Set customized outline minor mode for Perl"
  (interactive)
  (setq outline-regexp "#!.\\|\\(pac\\)kage\\|sub\\|\\(=he\\)ad\\|\\(=po\\)d")
  (outline-minor-mode))

(defun text-outline-mode ()
  "Set customized outline major mode for text with numbered headings"
  (interactive)
  (setq outline-regexp "[0-9.]+")
  (outline-mode))

(defun php-outline-mode ()
  "Set customized outline minor mode for PHP"
  (interactive)
  (setq outline-regexp "<\\?\\| *function\\|class")
  (outline-minor-mode))


txt2html.pl  \
--heading '^\*\s+\S+' \
--heading '^\*\*\s+\S+' \
--heading '^\*\*\*\s+\S+' \
--heading '^\*\*\*\*\s+\S+' \
--heading '^\*\*\*\*\*\s+\S+' \
--heading '^\*\*\*\*\*\*\s+\S+' \
--heading '^\*\*\*\*\*\*\*\s+\S+' \
--heading '^\*\*\*\*\*\*\*\*\s+\S+' \
--heading '^\*\*\*\*\*\*\*\*\*\s+\S+' \
--heading '^\*\*\*\*\*\*\*\*\*\*\s+\S+' \
--list_prefix_char '[-=o\267]' \
--trim_headings '\*+\s+' \
--number_headings \
--explicit_headings \
"$@"


txt2tex.pl  \
--heading '^\*\s+\S+' \
--heading '^\*\*\s+\S+' \
--heading '^\*\*\*\s+\S+' \
--heading '^\*\*\*\*\s+\S+' \
--heading '^\*\*\*\*\*\s+\S+' \
--heading '^\*\*\*\*\*\*\s+\S+' \
--heading '^\*\*\*\*\*\*\*\s+\S+' \
--heading '^\*\*\*\*\*\*\*\*\s+\S+' \
--heading '^\*\*\*\*\*\*\*\*\*\s+\S+' \
--heading '^\*\*\*\*\*\*\*\*\*\*\s+\S+' \
+EH \
-headingtags number \
--trimheadings '\*+\s+' \
"$@"


DISCLAIMER: Please note that using this with txt2html needs a patched
version of txt2html-1.28 (available from
http://www.aigeek.com/txt2html/ ), see patch below:


diff -Naur txt2html-1.28/txt2html.pl txt2html-1.28-patched/txt2html.pl
--- txt2html-1.28/txt2html.pl   Tue May 23 16:10:26 2000
+++ txt2html-1.28-patched/txt2html.pl   Mon Feb 25 14:49:48 2002
@@ -202,6 +202,14 @@
                                 # in the order they are specified on
                                 # the command line.
 
+# [-nh        ] | [--number_headings               ]
+$number_headings = 0;           # prepend section number to headings
+
+# [-th        ] | [--trim_headings                 ]
+$trim_headings = "";            # regex to trim headings with
+
+# [-lpc       ] | [--list_prefix_char              ]
+$list_prefix_char = "[-=o\\*\\267]"; # character class for list prefixes
 
 # Not implemented yet.
 # [-T <t>:<r> ] | [--tag <tagname>:<regexp>        ]
@@ -347,6 +355,9 @@
      [+l         ] | [--nolink                        ]
      [-H <regexp>] | [--heading <regexp>              ]
      [-EH/+EH    ] | [--explicit_headings / --noexplicit_headings ]
+     [-nh        ] | [--number_headings               ]
+     [-th        ] | [--trim_headings <regexp>        ]
+     [-lpc       ] | [--list_prefix_char <regexp>     ]
      [-ab <file> ] | [--append_body <file>            ]
      [+ab        ] | [--noappend_body                 ]
      [-ah <file> ] | [--append_head <file>            ]
@@ -720,6 +731,26 @@
             next;
         }
 
+        if ($ARGV[0] eq "-nh" || $ARGV[0] eq "--number_headings")
+        {
+            $number_headings = 1;
+            next;
+        }
+
+        if ($ARGV[0] eq "-lpc" || $ARGV[0] eq "--list_prefix_char")
+        {
+            $list_prefix_char = $ARGV[1];
+            shift @ARGV;
+            next;
+        }
+
+        if ($ARGV[0] eq "-th" || $ARGV[0] eq "--trim_headings")
+        {
+            $trim_headings = $ARGV[1];
+            shift @ARGV;
+            next;
+        }
+
         if ($ARGV[0] eq "--")
         {
             last;
@@ -869,7 +900,7 @@
     local($line) = @_;
     local($prefix, $number, $rawprefix);
 
-    return (0,0,0) if (!($line =~ /^\s*[-=o\*\267]+\s+\S/ ) &&
+    return (0,0,0) if (!($line =~ /^\s*$list_prefix_char+\s+\S/ ) &&
                        !($line =~ /^\s*(\d+|[^\W\d_])[\.\)\]:]\s+\S/ ));
 
     ($number) = $line =~ /^\s*(\d+|[^\W\d_])/;
@@ -889,7 +920,7 @@
         $prefix = $rawprefix;
         $prefix =~ s/(\d+|[^\W\d_])//;  # Take the number out
     } else {
-        ($rawprefix) = $line =~ /^(\s*[-=o\*\267]+.)/;
+        ($rawprefix) = $line =~ /^(\s*$list_prefix_char+.)/;
         $prefix = $rawprefix;
     }
     ($prefix, $number, $rawprefix);
@@ -1111,6 +1142,22 @@
     $line =~ s/(<H.>)(.*)(<\/H.>)/$1<A NAME="$anchor">$2<\/A>$3/;
 }
 
+sub trim_heading_maybe
+{
+    if ($trim_headings) {
+       $line =~ s/$trim_headings//g;
+    }
+}
+
+sub number_heading_maybe
+{
+    local($heading_number) = ($line =~ /<A NAME="section-([^"]*)">/);
+    #" keep cperl happy
+    if ($number_headings) {
+        $line =~ s/(<H.><A [^>]*>)(.*)(<\/A><\/H.>)/$1$heading_number $2$3/;
+    }
+}
+
 sub heading_level
 {
     local($style) = @_;
@@ -1150,6 +1197,8 @@
     $heading_level = &heading_level($underline);
     &tagline("H" . $heading_level);
     &anchor_heading( $heading_level );
+    &number_heading_maybe;
+    &trim_heading_maybe;
     $line_action |= $HEADER;
 }
 
@@ -1168,6 +1217,8 @@
             }
             &tagline("H" . $level);
             &anchor_heading( $level );
+           &number_heading_maybe;
+           &trim_heading_maybe;
             $line_action |= $HEADER;
             last;
         }


-- 
Christian Lemburg, <lemburg@aixonix.de>, http://www.clemburg.com/


 Disc space -- the final frontier!


reply via email to

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