home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
me34src.zip
/
me3
/
mutt
/
builtin
/
hook.mut
< prev
next >
Wrap
Text File
|
1995-01-14
|
5KB
|
129 lines
;; Hook.mut : Hook central
;; These routines let lots of routines share ME hooks. For example, if you
;; want foo to called from buffer-created-hook, then just
;; (register-hook BUFFER-CREATED-HOOK "foo") and every time
;; (buffer-created-hook) is called, (foo) will be called.
;; Notes:
;; DO NOT defun buffer-created-hook or other hooks! If you do, you'll
;; ruin the party for everybody.
;; Hooks not here:
;; modeline-hook : Needs to be handled differently. See modeline.mut.
;; key-pressed-hook : Slows things down too much. Your on your own.
;; I define some of own hooks: the "I" ones. These are subsets of
;; existing hooks that are called when a buffer is Interactive. I do
;; this to avoid doing a bunch of work when I don't need to.
;; C Durland 10/89 Public Domain
(include me.mh)
(list
create-buffer-list
Icreate-buffer-list ;; interactive buffer created
clear-buffer-list
Iclear-buffer-list ;; interactive buffer cleared
free-buffer-list
Ifree-buffer-list
file-read-list
Ifile-read-list ;; interactive file read
enter-ME-list
leave-ME-list
process-list
command-line-list
stop-list
idle-list
)
(defun
register-hook (int hook-id)(string who-u-gonna-call)
{
(switch hook-id
CREATE-BUFFER-HOOK (add-hook create-buffer-list who-u-gonna-call)
ICREATE-BUFFER-HOOK (add-hook Icreate-buffer-list who-u-gonna-call)
CLEAR-BUFFER-HOOK (add-hook clear-buffer-list who-u-gonna-call)
ICLEAR-BUFFER-HOOK (add-hook Iclear-buffer-list who-u-gonna-call)
FREE-BUFFER-HOOK (add-hook free-buffer-list who-u-gonna-call)
IFREE-BUFFER-HOOK (add-hook Ifree-buffer-list who-u-gonna-call)
READ-FILE-HOOK (add-hook file-read-list who-u-gonna-call)
IREAD-FILE-HOOK (add-hook Ifile-read-list who-u-gonna-call)
ENTER-ME-HOOK (add-hook enter-ME-list who-u-gonna-call)
LEAVE-ME-HOOK (add-hook leave-ME-list who-u-gonna-call)
PROCESS-HOOK (add-hook process-list who-u-gonna-call)
COMMAND-LINE-HOOK (add-hook command-line-list who-u-gonna-call)
STOP-ME-HOOK (add-hook stop-list who-u-gonna-call)
IDLE-HOOK (add-hook idle-list who-u-gonna-call)
)
}
unregister-hook (int hook-id)(string name)
{
(switch hook-id
IDLE-HOOK (remove-hook idle-list name)
default FALSE
)
}
enter-ME-hook { (call-hooks enter-ME-list) }
leave-ME-hook { (call-hooks leave-ME-list) }
process-hook { (call-hooks process-list (push-args 0)) }
stop-ME-hook { (call-hooks stop-list (push-args 0)) }
idle-hook { (call-hooks idle-list (push-args 0)) }
create-buffer-hook { (two-timer create-buffer-list Icreate-buffer-list) }
clear-buffer-hook { (two-timer clear-buffer-list Iclear-buffer-list) }
free-buffer-hook { (two-timer free-buffer-list Ifree-buffer-list) }
read-file-hook { (two-timer file-read-list Ifile-read-list) }
command-line-hook { (call-hooks-until-true command-line-list (push-args 0)) }
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;; Gory Details ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun
two-timer (list hook-list Ihook-list)(hook-args) HIDDEN
{
(call-hooks hook-list (push-args 2))
(if (!= 0 (bit-and BFInteractive (buffer-flags -1)))
(call-hooks Ihook-list (push-args 2)))
}
call-hooks (list hook-list)(hook-args) HIDDEN
{
(int j z)
(for { (j 0)(z (length-of hook-list)) } (!= j z) (+= j 1)
(floc (extract-element hook-list j)(push-args 1))) ;; call the hook
}
call-hooks-until-true (list hook-list)(hook-args) HIDDEN
{
(int j z)
(for { (j 0)(z (length-of hook-list)) } (!= j z) (+= j 1)
(if (floc (extract-element hook-list j)(push-args 1)) ;; call the hook
(done)))
FALSE ;; nobody handled arg(s)
}
add-hook (list hook-list) (string name) HIDDEN
{
(int j z)
;; Check to see if name is already registered
(for { (j 0)(z (length-of hook-list)) } (!= j z) (+= j 1)
(if (== name (extract-element hook-list j)) (done)))
(insert-object hook-list 0 name) ;; put name in list
}
remove-hook (list hook-list) (string name) HIDDEN
{
(int j z)
(for { (j 0)(z (length-of hook-list)) } (!= j z) (+= j 1)
(if (== name (extract-element hook-list j))
{
(remove-elements hook-list j 1)
TRUE
(done)
}))
FALSE
}
)