how to make emacs indent using tab instead of spaces

how to make emacs indent using tab instead of spaces

Post by Fredrik Olausso » Mon, 09 Apr 2001 21:31:38



Hi all,

When I am using the C-mode, I use the c-toggle-auto-state function, to
make emacs indent automagically. However, it indents by inserting
spaces, which leads to the situation that I have to hammer away at
backspace several times instead of only once when I want to "un-indent"
manually.

Does anyone know what I need to put in my .emacs to make it insert a
single TAB character in my file instead of several spaces?

TIA,
Fredrik

 
 
 

how to make emacs indent using tab instead of spaces

Post by Koll » Mon, 09 Apr 2001 22:39:21


    set indent-tabs-mode  to t
    (setq indent-tabs-mode t)
    M-x describe-variable RET indent-tabs-mode

    Fredrik> Hi all,
    Fredrik> When I am using the C-mode, I use the c-toggle-auto-state
    Fredrik> function, to make emacs indent automagically. However, it
    Fredrik> indents by inserting spaces, which leads to the situation
    Fredrik> that I have to hammer away at backspace several times
    Fredrik> instead of only once when I want to "un-indent" manually.

    Fredrik> Does anyone know what I need to put in my .emacs to make
    Fredrik> it insert a single TAB character in my file instead of
    Fredrik> several spaces?

    Fredrik> TIA, Fredrik

HTH
-Kolla
--
Kolla Suresh Babu

Some husbands are living proof that a woman can take a joke.

 
 
 

how to make emacs indent using tab instead of spaces

Post by Fredrik Olausso » Mon, 09 Apr 2001 23:48:36


Kolla,

Thanks for your reply, but I can't get that to work! I added the setq
statement to my .emacs, but still, when I press TAB to indent a line, I
have to press backspace several times to un-indent the same line. Am I
doing something wrong here?

Thanks,
Fredrik



>     set indent-tabs-mode  to t
>     (setq indent-tabs-mode t)
>     M-x describe-variable RET indent-tabs-mode

>     Fredrik> Hi all,
>     Fredrik> When I am using the C-mode, I use the c-toggle-auto-state
>     Fredrik> function, to make emacs indent automagically. However, it
>     Fredrik> indents by inserting spaces, which leads to the situation
>     Fredrik> that I have to hammer away at backspace several times
>     Fredrik> instead of only once when I want to "un-indent" manually.

>     Fredrik> Does anyone know what I need to put in my .emacs to make
>     Fredrik> it insert a single TAB character in my file instead of
>     Fredrik> several spaces?

>     Fredrik> TIA, Fredrik

> HTH
> -Kolla
> --
> Kolla Suresh Babu

> Some husbands are living proof that a woman can take a joke.

 
 
 

how to make emacs indent using tab instead of spaces

Post by Dan Espe » Mon, 09 Apr 2001 23:55:16



> Kolla,

> Thanks for your reply, but I can't get that to work! I added the setq
> statement to my .emacs, but still, when I press TAB to indent a line, I
> have to press backspace several times to un-indent the same line. Am I
> doing something wrong here?

If your indent spacing is not a multiple of 8, XEmacs has little choice other
than to insert spaces.  If you indent 2 spaces, XEmacs will replace the spaces
with tabs by the time you get 4 levels deep.

For most users, the spaces aren't a problem, you hit tab once, and XEmacs
puts the line where it should be.

You can change the width a tab represents, or change to indent by 8.
I don't recommend either of these approaches.

> Thanks,
> Fredrik



> >     set indent-tabs-mode  to t
> >     (setq indent-tabs-mode t)
> >     M-x describe-variable RET indent-tabs-mode

> >     Fredrik> Hi all,
> >     Fredrik> When I am using the C-mode, I use the c-toggle-auto-state
> >     Fredrik> function, to make emacs indent automagically. However, it
> >     Fredrik> indents by inserting spaces, which leads to the situation
> >     Fredrik> that I have to hammer away at backspace several times
> >     Fredrik> instead of only once when I want to "un-indent" manually.

> >     Fredrik> Does anyone know what I need to put in my .emacs to make
> >     Fredrik> it insert a single TAB character in my file instead of
> >     Fredrik> several spaces?

> >     Fredrik> TIA, Fredrik

> > HTH
> > -Kolla
> > --
> > Kolla Suresh Babu

> > Some husbands are living proof that a woman can take a joke.

 
 
 

how to make emacs indent using tab instead of spaces

Post by Fredrik Olausso » Tue, 10 Apr 2001 01:29:50


Dan,

This seems like a likely explanation. Just one thing though, how do I go
about changing the tab-width? Sorry for all the newbie questions ;-)

Thanks,

Fredrik



> > Kolla,

> > Thanks for your reply, but I can't get that to work! I added the setq
> > statement to my .emacs, but still, when I press TAB to indent a line, I
> > have to press backspace several times to un-indent the same line. Am I
> > doing something wrong here?

> If your indent spacing is not a multiple of 8, XEmacs has little choice other
> than to insert spaces.  If you indent 2 spaces, XEmacs will replace the spaces
> with tabs by the time you get 4 levels deep.

> For most users, the spaces aren't a problem, you hit tab once, and XEmacs
> puts the line where it should be.

> You can change the width a tab represents, or change to indent by 8.
> I don't recommend either of these approaches.

> > Thanks,
> > Fredrik



> > >     set indent-tabs-mode  to t
> > >     (setq indent-tabs-mode t)
> > >     M-x describe-variable RET indent-tabs-mode

> > >     Fredrik> Hi all,
> > >     Fredrik> When I am using the C-mode, I use the c-toggle-auto-state
> > >     Fredrik> function, to make emacs indent automagically. However, it
> > >     Fredrik> indents by inserting spaces, which leads to the situation
> > >     Fredrik> that I have to hammer away at backspace several times
> > >     Fredrik> instead of only once when I want to "un-indent" manually.

> > >     Fredrik> Does anyone know what I need to put in my .emacs to make
> > >     Fredrik> it insert a single TAB character in my file instead of
> > >     Fredrik> several spaces?

> > >     Fredrik> TIA, Fredrik

> > > HTH
> > > -Kolla
> > > --
> > > Kolla Suresh Babu

> > > Some husbands are living proof that a woman can take a joke.

 
 
 

how to make emacs indent using tab instead of spaces

Post by Samuel Padget » Tue, 10 Apr 2001 01:30:29



> When I am using the C-mode, I use the c-toggle-auto-state function, to
> make emacs indent automagically. However, it indents by inserting
> spaces, which leads to the situation that I have to hammer away at
> backspace several times instead of only once when I want to "un-indent"
> manually.

Maybe your Backspace key is bound to `backward-delete-char-untabify'?
If this is true, even if there are TAB characters in the buffer,
you'll have to backspace several times instead of once.  You might
want to bind it to simply `backward-delete-char'.

To make Emacs use TABs in indention, try

(setq-default indent-tabs-mode t)

Be aware, though, that if `c-basic-offset' and `tab-width' are set to
different values, a TAB character does not correspond to one indention
level.  Emacs will only insert a TAB character if the indention is at
least `tab-width' characters.

Of course, if you set up the CC Mode indention engine to format code
in your style, you can always use commands like TAB and C-M-\ to
indent code instead of doing it manually.

Sam
--
Room service?  Send up a larger room.
                -- Groucho Marx

 
 
 

how to make emacs indent using tab instead of spaces

Post by Samuel Padget » Tue, 10 Apr 2001 01:40:07



> Just one thing though, how do I go about changing the tab-width?

Put the following in your .emacs:

(setq-default tab-width 4)

But I don't recommend doing this because your files will likely not
display properly in other people's editors, and other people's files
will likely not display properly in your editor.

For some background on all this, you might want to look at

<URL:http://www.jwz.org/doc/tabs-vs-spaces.html>

Sam
--
Room service?  Send up a larger room.
                -- Groucho Marx

 
 
 

how to make emacs indent using tab instead of spaces

Post by Knut Forkalsru » Tue, 10 Apr 2001 03:49:13



> When I am using the C-mode, I use the c-toggle-auto-state function, to
> make emacs indent automagically. However, it indents by inserting
> spaces, which leads to the situation that I have to hammer away at
> backspace several times instead of only once when I want to "un-indent"
> manually.

I believe there is something called hungry delete that you can toggle
the same way you toggle the auto state in c-mode.  It is indicated
with an H in the modeline next to the A of auto-state.  Let's see...

OK a quick M-x apropos RET hungry RET reveals a few leads.  Especially
the c-toggle-hungry-state looks promising.  So I type M-x
c-toggle-hungry-state RET and Emacs is kind enough to tell me that C-c
C-d is the shortcut.

For details on the function, type C-h f c-toggle-hungry-state RET

Quote:> Does anyone know what I need to put in my .emacs to make it insert a
> single TAB character in my file instead of several spaces?

This is probably not what you want to mess with.

-Knut

--
Hard work often pays off after time.  But laziness always pays off now.

 
 
 

how to make emacs indent using tab instead of spaces

Post by Kai Gro?joha » Tue, 10 Apr 2001 04:54:00



> When I am using the C-mode, I use the c-toggle-auto-state function,
> to make emacs indent automagically. However, it indents by inserting
> spaces, which leads to the situation that I have to hammer away at
> backspace several times instead of only once when I want to
> "un-indent" manually.

There is `M-\', but I rarely use it because I don't need to manually
indent lines.  I just reformulate my source code a bit.

Can you show a specific case where you need to unindent manually?

kai
--
Be indiscrete.  Do it continuously.

 
 
 

how to make emacs indent using tab instead of spaces

Post by Timothy M. Schaeffe » Tue, 10 Apr 2001 23:28:09


Or

http://apache.bsilabs.com/~tim/cc-mode/description.html

TMS



> > Just one thing though, how do I go about changing the tab-width?

> Put the following in your .emacs:

> (setq-default tab-width 4)

> But I don't recommend doing this because your files will likely not
> display properly in other people's editors, and other people's files
> will likely not display properly in your editor.

> For some background on all this, you might want to look at

> <URL:http://www.jwz.org/doc/tabs-vs-spaces.html>

> Sam
> --
> Room service?  Send up a larger room.
>                 -- Groucho Marx

 
 
 

how to make emacs indent using tab instead of spaces

Post by David Caspers » Sun, 15 Apr 2001 03:03:44




Quote:>Hi all,

>When I am using the C-mode, I use the c-toggle-auto-state function, to
>make emacs indent automagically. However, it indents by inserting
>spaces, which leads to the situation that I have to hammer away at
>backspace several times instead of only once when I want to "un-indent"
>manually.

>Does anyone know what I need to put in my .emacs to make it insert a
>single TAB character in my file instead of several spaces?

Others have commented that the problem may be that back-space is
converting tabs into sequences of spaces when you backspace.  Do
    C-h c backspace
in a C buffer to check this.

I was surprised by your question, which made me think about what I
type.  Usually when backing up, I type M-backspace to go back one word
at a time, and use M-space to collapse the current white space down to
just one space.  Sequences I often use:
    M-backspace M-space
    M-backspace M-\             (no space)
    M-C-u C-k  (or M-C-k)       (if I'm in the middle of typing the
                                 condition on a while loop and it gets
                                 really messed up.)

I hope these help.

David
--

Department of Mathematics & Computer Science |  (250) 960-6672
Faculty of Science                           |
College of Science and Management            |