- Subject: Re: c_mode_hook configuration
- From: "John E. Davis" <davis@xxxxxxxxxxxxx>
- Date: Sat, 13 Oct 2007 03:28:18 -0400
On Tue, 9 Oct 2007 12:27:52 +0100 (CET), Peter Karlsson <peter@xxxxxxxxxxxxxxxx> said:
> int main ()
> {
> <tab>if (foo)
> <tab><tab>{
> <tab><tab>bar();
> <tab><tab>}
> <tab>
> <tab>switch (foo)
> <tab><tab>{
> <tab><tab>case bar:
> <tab><tab><tab>break;
> <tab><tab>case baz:
> <tab><tab><tab>break;
> <tab><tab>default:
> <tab><tab><tab>break;
> <tab><tab>}
> }
I strongly encourage you to try using the version of jed in the SVN
repository, which I believe can be customized to get the desired
indentation. It should build quite easily under cygwin.
With that said, here is another crude attempt to achieve this with
earlier versions of jed. Keep in mind that it does not handle
comments, etc. If you want that, you will need to upgrade. Good
luck, --John
define my_c_mode_indent_hook ()
{
push_spot ();
bol ();
variable mark = create_user_mark ();
variable col, indent_col;
EXIT_BLOCK
{
if (col != indent_col)
{
goto_user_mark (mark);
trim ();
whitespace (indent_col-1);
}
pop_spot ();
if (bolp ())
skip_white ();
}
skip_white ();
col = what_column ();
variable ch = what_char ();
variable is_case = looking_at ("case ");
if (ch == '}')
() = find_matching_delimiter ('}');
else
bskip_chars ("\n \t");
bol_skip_white ();
variable ch1 = what_char ();
variable is_case1 = looking_at ("case ");
indent_col = what_column ();
if ((ch == '}') and (ch1 == '{'))
return;
if (ch == '{')
{
if (indent_col != 1) indent_col += 3;
return;
}
if (ch1 == '}')
{
indent_col -= 3;
return;
}
if (ch1 == '{')
{
if (indent_col == 1) indent_col += 3;
return;
}
if (is_case1)
{
if (not is_case)
indent_col += 3;
return;
}
if (is_case and (ch1 != '{'))
indent_col -= 3;
}
define my_c_mode_indent ()
{
my_c_mode_indent_hook ();
push_mark ();
bskip_white ();
variable is_bol = bolp ();
skip_white ();
pop_mark (not is_bol);
}
public define c_mode_hook ()
{
TAB = 3;
set_buffer_hook ("indent_hook", "my_c_mode_indent_hook");
local_setkey ("my_c_mode_indent", "\t");
local_setkey ("self_insert_cmd", ":");
}
--------------------------
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]