jed-users mailing list

[2008 Date Index] [2008 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

Re: hooks and modes


Michele Dondi <blazar@xxxxxxxxxxxxxxxxxx> wrote:
> Out of curiosity: I'm a big fan of KISS approaches all the way, and I 
> would regard relying on a name convention as KISS enough, but... err well, 
> perhaps even TOO simple, to the point of being error prone. How does it 
> work? Is there a sybol table or so that gets scanned for functions having 
[...]

If the name of the mode is "foo_mode", then the foo_mode function will
make the function call:

  run_mode_hooks ("foo_mode_hook");

The run_mode_hooks function is defined in site.sl.  It first calls a
function call `global_mode_hook' with the name of the mode hook
("foo_mode_hook" in this case), then if `foo_mode-hook' exists, it
will call it.

> names ending in "_hook"? Wouldn't it be more reliable to have, say, a 
> register_hook_for_mode() function instead, at the expense of some more 
> verbosity. Please feel free to laugh at me if all this is too naive...

You can create such a mechanism by defining your own global_mode_hook.

   private variable Mode_Hooks = Assoc_Type[];
   define register_hook_for_mode (mode_hook_name, func)
   {
       Mode_Hooks[mode_hook_name] = &func;
   }
   
   define global_mode_hook (mode_hook_name)
   {
       if (assoc_key_exists (Mode_Hooks, mode_hook_name))
         (@Mode_Hooks[mode_hook_name])();
   }
   
   private define my_foo_mode_hook ()
   {
      % whatever
   }
   register_hook_for_mode ("foo_mode_hook", &my_foo_mode_hook);

I encourage you to look at the various *.sl files in jed lib/
directory.  I think that you will find that it is not too difficult to
understand.

--John

--------------------------
To unsubscribe send email to <jed-users-request@xxxxxxxxxxx> with
the word "unsubscribe" in the message body.
Need help? Email <jed-users-owner@xxxxxxxxxxx>.


[2008 date index] [2008 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]