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 >
Text File  |  1995-01-14  |  5KB  |  129 lines

  1. ;; Hook.mut : Hook central
  2. ;; These routines let lots of routines share ME hooks.  For example, if you
  3. ;;   want foo to called from buffer-created-hook, then just
  4. ;;   (register-hook BUFFER-CREATED-HOOK "foo") and every time
  5. ;;   (buffer-created-hook) is called, (foo) will be called.
  6. ;; Notes:
  7. ;;   DO NOT defun buffer-created-hook or other hooks!  If you do, you'll
  8. ;;     ruin the party for everybody.
  9. ;;   Hooks not here:
  10. ;;     modeline-hook : Needs to be handled differently.  See modeline.mut.
  11. ;;     key-pressed-hook : Slows things down too much.  Your on your own.
  12. ;;   I define some of own hooks:  the "I" ones.  These are subsets of
  13. ;;     existing hooks that are called when a buffer is Interactive.  I do
  14. ;;     this to avoid doing a bunch of work when I don't need to.
  15. ;; C Durland 10/89    Public Domain
  16.  
  17. (include me.mh)
  18.  
  19. (list
  20.    create-buffer-list
  21.   Icreate-buffer-list        ;; interactive buffer created
  22.    clear-buffer-list
  23.   Iclear-buffer-list        ;; interactive buffer cleared
  24.    free-buffer-list
  25.   Ifree-buffer-list
  26.    file-read-list
  27.   Ifile-read-list        ;; interactive file read
  28.   enter-ME-list
  29.   leave-ME-list
  30.   process-list
  31.   command-line-list
  32.   stop-list
  33.   idle-list
  34. )
  35.  
  36. (defun
  37.   register-hook (int hook-id)(string who-u-gonna-call)
  38.   {
  39.     (switch hook-id
  40.        CREATE-BUFFER-HOOK (add-hook  create-buffer-list    who-u-gonna-call)
  41.       ICREATE-BUFFER-HOOK (add-hook Icreate-buffer-list    who-u-gonna-call)
  42.  
  43.        CLEAR-BUFFER-HOOK  (add-hook  clear-buffer-list    who-u-gonna-call)
  44.       ICLEAR-BUFFER-HOOK  (add-hook Iclear-buffer-list    who-u-gonna-call)
  45.  
  46.        FREE-BUFFER-HOOK   (add-hook  free-buffer-list    who-u-gonna-call)
  47.       IFREE-BUFFER-HOOK   (add-hook Ifree-buffer-list    who-u-gonna-call)
  48.  
  49.        READ-FILE-HOOK      (add-hook  file-read-list    who-u-gonna-call)
  50.       IREAD-FILE-HOOK      (add-hook Ifile-read-list    who-u-gonna-call)
  51.  
  52.       ENTER-ME-HOOK      (add-hook enter-ME-list    who-u-gonna-call)
  53.       LEAVE-ME-HOOK      (add-hook leave-ME-list    who-u-gonna-call)
  54.       PROCESS-HOOK      (add-hook process-list    who-u-gonna-call)
  55.       COMMAND-LINE-HOOK   (add-hook command-line-list    who-u-gonna-call)
  56.       STOP-ME-HOOK      (add-hook stop-list        who-u-gonna-call)
  57.       IDLE-HOOK          (add-hook idle-list        who-u-gonna-call)
  58.     )
  59.   }
  60.   unregister-hook (int hook-id)(string name)
  61.   {
  62.     (switch hook-id
  63.       IDLE-HOOK           (remove-hook idle-list        name)
  64.       default           FALSE
  65.     )
  66.   }
  67.   enter-ME-hook        { (call-hooks enter-ME-list) }
  68.   leave-ME-hook        { (call-hooks leave-ME-list) }
  69.   process-hook        { (call-hooks process-list (push-args 0)) }
  70.   stop-ME-hook        { (call-hooks stop-list    (push-args 0)) }
  71.   idle-hook        { (call-hooks idle-list    (push-args 0)) }
  72.   create-buffer-hook { (two-timer create-buffer-list Icreate-buffer-list) }
  73.   clear-buffer-hook  { (two-timer clear-buffer-list  Iclear-buffer-list) }
  74.   free-buffer-hook   { (two-timer free-buffer-list   Ifree-buffer-list) }
  75.   read-file-hook     { (two-timer file-read-list     Ifile-read-list) }
  76.   command-line-hook { (call-hooks-until-true command-line-list (push-args 0)) }
  77. )
  78.  
  79. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  80. ;;;;;;;;;;;;;;;;;;;;; Gory Details ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  81. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  82.  
  83. (defun
  84.   two-timer (list hook-list Ihook-list)(hook-args) HIDDEN
  85.   {
  86.     (call-hooks hook-list (push-args 2))
  87.     (if (!= 0 (bit-and BFInteractive (buffer-flags -1)))
  88.     (call-hooks Ihook-list (push-args 2)))
  89.   }
  90.   call-hooks (list hook-list)(hook-args) HIDDEN
  91.   {
  92.     (int j z)
  93.  
  94.     (for { (j 0)(z (length-of hook-list)) }   (!= j z)   (+= j 1)
  95.       (floc (extract-element hook-list j)(push-args 1)))    ;; call the hook
  96.   }
  97.   call-hooks-until-true (list hook-list)(hook-args) HIDDEN
  98.   {
  99.     (int j z)
  100.  
  101.     (for { (j 0)(z (length-of hook-list)) }   (!= j z)   (+= j 1)
  102.       (if (floc (extract-element hook-list j)(push-args 1))  ;; call the hook
  103.     (done)))
  104.     FALSE        ;; nobody handled arg(s)
  105.   }
  106.   add-hook (list hook-list) (string name) HIDDEN
  107.   {
  108.     (int j z)
  109.  
  110.     ;; Check to see if name is already registered
  111.     (for { (j 0)(z (length-of hook-list)) }   (!= j z)   (+= j 1)
  112.       (if (== name (extract-element hook-list j)) (done)))
  113.     (insert-object hook-list 0 name)            ;; put name in list
  114.   }
  115.   remove-hook (list hook-list) (string name) HIDDEN
  116.   {
  117.     (int j z)
  118.  
  119.     (for { (j 0)(z (length-of hook-list)) }   (!= j z)   (+= j 1)
  120.       (if (== name (extract-element hook-list j))
  121.         {
  122.       (remove-elements hook-list j 1)
  123.       TRUE
  124.       (done)
  125.     }))
  126.     FALSE
  127.   }
  128. )
  129.