How to tidy up a source file:

Separate table and figure numbering
- look at toc.

Tables: bold headings.
.TB -> .Table-heading

Bad words:
- adapt[eo]r? -> adapter
- no future: will
- no passive: are, be, is, been, by
- normally no however, generally
- maybe no might, probably, get active, necessarily (thanks, JHC)
  just
  the fact
  gets

- justify C comments (c-mode) to col 30
- justify shell script comments to column 42.
- fewer "Note that"
- 'only' after verb
- which->that
- no dangling references: check this, these
- opposite->converse
- replace -- with ".  "?
- remove ... which defines
- \\ -> \e
- control characters CTRL-M, not ^M
- Less first person (-> you)
- suffices->suffixes

- 2 spaces after periods:
(query-replace-regexp "\\. \\([^ 
]\\)" ".  \\1" nil)

- don't run __ together:
(query-replace-regexp "__" "_\\\\/_" nil)

- untabify

Check indented quotations

-- Indices for authors: search for " ["

check for tabu words:
- source program
- compiler option (->flag)
- portation
- configurability
- pid->Process ID
- i.e, e.g.
- super-user -> superuser
- file name extension->suffix
- Microsoft operating system

Tables: .sp .4v between items
 .ne 10 before
 remove center, 

Remove initial letter highlights (?)

Second level lists; .Ls B "" "\-"

Make sure we have a summary.

-- correct sequence in CW
(query-replace-regexp "\\\\f(CW\\\\s10" "\\\\s10\\\\f(CW" nil)
(query-replace-regexp "\\\\s0\\\\fR" "\\\\fR\\\\s0" nil)


Index stuff:

- F6 indexes all \fI stuff
- check tables
- text in lower case unless good reason
-- repeat section header as index hit
(query-replace-regexp "\\(\\.H. \"\\)\\(.*\\)\"" "\\1\\2\"
.X \"\\2\"" nil)
-- function call from section header.  This may not do what it should.
(query-replace-regexp "H\\(.\\) \"\\(.*\\)\"" "\\1h \"\\2\"
.X \"\\2, function call\"
.X \"function call, \\2\"" nil)
-- Xref for first column of a table
(query-replace-regexp "^\\([^ #\\{}
]+\\)#" ".X \"\\1\"
\\1#" nil)
-- Xref for second column of a table
(query-replace-regexp "\\(^\\.[^#]+#\\)\\([^
#]+\\)#" ".X \"\\2\"
\\1\\2#" nil)

-- add .X "foo, bar" to .X "bar, foo"
(query-replace-regexp "X \"\\(.*\\), \\(.*\\)\"$" "X \"\\1, \\2\"
.X \"\\2, \\1\"" nil)
-- add .X "foo, bar" to .X "bar foo"
(query-replace-regexp "X \"\\([^
,\\]+\\) \\([^
,\\]+\\)\"$" "X \"\\1 \\2\"
.X \"\\2, \\1\"" nil)
-- same without commas, 'command'
(query-replace-regexp "^.X \"\\([^ ,
]+\\) command\"" ".X \"\\1 command\"
.X \"command, \\1\"" nil)
-- remove plurals from index hits
(query-replace-regexp "\\(.X \".*\\)s\"" "\\1\"" nil)

-- refs for well-known structs
(query-replace-regexp "^struct +\\([^ 	;
]+\\)" ".X \"struct, \\1\"
".X \"\\1, struct\"
struct \\1" nil)

Version 1.11:

Put in C shell equivalents to Bourne shell scripts

Version 1.13:

ise -> ize
Xenix -> XENIX

Version 2.0:

Get fonts in tables right for big macros

Version 2.2:

Replace .RS/.RE with .QS/.QE
Get file names for CD-ROM files into appcdrom.

V 2.4

Change .QQE to .QE when new macros become available
check comma  after page number and chapter refs

Change ^' to ^\&'
----------------------------------------

Put mail IDs in CW:
  (query-replace-regexp "(\\(.*@.*\\))" "(\\\\f(CW\\1\\\\fP)" nil)

Change heading lines:
  (query-replace-regexp "\\.ds h \\(.*\\)$" ".H2 \"\\1\"" nil)

Remove some of the heading junk:
  (replace-string "\\*h
.XS \\n%
\\*(SN \\*h
.XE
.nr h 1
.P
" "" nil)

Remove excess .Ps:

(defun tidy ()
  (interactive)
  (beginning-of-buffer)
  (query-replace-regexp "^\\.NH.*
" "" nil)
  (beginning-of-buffer)
  (query-replace-regexp "\\.P
\\.P" ".P" nil)
  (beginning-of-buffer)
  (query-replace-regexp "\\.P
.H" ".H" nil)
  (beginning-of-buffer)
  (query-replace-regexp ".br
.po 0.75i
.ll 6.0i
.ft C
.LP
.DS L
.ft R
.eo
" ".Ds
" nil)
  (beginning-of-buffer)
  (query-replace-regexp ".ft P
.LP
.br
.po 0.25i
.ll 7.0i
.ft R
" "" nil)
  (beginning-of-buffer)
  (query-replace-regexp "^\\.nr.*
" "" nil) )

Replace "foo"  with

.H4 "foo"
.Pn config-foo
\f(CWfoo\fP

  (query-replace-regexp "^\\(.*\\)$" ".H4 \"\\1\"
.Pn config-\\1
\\\\f(CW\\1\\\\fP" nil)


Change file names to .File:

(defun fixit ()
  (interactive)
  (save-excursion
    (beginning-of-buffer)
    (query-replace-regexp "\\\\fI\\([/~][^\\]+\\)\\\\fP\\([^\\]\\) *" "
.File \\1 \\2
" nil nil nil)
    
    (beginning-of-buffer)
    (query-replace-regexp "\\\\fI\\([/~][^\\]+\\)\\\\fP\\\\. *" "
.File \\1
" nil nil nil)
    
    (beginning-of-buffer)
    (query-replace-regexp "\\\\fI\\([^\\]+\\)\\\\fP\\([^\\]\\) *" "
.Command \\1 \\2
" nil nil nil)
    
    (beginning-of-buffer)
    (query-replace-regexp "\\\\fI\\([^\\]+\\)\\\\fP\\\\. *" "
.Command \\1
" nil nil nil) 
    (beginning-of-buffer)
    (query-replace-regexp "^\\.X \"/.*
" "" nil nil nil)
    ) )

Remove index hits for file names:

(query-replace-regexp "\\.De
\\.L" ".De
.SPUP
.L" nil nil nil)

Put an .Sref round strings.

(query-replace-regexp "\\\\\\*\\[\\([^]]+\\)\\]" "
.Sref \\\\*[\\1] \\\\&
" nil nil nil)

CW widths:

7 pt: 84 chars
8 pt: 74 chars

$Id: totidy,v 2.6 2003/03/20 06:55:57 grog Exp grog $

From CFBSDIV proofread
----------------------

\rg as smaller superscript (done)
\| -> \/:
(query-replace-regexp "\\\\|" "\\\\/" nil nil nil)
filename ->file name (done)
Driver names: \fI
(query-replace-regexp "''\\([.,]\\)" "\\1''" nil nil nil)
In order ->

Don't include chapter titles in xrefs (look for [ch)
Consider changing "since" -> as, because, ...
which->that
(query-replace-regexp "[Vv]ersion" "Release" nil nil nil)
.Tn -> .Fn?
F6: index hits.
; Remove white space at EOL:
(query-replace-regexp "[ 	]+$" "" nil nil nil)
