home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 September
/
Simtel20_Sept92.cdr
/
msdos
/
editor
/
me_cd.arc
/
MUTTMODE.MUT
< prev
next >
Wrap
Text File
|
1988-10-10
|
5KB
|
193 lines
; muttmode.mut : an electric Mutt mode
; C Durland
(const
Mutt-wrapper 75 ; column to wrap block comments at
Mutt-start-comment ";; " ; what a comment usually starts with
Enter-key-action "newline-and-indent"
)
(defun
mutt-mode
{
(tab-stops 0)(word-wrap 0)
(bind-local-key Enter-key-action "^M")
(bind-local-key "Mutt-mode-{" "{")
(bind-local-key "Dr.Commento" "M-;")
(bind-local-key "BS-untabify" "^H")
(bind-local-key "format-Mutt-comment" "M-J")
(bind-local-key "deref-key" "F-3")
(bind-local-key "pgm-completer" "F-4")
}
)
(include me.h)
(include bs_untab.mut)
(defun
deref-key ; insert name of the function bound to a key
{
(string key 10 bind 80)
(key (ask "Key: "))
(if (!= "" (bind (key-bound-to key)))(insert-text bind))
}
pgm-completer ; use command completion
{ (insert-text (complete "command: " 23)) }
"Mutt-mode-{" ; handle {
{
(int key n)
(insert-text "{")(update)
(switch (key (get-key))
Space-bar
(if (looking-at '\ *$') ; only ws til end of line
{ (insert-text " () }")(arg-prefix 3)(previous-character) }
(insert-text " ")
)
Enter-key
{
(newline-and-indent)(n (+ 2 (current-column)))
(if (looking-at '\ *$') ; white space to end of line
{
(insert-text "}")
(beginning-of-line)(open-line)(to-col n)
(insert-text "()")(previous-character)
}
(to-col n)
)
}
default (exe-key key)
)
}
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;; Comment Mode ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun
Dr.Commento ; Start up a block comment
{
(int key col)
(col (current-column))(beginning-of-line)
(if (not (looking-at '\ *$')) ; Not ^[ws]$ => not a block comment
{
(current-column col)
(msg "Not a valid place to start a block comment!")
(done)
})
; turn on block comment mode
(current-column col)(insert-text Mutt-start-comment)
(word-wrap Mutt-wrapper)
(bind-local-key "Dr.Enter" "C-M")
(bind-local-key "end-Mutt-comment" "M-;")
(msg "Consulting Dr Commento")
}
end-Mutt-comment
{
(int col)
;; if [ws];[;...][ws] only thing on line, clear the line
(col (current-column))
(beginning-of-line)
(if (looking-at '\ *;+\ *$') ; [ws];[;...][ws]$
(kill-line)
(current-column col))
;; turn off comment mode
(word-wrap 0)
(bind-local-key Enter-key-action "C-M")
(bind-local-key "Dr.Commento" "M-;")
(msg "end comment")
}
Dr.Enter ; handle Return
{
(int key)
(open-line)(beginning-of-line)
(msg "Still consulting Dr Commento")
(if (looking-at '\(\ *;+\ *\)') ; [ws];[;...][ws]
{
(forward-line 1)
(insert-text (get-matched '\1'))
})
}
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;; Format block comment ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun
format-Mutt-comment
{
(int offset)
(string code-buffer 50 semis 50)
(code-buffer (buffer-name -1))
(delete-region-as-block)
(switch-to-buffer scratch-buffer)
(buffer-flags -1 BFGone)(clear-buffer -1)
(insert-register 0)
; get the ;'s that start a comment
(beginning-of-buffer)
(semis
(if (re-search-forward '^\ *\(;+\)') ; [ws];[;...]
(get-matched '\1')
";;" ; if no ;'s, use my favorite
))
; Get the block offset from left margin
; Hopefully on same line as start comment
(beginning-of-line)
(while (isspace) (next-character))
(offset (current-column))
(beginning-of-buffer)
(re-query-replace '^\ *;+' "") ; get rid of [white-space];[;...]
(msg "Formatting comment ...")
(beginning-of-buffer)
(adjust-lines 10000 (- Mutt-wrapper (- offset 1) (strlen semis)) FALSE)
(beginning-of-buffer)
; put ;'s in front of text
(while (not (EoB))
{
(if (looking-at '^$')
{ (arg-prefix 1)(kill-line)(continue) } ; remove blank lines
{ (to-col offset)(insert-text semis) } ; else prepend ;
)
(forward-line 1)
})
; replace comment
(beginning-of-buffer)(set-mark)(end-of-buffer)
(clear-register 0)(append-to-register 0)
(msg "Comment formatted.")
(switch-to-buffer code-buffer)(exchange-dot-and-mark)
(insert-register 0)
; clean up
(clear-buffer (attached-buffer scratch-buffer))
}
)
(defun
delete-region-as-block HIDDEN
{
(byte type)(int left-edge width height)(INT size)
(region-stats (loc type))
(if (== type MARK-ABOVE-DOT)(exchange-dot-and-mark))
(beginning-of-line)
(arg-prefix height)(kill-line)
}
)