unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Christian Lemburg <lemburg@aixonix.de>
Subject: Re: State of the art in Emacs outlining?
Date: 02 Oct 2002 17:01:41 +0200	[thread overview]
Message-ID: <m3k7l07ulm.fsf@maki.aixonix.de> (raw)
In-Reply-To: 5llm5ijjab.fsf@rum.cs.yale.edu

"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!

  parent reply	other threads:[~2002-10-02 15:01 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.1033440784.21858.help-gnu-emacs@gnu.org>
2002-10-01 15:00 ` State of the art in Emacs outlining? Stefan Monnier <foo@acm.com>
2002-10-02 14:44   ` Benjamin Rutt
2002-10-02 16:06     ` Stefan Monnier <foo@acm.com>
2002-10-02 15:01   ` Christian Lemburg [this message]
2002-10-02 17:11     ` Matthias Meulien
     [not found] <mailman.1033275084.18063.help-gnu-emacs@gnu.org>
2002-09-29  9:33 ` Alex Schroeder
2002-10-01  2:52   ` Tom Davey
2002-09-29 15:38 ` Kai Großjohann
2002-09-29  4:49 Tom Davey
2002-10-01 15:02 ` Sacha Chua
2002-10-04  0:53   ` Tom Davey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3k7l07ulm.fsf@maki.aixonix.de \
    --to=lemburg@aixonix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).