home *** CD-ROM | disk | FTP | other *** search
- ;; 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
-
- (const
- things-that-require-2-blanks "[.:?!]"
- things-that-can-also-end-sentences "[])}'\"]"
- )
-
- (include wspace.mut)
-
- (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))
- (forward-line 1)
- (skip-whitespace) (indent (current-column))
- (forward-line -1) (current-column col)
- (last-break-column (blanks-needed 0))
- (while TRUE
- {
- (if (skip-over-text) ; looking at text
- {
- (if (< wrap-column (+ (current-column) blanks-needed))
- {
- (if (== 0 last-break-column)
- {
- (kill-whitespace)
- (if (looking-at '$') ;; might be at end of region
- {
- (last-break-column (current-column))
- (blanks-needed 0) ;; since already past wrap column
- (continue)
- })
- }
- (current-column last-break-column))
- (newline)
- ;(if justify
- ; { (forward-line -1)(justify-line wrap-column)(forward-line 1) })
- ;(update)
- (to-col indent)
- (last-break-column (blanks-needed 0))
- }
- {
- ;; put blanks at end of last word
- (col (+ (current-column) blanks-needed))
- (current-column last-break-column)
- (insert-text (substr " " 0 blanks-needed))
- (last-break-column (current-column col))
- ;; calculate blanks needed at end of current word
- (while
- { (previous-character)
- (looking-at things-that-can-also-end-sentences) } ())
- (blanks-needed
- (if (looking-at things-that-require-2-blanks) 2 1))
- (current-column last-break-column)
- ;; get ready for next word
- (kill-whitespace)
- }
- )
- }
- { ;; end of line
- (switch (skip-blank-lines) 1 (goto new-paragraph) 2 (done))
- (forward-line -1)(end-of-line)
- (delete-character)(kill-whitespace)
- }
- )
- })
- }
- skip-over-text HIDDEN ; TRUE if skiped over text, FALSE if EoL
- {
- (if (looking-at '$') { FALSE (done) })
- (if (looking-at "\\([\^ ^I]+\\)")
- { (arg-prefix (strlen (get-matched '\1')))(next-character) TRUE }
- FALSE
- )
- }
- ;; Returns: 0 (text on next line), 1 (blank lines), 2 (if bottoms out)
- ;; Point 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
- }
- )
-