home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / me34exe.zip / mutt / contrib / docmode.mut < prev    next >
Text File  |  1995-01-14  |  24KB  |  823 lines

  1. ;;
  2. ;; File:
  3. ;;     docmode.mut  -  document mode
  4. ;;
  5. ;; Description:
  6. ;;     This 'DocumentMode' is a replacement for 'TextMode'. The function
  7. ;;     'doc-format-paragraph' handles the formatting of paragraphs.  The
  8. ;;     function is able to recognize some special kinds  of  paragraphs,
  9. ;;     it allows  for  special  indentation  of  the  first  line  of  a
  10. ;;     paragraph and it handles justification.
  11. ;; 
  12. ;;     Paragraph indentation is as follows:
  13. ;; 
  14. ;;     - The indentation of the first  line  of  a  paragraph  is  never
  15. ;;       changed!
  16. ;; 
  17. ;;     - The indentation of a paragraph relative to the left edge of the
  18. ;;       paper is based  on  the  indentation  of  the  first  non-blank
  19. ;;       character on the first line of the paragraph.
  20. ;; 
  21. ;;     - The indentation of the 'tail' of a paragraph (all lines  except
  22. ;;       the first) is based on the indentation of the first line of the
  23. ;;       paragraph and the value of the variable 'docTailOffset':
  24. ;; 
  25. ;;       - If docTailOffset equals 0,  the  tail  of  the  paragraph  is
  26. ;;         alligned with the first line of the paragraph.
  27. ;; 
  28. ;;       - If docTailOffset not equals 0, the tail of the  paragraph  is
  29. ;;         indented by the sum of the indentation of the first line  and
  30. ;;         the  value   of   docTailOffset.   Note   that   a   negative
  31. ;;         docTailOffset gives an extra indented first line, a  positive
  32. ;;         docTailOffset gives an extra indented tail.
  33. ;; 
  34. ;;       - Paragraphs that start with a dash or a number followed  by  a
  35. ;;         right-brace are indented automatically.
  36. ;; 
  37. ;;     - The variable  'docJustify'  controls  whether  a  paragraph  is
  38. ;;       justified or not. All varieties of paragraphs can be justified,
  39. ;;       flushed left, flushed right or centered.
  40. ;; 
  41. ;;     Examples: (All examples assume docJustify equals TRUE)
  42. ;; 
  43. ;;     - This is the first example of a paragraph that is formatted with
  44. ;;       doc-format-paragraph. Indentation of the paragraph is based  on
  45. ;;       the dash ('- ').
  46. ;; 
  47. ;;     1) This is the second example of a paragraph  that  is  formatted
  48. ;;        with doc-format-paragraph. Indentation  of  the  paragraph  is
  49. ;;        based on the number ('1) ').
  50. ;; 
  51. ;;     This paragraph is the  third  example  of  a  paragraph  that  is
  52. ;;     formatted with doc-format-paragraph (assumes  that  docTailOffset
  53. ;;     equals 0).
  54. ;; 
  55. ;;        33) This  is  the  fourth  example  of  a  paragraph  that  is
  56. ;;            formatted with doc-format-paragraph. Indentation is  based
  57. ;;            on the number ('33) ') and on  the  fact  that  the  first
  58. ;;            line is indented.
  59. ;; 
  60. ;;         This  is  paragraph  number  five.   This   example   assumes
  61. ;;     docTailOffset equals -4. Then, although the  indentation  of  the
  62. ;;     first line equals 4, the tail is indented  (4  +  docTailIndent),
  63. ;;     which is 0.
  64. ;;          
  65. ;;       SIX This  is  paragraph  number  six.  This   example   assumes
  66. ;;           docTailOffset equals 4. Then, although the  indentation  of
  67. ;;           the first  line  equals  0,  the  tail  is  indented  (0  +
  68. ;;           docTailOffset), which is 4.
  69. ;; 
  70. ;;     - In the text below a 'special' paragraph  is  a  paragraph  that
  71. ;;       starts with a text defined in function 'doc-special-paragraph'.       
  72. ;; 
  73. ;; Known Bugs:
  74. ;;     - A big NEGATIVE  docTailIndent  gives  badly  distributed  extra
  75. ;;       spaces when justifying a paragraph.
  76. ;; 
  77. ;; History:
  78. ;;   942601   M.J. van der Velden
  79. ;;            - added support for repagination (see docform.mut)
  80. ;;            - more special paragraphs are recognized
  81. ;;            - fixed documentation errors
  82. ;;            - special formats now handled in function 
  83. ;;              'doc-special-paragraph'
  84. ;;            Public Domain (Version 2.3)
  85. ;;   930702   M.J. van der Velden
  86. ;;            - fixed documentation errors
  87. ;;            - less info in modeline (the clock is more interesting)
  88. ;;              removed 'doc-add-major-mode' and added 'doc-minor-mode'.
  89. ;;            Public Domain (Version 2.2)
  90. ;;   930130   M.J. van der Velden
  91. ;;            - Removed MAIN from doc-mode.
  92. ;;          - Added doc-flush-right (based on end-slide made by C.
  93. ;;              Durland in cstuff.mut)
  94. ;;            Public Domain (Version 2.1)
  95. ;;   930105   M.J. van der Velden
  96. ;;            Public Domain (Version 2.0)
  97. ;;   921119   M.J. van der velden
  98. ;;            - Fixed a formatting error when the last line of a 
  99. ;;              paragraph has exactly the correct format before 
  100. ;;              justification.
  101. ;;            - Added "doc-mode-hook".
  102. ;;            - Added functions to set or get the various "docXXX" 
  103. ;;              variables non-interactivally.
  104. ;;            - Changed format of major-mode and minor-mode.
  105. ;;            - Fixed some minor documentation errors.
  106. ;;            - Added '\a+)\ ' to be the start of a special paragraph.
  107. ;;          - added funtions to add text to the major mode.
  108. ;;   921005   M.J. van der Velden
  109. ;;            Public Domain (Version 1.0)
  110. ;;
  111.  
  112. (include me.mh)
  113.  
  114. ;; Global Constants.
  115. (const
  116.     DOC-DEF-LINES-ON-PAGE 60
  117.     DOC-DEF-RIGHT-MARGIN  72    
  118.     DOC-DEF-TAIL-OFFSET   0     
  119.     DOC-DEF-TAB-SIZE      4     
  120.     
  121.     DOC-DEF-JUSTIFY       TRUE  
  122.     DOC-DEF-RIGHT-FLUSH   FALSE 
  123.     DOC-DEF-CENTER        FALSE 
  124.     
  125.     DOC-MAJOR-MODE        "Doc"
  126.     DOC-MINOR-MODE        ""
  127.  
  128.     DOC-EMPTY-LINE        '\ *$'
  129. )
  130. ;; End Of Global Constants.
  131.  
  132. ;; Global Variables.
  133. (int
  134.     docRightMargin   ;; Current column to word wrap at (0 means no 
  135.                      ;; wrapping).
  136.     docTailOffset    ;; Offset between indentation of first line 
  137.                      ;; and the indentation of the rest of the 
  138.                      ;; paragraph.
  139.     docTabSize       ;; Tab size (0 means use the TAB character).
  140. )
  141.  
  142. (string
  143.     docMajorMode     ;; Major mode string
  144.     docMinorMode     ;; Minor mode string
  145. )
  146.  
  147. (bool
  148.     docJustify       ;; Justify?
  149.     docRightFlush    ;; Flush right?
  150.     docCenter        ;; Center?
  151.                      ;; Note: if all these options are false, paragraphs 
  152.                      ;;       are flushed left.
  153. )
  154. ;; End Of Global Variables.
  155.  
  156. ;; Paragraph movement and selection.
  157. (defun
  158.     doc-begin-of-paragraph
  159.     ;; pre:
  160.     ;;     true
  161.     ;; post:
  162.     ;;     if >THE-DOT between paragraphs then
  163.     ;;         THE-DOT> is at the beginning of the next paragraph
  164.     ;;     else
  165.     ;;         THE-DOT> is at the beginning of the current paragraph
  166.     ;;     endif
  167.     ;; returns:
  168.     ;;     void
  169.     {
  170.         (beginning-of-line)
  171.  
  172.         (while (and (not (EoB)) (looking-at DOC-EMPTY-LINE)) {
  173.             (forward-line 1)
  174.         })
  175.  
  176.         (while (forward-line -1) {
  177.             (if (looking-at DOC-EMPTY-LINE) {
  178.                 (forward-line 1)
  179.                 (break)
  180.             })
  181.         })
  182.     }
  183.  
  184.     doc-end-of-paragraph
  185.     ;; pre:
  186.     ;;     true
  187.     ;; post:
  188.     ;;     if >THE-DOT between paragraphs then
  189.     ;;         THE-DOT> is at the end of the next paragraph
  190.     ;;     else
  191.     ;;         THE-DOT> is at the end of the current paragraph
  192.     ;;     endif
  193.     ;; returns:
  194.     ;;     void
  195.     {
  196.         (beginning-of-line)
  197.  
  198.         (while (and (not (EoB)) (looking-at DOC-EMPTY-LINE)) {
  199.             (forward-line 1)
  200.         })
  201.  
  202.         (while (not (EoB)) {
  203.             (forward-line 1)
  204.             (if (looking-at DOC-EMPTY-LINE) {
  205.                 (break)
  206.             })
  207.         })
  208.  
  209.         (forward-line -1)
  210.         (end-of-line)
  211.     }
  212.  
  213.     doc-select-paragraph
  214.     ;; pre:
  215.     ;;     true
  216.     ;; post:
  217.     ;;     if >THE-DOT between paragraphs then
  218.     ;;         THE-MARK> is at the beginning of the next paragraph
  219.     ;;         THE-DOT> is at the end of the next paragraph
  220.     ;;     else
  221.     ;;         THE-MARK> is at the beginning of the current paragraph
  222.     ;;         THE-DOT> is at the end of the current paragraph
  223.     ;;     endif
  224.     ;; returns:
  225.     ;;     void
  226.     {
  227.         (doc-begin-of-paragraph)
  228.         (set-mark THE-MARK)
  229.         (doc-end-of-paragraph)
  230.     }
  231. )
  232.  
  233. ;; Paragraph formatting.
  234. (defun
  235.     ;; pre:
  236.     ;;     true
  237.     ;; post:
  238.     ;;     true
  239.     ;; returns:
  240.     ;;     >THE-DOT is looking at the start of a special paragraph
  241.     doc-special-paragraph
  242.     {        
  243.         (or (looking-at '-\ ')
  244.             (looking-at '\d+)\ ')
  245.             (looking-at '\a+)\ ')
  246.             (looking-at '\d+.\d+)\ ')
  247.         )
  248.     }
  249.  
  250.     ;; pre:
  251.     ;;     >THE-DOT is at the beginning-of-paragraph
  252.     ;; post:
  253.     ;;     - indent> is the indentation level of current paragraph 
  254.     ;;     - tailOffset> is the tail offset of the current paragraph
  255.     ;;     - if the current paragraph is 'special' then
  256.     ;;           THE-DOT> is on the first line of the current paragraph
  257.     ;;           at column tailOffset>
  258.     ;;       else
  259.     ;;           THE-DOT> is on the first line of the current paragraph
  260.     ;;           at column indent>
  261.     ;;       endif
  262.     ;; returns:
  263.     ;;     void
  264.     doc-get-indent-and-tail (array int indent 1 tailOffset 1) HIDDEN
  265.     {
  266.         (skip-whitespace)
  267.         (indent 0 (current-column))
  268.  
  269.         (if (doc-special-paragraph) {
  270.             (while (not (is-space)) {
  271.                 (next-character)
  272.             })
  273.             (skip-whitespace)
  274.             (tailOffset 0 (- (current-column) (indent 0)))
  275.         } {
  276.             (tailOffset 0 docTailOffset)
  277.         })
  278.     }
  279.  
  280.     doc-justify-line (int from rightMargin) HIDDEN
  281.     ;; pre:
  282.     ;;     - current line has no trailing whitespace
  283.     ;;     - there is at most a single space between each word
  284.     ;;     - >from < >rightMargin
  285.     ;; post:
  286.     ;;     - the current line is justified such that at most
  287.     ;;       (>rightMargin - 1) characters are put on the line
  288.     ;;     - extra spaces are only added after column >from
  289.     ;; returns:
  290.     ;;     void
  291.     {
  292.         (int noOfGaps)
  293.         (int noOfExtraSpaces)
  294.         (int widening)
  295.  
  296.         ;; calculate the number of gaps
  297.         (noOfGaps 0)
  298.         (current-column from)
  299.         (while (not (looking-at '$')) {
  300.             (if (is-space) {
  301.                 (+= noOfGaps 1)
  302.             })
  303.             (next-character)
  304.         })
  305.  
  306.         ;; calculate the number of extra spaces
  307.         (end-of-line)
  308.         (noOfExtraSpaces (- rightMargin (current-column)))
  309.  
  310.         ;; add the extra spaces to the line
  311.         (current-column from)
  312.         (while (> noOfGaps 0) {
  313.             (if (is-space) {
  314.                 (widening (/ noOfExtraSpaces noOfGaps))
  315.                 (-= noOfExtraSpaces widening)
  316.                 (-= noOfGaps 1)
  317.                 (while (>= (-= widening 1) 0) {
  318.                     (insert-text " ")
  319.                 })
  320.             })
  321.             (next-character)
  322.         })
  323.     }
  324.  
  325.     doc-left-flush-line (int from) HIDDEN
  326.     ;; pre:
  327.     ;;     true
  328.     ;; post:
  329.     ;;     - sequences of more than one space at or after column >from
  330.     ;;       in the current line are replaced by a single space
  331.     ;;     - trailing whitespace is removed from the current line
  332.     ;;     - THE-DOT> is at the end-of-line
  333.     ;; returns:
  334.     ;;     void
  335.     {
  336.         (while (not (looking-at '$')) {
  337.             (if (is-space) {
  338.                 (next-character)
  339.                 (delete-whitespace)
  340.             } {
  341.                 (next-character)
  342.             })
  343.         })
  344.  
  345.         (delete-previous-whitespace)
  346.     }
  347.  
  348.     doc-right-flush-line (int from rightMargin) HIDDEN
  349.     ;; pre:
  350.     ;;     current line is flushed left from postion >from
  351.     ;; post:
  352.     ;;     - the current line is flushed right such that at most 
  353.     ;;       (>rightMargin -1) characters are put on the line
  354.     ;;     - extra spaces are added at column >from
  355.     ;; returns:
  356.     ;;     void
  357.     {
  358.         (int noOfExtraSpaces)
  359.  
  360.         (end-of-line)
  361.         (noOfExtraSpaces (- rightMargin (current-column)))
  362.  
  363.         (current-column from)
  364.         (while (>= (-= noOfExtraSpaces 1) 0) {
  365.             (insert-text " ")
  366.         })
  367.     }
  368.  
  369.     doc-center-line (int from rightMargin) HIDDEN
  370.     ;; pre:
  371.     ;;     the current line is flushed left from column >from
  372.     ;; post:
  373.     ;;     - the current line is centered between >from and 
  374.     ;;       (>rightMargin -1)
  375.     ;;     - extra spaces are added at column >from
  376.     ;; returns:
  377.     ;;     void
  378.     {
  379.         (int noOfExtraSpaces)
  380.  
  381.         (end-of-line)
  382.         (noOfExtraSpaces (/ (- rightMargin (current-column)) 2))
  383.  
  384.         (current-column from)
  385.         (while (>= (-= noOfExtraSpaces 1) 0) {
  386.             (insert-text " ")
  387.         })
  388.     }
  389.  
  390.     doc-find-split-position (int from rightMargin) HIDDEN
  391.     ;; pre:
  392.     ;;     - length of current line extends >rightMargin
  393.     ;;     - there is not more than one space between words
  394.     ;; post:
  395.     ;;     THE-DOT is on the "best" column to split the line
  396.     ;; returns:
  397.     ;;     void
  398.     {
  399.         (current-column rightMargin)
  400.         (while (and (> (current-column) from) (previous-character)) {
  401.             (if (is-space) {
  402.                 (break)
  403.             })
  404.         })
  405.  
  406.         ;; if line is solid, go to rightMargin...
  407.         (if (== (current-column) from) {
  408.             (current-column rightMargin)
  409.         })
  410.     }
  411.  
  412.     doc-format-previous-line 
  413.         (int from rightMargin) (bool lastOfParagraph) HIDDEN
  414.     ;; pre:
  415.     ;;     - there is a previous line
  416.     ;;     - the previous line is flushed left from column >from
  417.     ;; post:
  418.     ;;     - if not (>docJustify and >lastOfParagraph) then
  419.     ;;           the previous line is formatted according to >docJustify,
  420.     ;;           >docRightFlush, >docCenter, >from and >rightMargin.
  421.     ;;       endif
  422.     ;;     - THE-DOT> is at the beginning of the current line
  423.     ;; returns:
  424.     ;;     void
  425.     {
  426.         (forward-line -1)
  427.  
  428.         (cond
  429.             docJustify {
  430.                 (if (not (lastOfParagraph)) {
  431.                     (doc-justify-line from rightMargin)
  432.                 })
  433.             }
  434.             docRightFlush {
  435.                 (doc-right-flush-line from rightMargin)
  436.             }
  437.             docCenter {
  438.                 (doc-center-line from rightMargin)
  439.             }
  440.         )
  441.  
  442.         (forward-line 1)
  443.         (beginning-of-line)
  444.     }
  445.     
  446.     doc-format-paragraph
  447.     ;; pre:
  448.     ;;     true
  449.     ;; post:
  450.     ;;     - if >THE-DOT is between paragraphs then
  451.     ;;           the next paragraph is formatted
  452.     ;;       else
  453.     ;;           the current paragraph is formatted
  454.     ;;       endif
  455.     ;;     - THE-DOT> is after the current paragraph (therefore a second 
  456.     ;;       call formats the next paragraph, and so on)
  457.     ;;     - note: see 'description' in module heading for a description
  458.     ;;             of the kind of formatting supported
  459.     ;; returns:
  460.     ;;     void
  461.     {
  462.         (bool atEndOfParagraph)
  463.         (int  rightMargin)
  464.         (int  indent)
  465.         (int  tailOffset)
  466.         (int  from)
  467.  
  468.         (msg "Formatting... ")
  469.  
  470.         (rightMargin 
  471.             (+ (if (== 0 (word-wrap)) docRightMargin (word-wrap)) 1)
  472.         )
  473.         
  474.         (doc-begin-of-paragraph)
  475.         (doc-get-indent-and-tail (loc indent) (loc tailOffset))
  476.         (from (if (> tailOffset 0) (+ indent tailOffset) indent))
  477.         
  478.         (if (>= from rightMargin) {
  479.             (doc-end-of-paragraph)
  480.             (next-character)
  481.             (msg "Paragraph indentation extends the right margin...")
  482.             (done)
  483.         })
  484.                 
  485.         (atEndOfParagraph FALSE)
  486.         (while (not atEndOfParagraph) {
  487.             (doc-left-flush-line (current-column))
  488.  
  489.             (cond
  490.                 (> (current-column) rightMargin) {
  491.                     ;; a "long line"...
  492.                     (doc-find-split-position from rightMargin)
  493.                     (newline)
  494.                     (doc-format-previous-line from rightMargin FALSE)
  495.  
  496.                     ;; indent the current line...
  497.                     (delete-whitespace)
  498.                     (to-col (+ indent tailOffset))
  499.                 }
  500.  
  501.                 (< (current-column) rightMargin) {
  502.                     ;; a "short" line, go and see the next line...
  503.                     (next-character)
  504.                     (atEndOfParagraph (or (EoB) (looking-at DOC-EMPTY-LINE)))
  505.                     (if (not atEndOfParagraph) {
  506.                         ;; join the current line with the previous line...
  507.                         (delete-previous-character)
  508.                         (insert-text " ")
  509.                         (delete-whitespace)
  510.                     })
  511.                 }
  512.  
  513.                 TRUE {
  514.                     ;; length of line is ok, go and see the next line
  515.                     (next-character)
  516.                     (atEndOfParagraph (or (EoB) (looking-at DOC-EMPTY-LINE)))
  517.                     (if (not atEndOfParagraph) {
  518.                         ;; indent the current line...
  519.                         (delete-whitespace)
  520.                         (to-col (+ indent tailOffset))
  521.                     })
  522.                 }
  523.             )
  524.         })
  525.  
  526.         ;; format the last line of the paragraph...
  527.         (doc-format-previous-line indent rightMargin TRUE)
  528.         
  529.         (msg "Formatted!")
  530.     }
  531. )
  532.  
  533. ;; Simple formatting functions
  534. (defun
  535.     doc-flush-right
  536.     {
  537.         (int col n x)
  538.  
  539.         (n (if (arg-flag) (arg-prefix) docRightMargin))
  540.     
  541.         (delete-horizontal-space)
  542.         (col (current-column))
  543.         (end-of-line)
  544.         (x (+ 1 (- n (current-column))))
  545.         (current-column col)
  546.         (to-col (+ col x))
  547.     }
  548. )
  549.  
  550. ;; Interactivally change document options.
  551. (defun
  552.     doc-show-modes HIDDEN
  553.     ;; pre:
  554.     ;;     true
  555.     ;; post:
  556.     ;;     - major-mode> gives an identification of this Document mode
  557.     ;;     - minor-mode> gives information about the current paragraph 
  558.     ;;       formatting style according to >docJustify, >docRightFlush 
  559.     ;;       and >docCenter.
  560.     ;; returns:
  561.     ;;     void
  562.     {
  563.         (major-mode 
  564.             (concat 
  565.                 docMajorMode 
  566.                 "("
  567.                 (cond
  568.                     docJustify    "J"
  569.                     docRightFlush "R"
  570.                     docCenter     "C"
  571.                     TRUE          "L"
  572.                 )
  573.                 ")"
  574.             )
  575.         )
  576.  
  577.         (minor-mode docMinorMode)
  578.     }
  579.  
  580.     doc-set-tail
  581.     ;; pre:
  582.     ;;     true
  583.     ;; post:
  584.     ;;     - the user is allowed to enter a new >docTailOffset>
  585.     ;; returns:
  586.     ;;     void
  587.     {
  588.         (string answer)
  589.  
  590.         (answer (ask (concat "Tail [" docTailOffset "]: ")))
  591.         (if (!= answer "") {
  592.             (docTailOffset (convert-to NUMBER answer))
  593.         })
  594.     }
  595.     
  596.     doc-set-tab-size
  597.     ;; pre:
  598.     ;;     true
  599.     ;; post:
  600.     ;;     - the user is allowed to enter a new >docTabSize>
  601.     ;;     - tab-stops> equals docTabSize>
  602.     ;; returns:
  603.     ;;     void
  604.     {
  605.         (string answer)
  606.         
  607.         (answer (ask (concat "Tab Size [" docTabSize "]: ")))
  608.         (if (!= answer "") {
  609.             (docTabSize (convert-to NUMBER answer))
  610.             (tab-stops docTabSize)
  611.         })
  612.     }
  613.  
  614.     doc-set-right-margin
  615.     ;; pre:
  616.     ;;     true
  617.     ;; post:
  618.     ;;     - the user is allowed to enter a new >docRightMargin>
  619.     ;;     - word-wrap> equals docRightMargin>
  620.     ;; returns:
  621.     ;;     void
  622.     {
  623.         (string answer)
  624.  
  625.         (answer (ask (concat "Right margin [" docRightMargin "]: ")))
  626.         (if (!= answer "") {
  627.             (docRightMargin (convert-to NUMBER answer))
  628.             (word-wrap docRightMargin)
  629.         })
  630.     }
  631.  
  632.     doc-set-justify
  633.     ;; pre: 
  634.     ;;     true
  635.     ;; post:
  636.     ;;     - docJustfiy>  equals TRUE
  637.     ;;     - docRightFlush> equals FALSE
  638.     ;;     - docCenter> equals FALSE
  639.     ;;     - changes are reflected in modes
  640.     ;; returns:
  641.     ;;     void
  642.     {
  643.         (docJustify    TRUE)
  644.         (docRightFlush FALSE)
  645.         (docCenter     FALSE)
  646.  
  647.         (doc-show-modes)
  648.     }
  649.  
  650.     doc-set-left-flush
  651.     ;; pre: 
  652.     ;;     true
  653.     ;; post:
  654.     ;;     - docJustfiy>  equals FALSE
  655.     ;;     - docRightFlush> equals FALSE
  656.     ;;     - docCenter> equals FALSE
  657.     ;;     - changes are reflected in modes
  658.     ;; returns:
  659.     ;;     void
  660.     {
  661.         (docJustify    FALSE)
  662.         (docRightFlush FALSE)
  663.         (docCenter     FALSE)
  664.  
  665.         (doc-show-modes)
  666.     }
  667.  
  668.     doc-set-right-flush
  669.     ;; pre: 
  670.     ;;     true
  671.     ;; post:
  672.     ;;     - docJustfiy>  equals FALSE
  673.     ;;     - docRightFlush> equals TRUE
  674.     ;;     - docCenter> equals FALSE
  675.     ;;     - changes are reflected in modes
  676.     ;; returns:
  677.     ;;     void
  678.     {
  679.         (docJustify    FALSE)
  680.         (docRightFlush TRUE)
  681.         (docCenter     FALSE)
  682.  
  683.         (doc-show-modes)
  684.     }
  685.  
  686.     doc-set-center
  687.     ;; pre: 
  688.     ;;     true
  689.     ;; post:
  690.     ;;     - docJustfiy>  equals FALSE
  691.     ;;     - docRightFlush> equals FALSE
  692.     ;;     - docCenter> equals TRUE
  693.     ;;     - changes are reflected in modes
  694.     ;; returns:
  695.     ;;     void
  696.     {
  697.         (docJustify    FALSE)
  698.         (docRightFlush FALSE)
  699.         (docCenter     TRUE)
  700.  
  701.         (doc-show-modes)
  702.     }
  703. )
  704.  
  705. ;; Non-interactivally change document options.
  706. (defun
  707.     ;; set or get docTailOffset
  708.     doc-tail-offset
  709.     {
  710.         (if (!= 0 (nargs)) {
  711.             (docTailOffset (arg 0))
  712.         })
  713.         docTailOffset
  714.     }
  715.     
  716.     ;; set or get docRightMargin
  717.     doc-right-margin
  718.     {
  719.         (if (!= 0 (nargs)) {
  720.             (docRightMargin (arg 0))
  721.         })
  722.         docRightMargin
  723.     }
  724.     
  725.     ;; set or get docTabSize
  726.     doc-tab-size
  727.     {
  728.         (if (!= 0 (nargs)) {
  729.             (docTabSize (arg 0))
  730.         })
  731.         docTabSize
  732.     }
  733.     
  734.     ;; set or get docJustify
  735.     doc-justify
  736.     {
  737.         (if (!= 0 (nargs)) {
  738.             (docJustify (arg 0))
  739.         })
  740.         docJustify
  741.     }
  742.     
  743.     ;; set or get docRightFlush
  744.     doc-right-flush
  745.     {
  746.         (if (!= 0 (nargs)) {
  747.             (docRightFlush (arg 0))
  748.         })
  749.         docRightFlush
  750.     }
  751.     
  752.     ;; set or get docCenter
  753.     doc-center
  754.     {
  755.         (if (!= 0 (nargs)) {
  756.             (docCenter (arg 0))
  757.         })
  758.         docCenter
  759.     }
  760.  
  761.     ;; set or get docMinorMode
  762.     doc-minor-mode
  763.     {
  764.         (if (!= 0 (nargs)) {
  765.             (docMinorMode (arg 0))
  766.         })
  767.         docMinorMode
  768.     }
  769. )
  770.  
  771. ;; Hooks into docform.mut
  772. (defun
  773.     doc-repaginate        { (autoload "doc-repaginate"        "docform"               ) }
  774.     doc-set-lines-on-page { (autoload "doc-set-lines-on-page" "docform"               ) }
  775.     doc-lines-on-page     { (autoload "doc-lines-on-page"     "docform" (push-args 0) ) }
  776.     doc-remove-pagebreaks { (autoload "doc-remove-pagebreaks" "docform"               ) }
  777. )
  778.  
  779. ;; Enable document mode.
  780. (defun
  781.     doc-mode
  782.     ;; pre:
  783.     ;;     true
  784.     ;; post:
  785.     ;;     - all active modes are cleared
  786.     ;;     - current mode settings are displayed
  787.     ;;     - all global variables used by this modules are given their
  788.     ;;       default values
  789.     ;;     - some keys are rebound according to this mode
  790.     ;; returns:
  791.     ;;     void
  792.     {
  793.         (clear-modes)
  794.  
  795.         (bind-local-key "newline-and-indent"     "C-M")
  796.         (bind-local-key "doc-end-of-paragraph"   "M-e")
  797.         (bind-local-key "doc-begin-of-paragraph" "M-a")
  798.         (bind-local-key "doc-select-paragraph"   "M-h")
  799.         (bind-local-key "doc-format-paragraph"   "M-J")
  800.         (bind-local-key "doc-flush-right"        "M-`")
  801.  
  802.         (docRightMargin DOC-DEF-RIGHT-MARGIN)
  803.         (docTailOffset  DOC-DEF-TAIL-OFFSET)
  804.         (docTabSize     DOC-DEF-TAB-SIZE)
  805.  
  806.         (docJustify     DOC-DEF-JUSTIFY)
  807.         (docRightFlush  DOC-DEF-RIGHT-FLUSH)
  808.         (docCenter      DOC-DEF-CENTER)
  809.     
  810.     (docMajorMode   DOC-MAJOR-MODE)
  811.     (docMinorMode   DOC-MINOR-MODE)
  812.  
  813.         (tab-stops      DOC-DEF-TAB-SIZE)
  814.         (word-wrap      DOC-DEF-RIGHT-MARGIN)
  815.  
  816.         (if (pgm-exists "doc-mode-hook") {
  817.             (floc "doc-mode-hook" ())
  818.         })
  819.     
  820.         (doc-show-modes)
  821.     }
  822. )
  823.