jed-users mailing list

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

Re: c_mode_hook configuration


On Thu, 4 Oct 2007 09:37:42 +0100 (CET), Peter Karlsson <peter@xxxxxxxxxxxxxxxx> said:
>Is it possible to get the C mode to follow the indentation of the
>previous line? I can live with having to backspace after entering an
>opening bracket, but not for each new line.

Try the following in your jedrc file.  It is not as smooth as the
routines as C mode but does automate things a bit.  --John

define my_c_mode_indent_hook ()
{
   push_spot ();
   EXIT_BLOCK
     {
	pop_spot ();
	if (bolp ())
	  skip_white ();
     }
   bol ();
   variable mark = create_user_mark ();
   skip_white ();
   variable col = what_column ();
   variable ch = what_char ();
   if (ch == '}')
     () = find_matching_delimiter ('}');
   else
     bskip_chars ("\n \t");
   bol_skip_white ();
   variable indent_col = what_column ();
   if (ch == '{') indent_col += 3;
   if (what_char () == '}') indent_col -= 3;
   if (col == indent_col)
     return;
   goto_user_mark (mark);
   trim ();
   whitespace (indent_col-1);
}

define my_c_mode_indent ()
{
   my_c_mode_indent_hook ();
   push_spot_bol ();
   insert ("\t");
   pop_spot ();
}

public define c_mode_hook ()
{
   TAB = 3;
   set_buffer_hook ("indent_hook", "my_c_mode_indent_hook");
   local_setkey ("my_c_mode_indent", "\t");
}

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


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