From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Christian Lemburg Newsgroups: gmane.emacs.help Subject: Re: State of the art in Emacs outlining? Date: 02 Oct 2002 17:01:41 +0200 Organization: KPNQwest Germany GmbH, customer reader site Sender: help-gnu-emacs-admin@gnu.org Message-ID: References: <5llm5ijjab.fsf@rum.cs.yale.edu> NNTP-Posting-Host: localhost.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1033660679 28718 127.0.0.1 (3 Oct 2002 15:57:59 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Thu, 3 Oct 2002 15:57:59 +0000 (UTC) Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 17x8MG-0007Ri-00 for ; Thu, 03 Oct 2002 17:57:48 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10) id 17x8Mb-0004gP-00; Thu, 03 Oct 2002 11:58:09 -0400 Original-Path: shelby.stanford.edu!nntp.stanford.edu!newsfeed.stanford.edu!syros.belnet.be!news.belnet.be!newsfeed00.sul.t-online.de!t-online.de!blackbush.xlink.net!blackbush.de.kpnqwest.net!scapa.de.kpnqwest.net!194.121.123.2!194.121.123.146 Original-Newsgroups: gnu.emacs.help Original-Lines: 199 Original-NNTP-Posting-Host: 194.121.123.2 Original-X-Trace: newsreader2.lb-lan.ka.de.kpnqwest.net 1033571854 14661 194.121.123.2 (2 Oct 2002 15:17:34 GMT) Original-X-Complaints-To: "abuse@de.kpnqwest.net" Original-NNTP-Posting-Date: Wed, 2 Oct 2002 15:17:34 +0000 (UTC) X-Face: "PlaRZ)@9[if~e#S1]D7|l`|7"C.kV+P^$.r!pL"NE^5Gh[Fwr?wR-@{Me)_Dfyec#Mi4M7 KWUn#dE$B3L3?WX:lR.vf-LI+w3OJL46>O2+HP#h$;.*K^Om]xOh8a>F1"6{%;k>=/;{Pn%sX2~'E? User-Agent: Gnus/5.0807 (Gnus v5.8.7) XEmacs/21.1 (Channel Islands) X-Original-NNTP-Posting-Host: 194.121.123.146 Original-Xref: nntp.stanford.edu gnu.emacs.help:105644 Original-To: help-gnu-emacs@gnu.org Errors-To: help-gnu-emacs-admin@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.help:2179 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:2179 "Stefan Monnier " 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 : ] | [--tag : ] @@ -347,6 +355,9 @@ [+l ] | [--nolink ] [-H ] | [--heading ] [-EH/+EH ] | [--explicit_headings / --noexplicit_headings ] + [-nh ] | [--number_headings ] + [-th ] | [--trim_headings ] + [-lpc ] | [--list_prefix_char ] [-ab ] | [--append_body ] [+ab ] | [--noappend_body ] [-ah ] | [--append_head ] @@ -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.>)/$1$2<\/A>$3/; } +sub trim_heading_maybe +{ + if ($trim_headings) { + $line =~ s/$trim_headings//g; + } +} + +sub number_heading_maybe +{ + local($heading_number) = ($line =~ //); + #" keep cperl happy + if ($number_headings) { + $line =~ s/(]*>)(.*)(<\/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, , http://www.clemburg.com/ Disc space -- the final frontier!