Idention of macro

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Idention of macro

Hans-5
Hello,
        Any one who knows how to enable idention for macros, help me please.

        I mean, I want:
-------------------
        a = 1;
        #ifdef MACRO1
        b = a;
        #else
        b = 2;
        #endif
--------------------
        While, what I get in Vim6.3 is:
--------------------
        a = 1;
#ifdef MACRO1
        b = a;
#else
        b = 2;
#endif
--------------------
        Vim always lets the macro decision begin at the start of the line.

Thanks

Yorkwar
20050919

Reply | Threaded
Open this post in threaded view
|

Re: Idention of macro

Gareth Oakes-2
Are you sure that's a good idea?  I can't remember in particular, but
I'm sure there are some C/C++ preprocessors that will not respect
#whatever lines that don't have the # as the first character of the
line.  Be wary of creating non-portable code...

I don't have any constructive input on how to change vim's behaviour but
at a guess I'd say it's linked to the ftplugin for the C language.

-G

Yorkwar wrote:

> Hello,
> Any one who knows how to enable idention for macros, help me please.
>
> I mean, I want:
> -------------------
> a = 1;
> #ifdef MACRO1
> b = a;
> #else
> b = 2;
> #endif
> --------------------
> While, what I get in Vim6.3 is:
> --------------------
> a = 1;
> #ifdef MACRO1
> b = a;
> #else
> b = 2;
> #endif
> --------------------
> Vim always lets the macro decision begin at the start of the line.
>
> Thanks
>
> Yorkwar
> 20050919

Reply | Threaded
Open this post in threaded view
|

Re: Idention of macro

Dominic Evans
In reply to this post by Hans-5
Do :help smartindent

The relevant section is this:

        When typing '#' as the first character in a new line, the indent for
        that line is removed, the '#' is put in the first column.  The indent
        is restored for the next line.  If you don't want this, use this
        mapping: ":inoremap # X^H#", where ^H is entered with CTRL-V CTRL-H.
        When using the ">>" command, lines starting with '#' are not shifted
        right.

Hope this helps there may be a better way,
Dom

On 19/09/05, Yorkwar <[hidden email]> wrote:

> Hello,
>         Any one who knows how to enable idention for macros, help me please.
>
>         I mean, I want:
> -------------------
>         a = 1;
>         #ifdef MACRO1
>         b = a;
>         #else
>         b = 2;
>         #endif
> --------------------
>         While, what I get in Vim6.3 is:
> --------------------
>         a = 1;
> #ifdef MACRO1
>         b = a;
> #else
>         b = 2;
> #endif
> --------------------
>         Vim always lets the macro decision begin at the start of the line.
>
> Thanks
>
> Yorkwar
> 20050919
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Idention of macro

Mathias Michaelis
In reply to this post by Hans-5
Hi Yorkwar

> Any one who knows how to enable idention for macros, help me
> please.
>
If you have set cindent, then try

:set cinkeys-=0#

I hope this helps.
Best regards
Mathias
Reply | Threaded
Open this post in threaded view
|

Re: Idention of macro

John (Eljay) Love-Jensen
In reply to this post by Gareth Oakes-2
Hi Gareth,

> Are you sure that's a good idea?  I can't remember in particular, but
> I'm sure there are some C/C++ preprocessors that will not respect
> #whatever lines that don't have the # as the first character of the
> line.  Be wary of creating non-portable code...

Not if the C compiler is ISO/IEC 9899:1990 compliant, or if the C++ compiler
is ISO/IEC 14882:1998 compliant.

There are some old, crusty K&R era C compilers that have a brain damaged
preprocessor.  Usually found on uncommon platforms, such as DEC VMS or
Microsoft Xenix (pre-SCO).[1]

Otherwise, this regex should be valid preprocessor directive introducer...
^\s*#\s*

Readability and team coding standards are another issue.  Let's not go
there, since that is an intractable problem to solve in the general (global)
case.

Sincerely,
--Eljay

[1] I'm just picking on DEC and Microsoft for the rarity of these respective
OS's.  I don't remember if their C compilers on said OS's had a brain
damaged C preprocessors or not.

Reply | Threaded
Open this post in threaded view
|

Re: Idention of macro

Bruce Mellows
John Love-Jensen wrote:

> Not if the C compiler is ISO/IEC 9899:1990 compliant, or if the C++ compiler
> is ISO/IEC 14882:1998 compliant.
>

You should have stopped here. The rest was a rant.