jed-users mailing list

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

Re: Namespaces for modes?


On Sun, Jul 13, 2003 at 08:05:27PM +0000, Joerg Sommer wrote:
> Hi,
> 
> why no mode use a namespace instead of mode_i_do_something()? All
> prefixes their functions and variables with mode_ even though the good
> concept of namespaces exist. Isn't it practicable? Are there any
> conflics? Which?

When writing a mode, I usually make functions that are intended to be used
from outside global (with names like "mode_*"). So, apropos("^mode") will
find all of them.

Functions that are only used by the same mode or derived modes can be in the
named namespace (although I sometimes use mode_* even there, for clarity
within the mode.sl file).
This also works for functions to be bound to the modes keymap or menu entries
with e.g.
  definekey("mode->fun", Key_F11);

A problem occures when working on a mode that declares a namespace:
reevaluating with evalbuffer results in an error.

After some other attempts, I now use this construct:

% evaluate buffer or region (if defined)
public define slang_run_buffer ()
{
   variable curbuf = whatbuf(), stkdepth_before = _stkdepth();
   if(is_visible_mark())
     narrow_to_region();
   push_spot();
   bob();
   if (bol_fsearch("implements"))
     {
	% error save implement of a namespace (just use if already existent)
	skip_word();
	skip_word();
	variable namespace = get_word;
	% show(namespace, current_namespace());
	ERROR_BLOCK
	  {
	     if(get_y_or_n("Namespace " + namespace + " exists. Use it?") == 1)
	       {
		  _clear_error;
		  use_namespace(namespace);
	       }
	  }
     }
   pop_spot();
   evalbuffer();
   setbuf(curbuf);
   widen_region();
   if (_stkdepth() > stkdepth_before)
     {
	show(whatbuf() + " leaved stuff on stack!");
	show_stack();
     }
   message(curbuf + " evaluated " + MESSAGE_BUFFER);
}


G|nter

-- 
Milde at ife.et.tu-dresden.de

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


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