home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
me34exe.zip
/
mutt
/
package
/
adjust.mut
next >
Wrap
Text File
|
1995-01-14
|
4KB
|
120 lines
;; adjust.mut : Format blocks of text
;; (adjust-lines) fills all lines of text starting at the line the point
;; is on and ending with the line n-lines-of-text -1 below the point or the
;; end of the buffer. Empty lines signal end of paragraph and are
;; otherwise ignored.
;; Paragraph indention is handled as follows: The first line is
;; indented the same as first line of text and subsequent lines are
;; indented the same as the second line.
;; Words ending in <terminal>[<quote><close>]* are followed by two
;; blanks, where <terminal> is any of ".:?!", <quote> is " or ', and
;; <close> is any of ")]}", e.g.:
;; end. of? sentence.' sorts!" of.) things?"]
;; If you want to convert a block of text into list of words one per
;; line, just set the right-margin to something small (like 0 or 1).
;; To Do:
;; Implement justify-line.
;; Handle backspace so that overstruck text is formatted properly.
;; C Durland 10/88 Public Domain
(const
things-that-require-2-blanks "[.:?!]"
things-that-can-also-end-sentences "[])}'\"]"
)
(include wspace.mut)
(small-int lines-left)
(defun
adjust-lines (int n-lines-of-text right-margin)(bool justify)
{
(int indent last-break-column blanks-needed col wrap-column)
(lines-left n-lines-of-text)(wrap-column (+ 1 right-margin))
(beginning-of-line)
(if (and (looking-at '\ *$') (== 2 (skip-blank-lines))) (done))
(label new-paragraph)
(skip-whitespace) (col (current-column)) ;; first line indent
(forward-line 1)
(skip-whitespace) (indent (current-column)) ;; second line indent
(forward-line -1) (current-column col)
(last-break-column (blanks-needed 0))
(while TRUE
{
(if (looking-at "[\^ ^I]+" TRUE) ;; skip over non-whitespace
{ ;; sitting at whitespace between words
(if (< wrap-column (+ (current-column) blanks-needed)) ;; split line
{
(if (== 0 last-break-column) ;; end of first word in line
{
(delete-whitespace) ;; remove space between words
(if (looking-at '$') ;; at end of line
{
(last-break-column (current-column)) ;; end of last word
(blanks-needed 0) ;; since already past wrap column
(continue)
})
}
(current-column last-break-column)) ;; split after last word
(newline) ;; split the line
;(if justify
; { (forward-line -1)(justify-line wrap-column)(forward-line 1) })
;(update)
(to-col indent) ;; start the new line
(last-break-column (blanks-needed 0))
}
;; else more stuff will fit on this line
{ ;; put blanks at end of last word
(col (+ (current-column) blanks-needed))
(current-column last-break-column)
(insert-text (extract-elements " " 0 blanks-needed))
(last-break-column (current-column col))
;; calculate blanks needed at end of current word
(while ;; take care of cases like "[foo.]"
{ (previous-character)
(and
(looking-at things-that-can-also-end-sentences)
(!= 1 (current-column))) ;; ugh
} ())
(blanks-needed
(if (looking-at things-that-require-2-blanks) 2 1))
(current-column last-break-column)
;; get ready for next word
(delete-whitespace)
}
) ;; end if
}
{ ;; else at end of line
(switch (skip-blank-lines) 1 (goto new-paragraph) 2 (done))
(forward-line -1)(end-of-line)
(delete-character)(delete-whitespace)
}
) ;; end if
}) ;; end while
}
;; Returns:
;; 0 (text on next line)
;; 1 (blank lines)
;; 2 (if no lines left to adjust)
;; Dot left at start of next non blank line.
skip-blank-lines HIDDEN
{
(byte blank-lines)
(blank-lines 0)
(while TRUE
{
(if (or (not (forward-line 1)) (== 0 (-= lines-left 1))) { 2 (done) })
(if (looking-at '\ *$')
(blank-lines 1)
(break))
})
blank-lines
}
)