all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Stop autoindenting!
@ 2004-05-27  2:52 SomeDude
  2004-05-27 18:07 ` Michael Slass
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: SomeDude @ 2004-05-27  2:52 UTC (permalink / raw)


I've got a pretty unique coding style for C\C++ that I like. I think
it makes my code easy to read and understand (especially once syntax
highlighting is enabled). Unfortunatly, it doesn't conform to any of
the predefined styles set by emacs. What I'd like to do is turn off
all forms of autoindentation and get the tab key to work like it would
in any normal word processor so that I can manually format my code.
Things like braces seem to jump around to odd places whenever I type
them in. Rebinding tab and entering text mode makes it work exactly
like I want it to except text mode doesn't include syntax highlighting
which I'd like to have. If it were possible to somehow program emacs
to my own style that'd be cool too, but I don't know how to do that\if
it'd be possible.

As an example of my style would be something like this:

This would be in a .h file:

class LIB_SomeClass : public LIB_BaseClass
{
    public:
    //const
        const int LIB_SomeClass__SOME_CONSTANT = 0xFF;
    //type
        enum LIB_SomeClass__Colors
        {
            COLOR_RED = 0,
            COLOR_GREEN,
            COLOR_BLUE
        };

        struct LIB_SomeClass__ImaginaryNum
        {
            int a, b;
        };

    //- [Constructor] -
    LIB_SomeClass();

    //- [Methods] -
    bool ExampleMethod();
    int  AnotherMethod(int i, double d, string str);

    private:
    //Vars
        int _i, _j, _k;
        string _exampleMember;
}

This would be in a .cpp:
/* Program: <ProgName>
   Author:  <Name>
   Descr:   <Description of this class>
   Other:   <Other header info>
*/

//---------------------------------------------- [Constructor] -
LIB_SomeClass::LIB_SomeClass
{
    //Vars
        int functionVariable;
        string anotherVariable;

    //Loop through a for loop, just as an example
        for(int i = 0; i < 300; i++)
        {
            SomeFunction();
            ReallyLongFunctionWithManyParameters(_i, _j, _k,
                _examplemember, functionVariable, anotherVariable);
            );
        }
}
//--------------------------------------------------- [Methods] -
bool LIB_SomeClass::ExampleMethod()
{
    //Do something to make this method look legit
        CallAnotherFunction();
}
//... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
int LIB_SomeClass::AnotherMethod(int i, double d, string str)
{
    //Const
        const int A_CONSTANT = 500;

    //Another random loop:
      while(_j != A_CONSTANT)
      {
          ExampleMethod();
          i++;
      }
}

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Stop autoindenting!
  2004-05-27  2:52 Stop autoindenting! SomeDude
@ 2004-05-27 18:07 ` Michael Slass
  2004-05-27 19:28 ` Stefan Monnier
  2004-05-27 20:42 ` Alan Mackenzie
  2 siblings, 0 replies; 4+ messages in thread
From: Michael Slass @ 2004-05-27 18:07 UTC (permalink / raw)


astone42@simla.colostate.edu (SomeDude) writes:

>I've got a pretty unique coding style for C\C++ that I like. I think
>it makes my code easy to read and understand (especially once syntax
>highlighting is enabled). Unfortunatly, it doesn't conform to any of
>the predefined styles set by emacs. What I'd like to do is turn off
>all forms of autoindentation and get the tab key to work like it would
>in any normal word processor so that I can manually format my code.
>Things like braces seem to jump around to odd places whenever I type
>them in. Rebinding tab and entering text mode makes it work exactly
>like I want it to except text mode doesn't include syntax highlighting
>which I'd like to have. If it were possible to somehow program emacs
>to my own style that'd be cool too, but I don't know how to do that\if
>it'd be possible.

It is almost certainly possible to make emacs indent your c/c++ code
exactly the way you want it to, and you'd be well-advised to let it,
rather than committing to a life of hand-indentation.  I would
recommend reading Kai's excellent tutorial on syntax-driven
indentation available here:

ftp://ls6-ftp.cs.uni-dortmund.de/pub/src/emacs/tutorials/tutorials_toc.html

If, after reading the tutorial, you still want to do it by hand then
you can bind the TAB, {, }, and what ever other keys produce electric
effects to 'self-insert-command, and they'll do just that. 
-- 
Mike Slass

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Stop autoindenting!
  2004-05-27  2:52 Stop autoindenting! SomeDude
  2004-05-27 18:07 ` Michael Slass
@ 2004-05-27 19:28 ` Stefan Monnier
  2004-05-27 20:42 ` Alan Mackenzie
  2 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2004-05-27 19:28 UTC (permalink / raw)


> I've got a pretty unique coding style for C\C++ that I like.  I think
> it makes my code easy to read and understand (especially once syntax
> highlighting is enabled).

I'd be surprised if other people find it easier to read than the standard
style they've been accustomed to for several years now.

Roll-your-own-style just makes it harder to collaborate with other people.
So please stick to one of the standard styles.  This way it'll be easier
for you to read that standard style (thus helping you read other people's
code).


        Stefan

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Stop autoindenting!
  2004-05-27  2:52 Stop autoindenting! SomeDude
  2004-05-27 18:07 ` Michael Slass
  2004-05-27 19:28 ` Stefan Monnier
@ 2004-05-27 20:42 ` Alan Mackenzie
  2 siblings, 0 replies; 4+ messages in thread
From: Alan Mackenzie @ 2004-05-27 20:42 UTC (permalink / raw)


SomeDude <astone42@simla.colostate.edu> wrote on 26 May 2004 19:52:24 -0700:
> I've got a pretty unique coding style for C\C++ that I like. I think
> it makes my code easy to read and understand (especially once syntax
> highlighting is enabled). Unfortunatly, it doesn't conform to any of
> the predefined styles set by emacs. What I'd like to do is turn off
> all forms of autoindentation and get the tab key to work like it would
> in any normal word processor so that I can manually format my code.

The variable you need to set is c-syntactic-indentation.  Either do it
via customize, with M-x customize-group <ret> c <ret> then look for "C
Syntactic Indentation" or put this into your .emacs:

(setq c-syntactic-indentation nil)

> Things like braces seem to jump around to odd places whenever I type
> them in.

Once you've disabled the auto-indentation, and you feel you've got some
semblance of control back, I'd recomment you to start experimenting
gently with auto-indentation.  It's one of those things which is
maddening when you're fighting against it all the time, but once you've
got it working how you want, you wonder how you ever managed without it.

> Rebinding tab and entering text mode makes it work exactly
> like I want it to except text mode doesn't include syntax highlighting
> which I'd like to have. If it were possible to somehow program emacs to
> my own style that'd be cool too, but I don't know how to do that\if
> it'd be possible.

It is most definitely possible, just as you'd expect in the world's most
configurable program.  :-)  It's all described in the CC Mode manual
(look for "CC Mode" in the Info directory node) on the page "Customizing
Indentation" and its subpages.  It can seem a bit heavy going, though.

I'd recommend you try one of the built-in styles to start with.  From a
C++ buffer, do C-c . (that's "control-c dot"), then <tab> to get a list
of alternatives.  Try "bsd" style or maybe "ellemtel".  If you like one
of these styles, then put (e.g.) the following into your .emacs:

(setq c-default-style "bsd")

(or use the customization feature).

[ .... ]

-- 
Alan Mackenzie (Munich, Germany)
Email: aacm@muuc.dee; to decode, wherever there is a repeated letter
(like "aa"), remove half of them (leaving, say, "a").

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2004-05-27 20:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-05-27  2:52 Stop autoindenting! SomeDude
2004-05-27 18:07 ` Michael Slass
2004-05-27 19:28 ` Stefan Monnier
2004-05-27 20:42 ` Alan Mackenzie

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.