unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Benjamin Rutt <brutt+news@bloomington.in.us>
Subject: Re: Renumbering paragraphs automatically
Date: Tue, 24 Feb 2004 16:22:37 -0500	[thread overview]
Message-ID: <wc3n078w4te.fsf@mu.cis.ohio-state.edu> (raw)
In-Reply-To: m3ad38s07u.fsf@bonsai.taydin.org

Timur Aydin <ta@taydin.org> writes:

> When writing an itemized list as follows:
>
> 1) Sentences in first paragraph.
>
> 2) The second paragraph.
>
> 3) The third paragraph.
>
> Can emacs help me regenerate the paragraph numbers when I
> insert/delete items or if I move items around?

I use outline-mode directly to build lists like this for maximum
flexibility.  When I want to produce numbered output for laymen to
read, I use the following shell script:

# filename: indentN.awk
#   author: Eric Pement - pemente@northpark.edu
#     date: 02/14/2001
#
#  purpose: awk script to modify files created and saved in GNU Emacs
#           "outline-mode" to a numbered, indented output format. E.g.,
#
#  INPUT FILE        OUTPUT FILE
#  ==============    ===========================            
#  * Line 1        | 1. Line 1
#  ** Line 2       |   1.1. Line 2
#  *** Line 3      |     1.1.1. Line 3
#  *** Line 4      |     1.1.2. Line 4
#  **** Line 5     |       1.1.2.1. Line 5
#  ***** Line 6    |         1.1.2.1.1. Line 6
#  ***** Line 7    |         1.1.2.1.2. Line 7
#  ** Line 8       |   1.2. Line 8
#  * Line 9        | 2. Line 9
#  ** Line 10      |   2.1. Line 10
#
# Note: this script can handle any number of asterisks on a line. 
# Lines of plain text (no asterisks) in source file are NOT indented.
/^\*/ {

  this_len = match($0,/\*[^*]/);  # get number of stars in 1st field
  array[this_len]++;              # increment index of current leaf

  if ( this_len < last_len ) {    # if we have moved up a branch...
     for (i = this_len + 1; i <= last_len; i++)
        array[i] = 0;             # .. reset the leaves below us
  }

  for (j=1; j <= this_len; j++) {   # build up the prefix string
     if   (j == 1)   prefix = array[j] "."
     else            prefix = "  " prefix array[j] "."
  }

  sub(/^\*+/, prefix)
  last_len = this_len
  prefix = ""
}
{ print }
# --- end of script ---

which I call from emacs using:

(defun my-outline-produce-numbered ()
  (interactive)
  (assert (string-match "\\.otl$" (buffer-file-name)))
  (let ((s (shell-command-to-string
	    (format "nawk -f ~/bin/indentN.awk < %s" (buffer-file-name)))))
    (find-file (my-re-replace-in-string "otl$" "txt" (buffer-file-name)))
    (erase-buffer)
    (insert s)
    (goto-char (point-min))))
-- 
Benjamin

  parent reply	other threads:[~2004-02-24 21:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-02-24 20:15 Renumbering paragraphs automatically Timur Aydin
2004-02-24 21:18 ` Reiner Steib
2004-02-24 21:22 ` Benjamin Rutt [this message]
2004-02-24 21:26   ` Benjamin Rutt

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=wc3n078w4te.fsf@mu.cis.ohio-state.edu \
    --to=brutt+news@bloomington.in.us \
    /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).