home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
me34src.zip
/
me3
/
mutt
/
contrib
/
docform.mut
< prev
next >
Wrap
Text File
|
1995-01-14
|
7KB
|
260 lines
;;
;; File:
;; docform.mut - document formatting
;;
;; Description:
;; Support for formatting of documents.
;;
;; The function 'doc-repaginate' is able to repaginate a document
;; (using ^L's at the beginning of an empty line line). The
;; repagination function is modelled after MS-WORD version 4.00.
;;
;; Although useful as a standalone package, this module is
;; modelled as an extension to 'docmode'.
;;
;; Known bugs:
;; - Repagination ussumes ^L's are at the beginning of an empty line
;; (so be careful when entering a ^L manually, that is, without the
;; help of the repagination functions).
;;
;; Historie:
;; 940126 M.J. van der Velden
;; - Creation
;; Public Domain (Version 1.0)
;;
(include "me.mh")
;; Constants that define defaults for the global variables below.
(const
DOC-DEF-LINES-ON-PAGE 60
DOC-NEWPAGE "^L"
DOC-NEWLINE "^J"
)
;; End Of Constants to define default behavior.
;; Global variables
(int
docLinesOnPage ;; Number of lines allowed on a page.
)
;; End Of Globale Variables
;; Interactivally change document options.
(defun
doc-set-lines-on-page
{
(string answer)
(answer (ask (concat "Maximum number of lines on page [" docLinesOnPage "]: ")))
(if (!= answer "") {
(docLinesOnPage (convert-to NUMBER answer))
(word-wrap docLinesOnPage)
})
}
)
;; Non-interactivally change document options.
(defun
;; set or get docLinesOnPage
doc-lines-on-page
{
(if (!= 0 (nargs)) {
(docLinesOnPage (arg 0))
})
docLinesOnPage
}
)
;; Repagination functions
(defun
doc-remove-pagebreaks
{
(msg "Removing pagebreaks... ")
(save-point
{{
(beginning-of-buffer)
(while (not (EoB)) {
(if (search-forward DOC-NEWPAGE) {
(beginning-of-line)
(cut-line)
}{
(break)
})
})
}})
(msg "Pagebreaks removed!")
}
doc-keep-pagebreak (int pageNo linesOnPage) HIDDEN
{
(int key)
(bool ready)
(msg linesOnPage " line" (if (== linesOnPage 1) "" "s") " on page " pageNo
". Press Y to keep pagebreak, N to remove or Q to quit... "
)
(update)
(ready FALSE)
(while (not ready) {
(key (get-key))
(switch key
0x0079 { ;; y
(ready TRUE)
}
0x0059 { ;; Y
(ready TRUE)
}
0x006E { ;; n
(cut-line)
(ready TRUE)
}
0x004E { ;; N
(cut-line)
(ready TRUE)
}
0x0071 { ;; q
(msg "Repagination aborted!")
(halt)
(ready TRUE)
}
0x0051 { ;; Q
(msg "Repagination aborted!")
(halt)
(ready TRUE)
}
0x0147 { ;; ^G
(msg "Repagination aborted!")
(halt)
(ready TRUE)
}
default {
(ready FALSE)
}
)
})
(or (== key 0x0079) (== key 0x0059)) ;; y or Y
}
doc-confirm-pagebreak (int pageNo linesOnPage maxLinesOnPage) HIDDEN
{
(int key)
(bool ready)
(int lineNo)
(lineNo linesOnPage)
(ready FALSE)
(while (not ready) {
(msg lineNo " lines on page " pageNo
". Press Y to confirm, Up/Down to move or Q to quit... "
)
(update)
(key (get-key))
(switch key
0x0079 { ;; y
(insert-text DOC-NEWPAGE DOC-NEWLINE)
(ready TRUE)
}
0x0059 { ;; Y
(insert-text DOC-NEWPAGE DOC-NEWLINE)
(ready TRUE)
}
0x0843 { ;; Up
(if (and (> lineNo 1) (forward-line -1)) {
(-= lineNo 1)
(update)
})
(ready FALSE)
}
0x0150 { ;; ^P
(if (and (> lineNo 1) (forward-line -1)) {
(-= lineNo 1)
(update)
})
(ready FALSE)
}
0x0844 { ;; Down
(if (forward-line 1) {
(+= lineNo 1)
(update)
})
(ready FALSE)
}
0x014E { ;; ^N
(if (forward-line 1) {
(+= lineNo 1)
(update)
})
(ready FALSE)
}
0x0071 { ;; q
(msg "Repagination aborted!")
(halt)
(ready TRUE)
}
0x0051 { ;; Q
(msg "Repagination aborted!")
(halt)
(ready TRUE)
}
0x0147 { ;; ^G
(msg "Repagination aborted!")
(halt)
(ready TRUE)
}
default {
(ready FALSE)
}
)
})
(or (== key 121) (== key 89)) ;; y or Y
}
doc-repaginate
{
(int pageHeight)
(int lineNo)
(int linesOnPage)
(int maxLinesOnPage)
(int pageNo)
(beginning-of-buffer)
(lineNo 1)
(linesOnPage 0)
(maxLinesOnPage (doc-lines-on-page))
(pageNo 1)
(while (not (EoB)) {
(+= lineNo 1)
(if (looking-at DOC-NEWPAGE) {
(if (doc-keep-pagebreak pageNo linesOnPage) {
(+= pageNo 1)
(linesOnPage 0)
})
})
(if (== linesOnPage maxLinesOnPage) {
(if (doc-confirm-pagebreak pageNo linesOnPage 3) {
(+= pageNo 1)
(linesOnPage 0)
})
})
(forward-line 1)
(+= linesOnPage 1)
})
(msg "Repagination ready, " pageNo " pages counted!")
}
)
;; Initialization
(defun
MAIN
{
(docLinesOnPage DOC-DEF-LINES-ON-PAGE)
}
)