jed-users mailing list

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

Re: hooks and modes


On 14.11.08, John E. Davis wrote:
> Michele Dondi <blazar@xxxxxxxxxxxxxxxxxx> wrote:

> > 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.

I do not think so.

> > How does it work? Is there a sybol table or so that gets scanned for
> > functions having.

It utilises the fact that SLang is an interpreted language. Hence
looking for a function given its name as a string value is
straightforward.

> 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...

I do not think that it is more reliable. However, it might be more
easy in case there is already a function that you want to run as
"foo_mode_hook" but it is named "bar_fly". In this case, instead of

   define foo_mode_hook() { bar_fly(); }

it might be simpler to register it as 

   mode_set_mode_info("foo", "mode_hook", "bar_fly");

or

   mode_set_mode_info("foo", "mode_hook", &bar_fly);


> You can create such a mechanism by defining your own
> global_mode_hook:

This could be made a bit simpler using mode_info:

   define global_mode_hook (mode_hook_name)
   {
      call_function(mode_get_mode_info("mode_hook"));
   }

   mode_set_mode_info("foo", "mode_hook", &bar_fly);

Maybe this could even go into the (currently empty) default definition
of global_mode_hook() in site.sl?

Günter

--------------------------
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]