- Subject: Re: Looking for C/C++ (and S-Lang) programmers for testing
- From: "John E. Davis" <davis@xxxxxxxxxxxxx>
- Date: Sun, 12 Nov 2006 23:35:02 -0500
Olesen, Mark <Mark.Olesen@xxxxxxxxxxxxxxxx> wrote:
>For some background: I've recently started working with C/C++ on a
>particular project (www.openfoam.org) and found that the JED c-mode kept
>getting in the way of the coding standards for the project. The style is a
>slight variation of BSD style, which looked horrible with the default
>parenthesis indentation semantics. In adjusting the c-mode code, I also
>streamlined it a bit and add comments (so I could understand what it is
>doing).
I was unable to find any coding standard document for the OpenFoam
project. So I downloaded the code to see the style for myself. There
I managed to get a feeling for the style as reflected by such code
fragments as these:
return
(
position_
+ iRadius
* (
tangentialInjectionVector1_*cos(iAngle)
+ tangentialInjectionVector2_*sin(iAngle)
)
);
scalar tauStrip =
Cs_ * p.d()
* sqrt
(
fuels.rho(pressure, p.T(), p.X())
/ rhoAverage
)
/ mag(p.Urel(vel));
I have not had any luck properly indenting the above code using either
your version of cmode.sl or mine. In fact, I spent more time trying
to make the code work than it took for me to write a specialized
"foam_mode" that seems to work pretty well. The file implementing
this mode is attached below. However, it requires the latest version
of my cmode.sl, which is in jed's svn repository (0.99.19-38).
Also, in the process of playing with cmode.sl, I fixed some
indentation bugs that have been around for a long time. These include
the indentation of arrays and lists. multiline macros, and the
stairstepping of continuation lines.
Thanks, --John
%%%%%%%%%%%%%%%%%%%%%% foam.sl %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
require ("cmode");
private variable Foam_Indent = 4;
private define goto_effective_eol ()
{
eol ();
if (-2 == parse_to_point ())
{
% Skip past comment */
while (bfind("//") and (parse_to_point () != 0))
;
}
bskip_white ();
}
private define looking_at_char_in_list (list, solitary)
{
if (0 == length (where (what_char() == list)))
return 0;
if (solitary == 0)
return 1;
push_spot ();
go_right (1);
skip_white ();
variable ret = (eolp () or looking_at ("//"));
pop_spot ();
return ret;
}
private define looking_at_string_in_list (list)
{
variable str;
foreach str (list)
{
if (looking_at (str))
return str;
}
return NULL;
}
private define foam_indent_line ()
{
variable indent_chars = ['(','{','<', ':'];
variable outdent_chars = [')','}','>'];
variable outdent_ops = ["&&", "||", "+ ", "- ", "* ", "/ "];
variable indent_ops = ["<<", ">>"];
push_spot ();
EXIT_BLOCK
{
goto_spot ();
bskip_white ();
if (bolp (), pop_spot ())
bol_skip_white ();
}
if (0 == up_1 ())
{
bol_trim ();
return;
}
bskip_chars (" \t\n\f");
variable is_continuation = 0;
variable is_eos = 0;
goto_effective_eol ();
% See if the previous line ends in a semi-colon(eos) or continues
% to the next line.
if (parse_to_point () == 0)
{
bskip_white ();
if (blooking_at ("="))
is_continuation = 1;
else if (blooking_at (";"))
is_eos = 1;
}
bol_skip_white ();
if (eolp ())
bskip_chars (" \t\n\f");
bol_skip_white ();
if (eolp ())
return;
variable indent = what_column ();
variable op;
if (op = looking_at_string_in_list (outdent_ops), op != NULL)
{
go_right (strlen (op));
skip_white ();
indent = what_column ();
% if this is a continuation line with a trailing semicolon, outdent
if (is_eos)
indent -= Foam_Indent;
}
else if (op = looking_at_string_in_list (indent_ops), op != NULL)
{
indent -= Foam_Indent;
}
if (looking_at_char_in_list (indent_chars, 1))
indent += Foam_Indent;
goto_spot ();
% Back to line we are trying to indent
bol_skip_white ();
if (looking_at_char_in_list (outdent_chars, 0))
indent -= Foam_Indent;
else if (looking_at_char_in_list (indent_chars, 1))
is_continuation = 0;
else if (op = looking_at_string_in_list (outdent_ops), op != NULL)
indent -= 1 + strlen (strtrim (op));
else if (op = looking_at_string_in_list (indent_ops), op != NULL)
indent += Foam_Indent;
if (is_continuation)
indent += Foam_Indent;
if (indent <= 0)
indent = 0;
bol_skip_white ();
if (what_column () != indent)
{
bol_trim ();
whitespace (indent-1);
}
}
$1 = "Foam";
!if (keymap_p ($1))
{
copy_keymap ($1, "C");
definekey ("foam_insert_bra", "{", $1);
definekey ("foam_insert_ket", "}", $1);
}
define foam_mode ()
{
c_mode ();
TAB = 0;
set_mode ("Foam", 2);
set_buffer_hook ("indent_hook", &foam_indent_line);
%set_buffer_hook ("newline_indent_hook", &foam_newline_and_indent);
run_mode_hooks ("foam_mode_hook");
}
%%%%%%%%%%%%%%%%%%%%%%%%%%% end of foam.sl %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--------------------------
To unsubscribe send email to <jed-users-request@xxxxxxxxxxx> with
the word "unsubscribe" in the message body.
Need help? Email <jed-users-owner@xxxxxxxxxxx>.
[2006 date index]
[2006 thread index]
[Thread Prev] [Thread Next]
[Date Prev] [Date Next]