unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Force spaces instead of tabs
@ 2006-10-10  7:04 Martin
  2006-10-10  8:20 ` ext-chunye.wang
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Martin @ 2006-10-10  7:04 UTC (permalink / raw)


I need to have emacs indent C++ code using only spaces, and no tab
characters.

I edited the options in the Programming/Languages/C group so that:
C Basic Offset is 3
C Tab Always Indent is "always indents"
C Insert Tab Function is "insert-tab"
C Syntactic Indentation is non-nil
C Offsets Alist: substatement-open is 0

In many cases, the indentation is correct, but when I have several
levels of sub-statements, tab characters are inserted anyway. See the
example below. What other options control this behaviour?

void B::e()
{
   if ()
   {
      ;
      if ()
      {
	 ; // tab character at beginning of this line!
      }
      ;
   }
}

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

* Re: Force spaces instead of tabs
  2006-10-10  7:04 Force spaces instead of tabs Martin
@ 2006-10-10  8:20 ` ext-chunye.wang
  2006-10-10  8:32   ` Martin
  2006-10-10 11:43 ` Hadron Quark
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 6+ messages in thread
From: ext-chunye.wang @ 2006-10-10  8:20 UTC (permalink / raw)


"Martin" <loveslave@frustratedhousewives.zzn.com> writes:
> I need to have emacs indent C++ code using only spaces, and no tab
> characters.
> 
> I edited the options in the Programming/Languages/C group so that:
> C Basic Offset is 3
> C Tab Always Indent is "always indents"
> C Insert Tab Function is "insert-tab"
> C Syntactic Indentation is non-nil
> C Offsets Alist: substatement-open is 0
> 
> In many cases, the indentation is correct, but when I have several
> levels of sub-statements, tab characters are inserted anyway. See the
> example below. What other options control this behaviour?
> 
> void B::e()
> {
>    if ()
>    {
>       ;
>       if ()
>       {
> 	 ; // tab character at beginning of this line!
>       }
>       ;
>    }
> }
try (setq indent-tabs-mode nil)

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

* Re: Force spaces instead of tabs
  2006-10-10  8:20 ` ext-chunye.wang
@ 2006-10-10  8:32   ` Martin
  0 siblings, 0 replies; 6+ messages in thread
From: Martin @ 2006-10-10  8:32 UTC (permalink / raw)



ext-chunye.wang@nokia.com skrev:

> "Martin" <loveslave@frustratedhousewives.zzn.com> writes:
> > I need to have emacs indent C++ code using only spaces, and no tab
> > characters.
>
> try (setq indent-tabs-mode nil)

Thanks, that's it!

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

* Re: Force spaces instead of tabs
  2006-10-10  7:04 Force spaces instead of tabs Martin
  2006-10-10  8:20 ` ext-chunye.wang
@ 2006-10-10 11:43 ` Hadron Quark
  2006-10-10 14:30 ` martin
  2006-10-10 23:46 ` Giorgos Keramidas
  3 siblings, 0 replies; 6+ messages in thread
From: Hadron Quark @ 2006-10-10 11:43 UTC (permalink / raw)


"Martin" <loveslave@frustratedhousewives.zzn.com> writes:

> I need to have emacs indent C++ code using only spaces, and no tab
> characters.
>
> I edited the options in the Programming/Languages/C group so that:
> C Basic Offset is 3
> C Tab Always Indent is "always indents"
> C Insert Tab Function is "insert-tab"
> C Syntactic Indentation is non-nil
> C Offsets Alist: substatement-open is 0
>
> In many cases, the indentation is correct, but when I have several
> levels of sub-statements, tab characters are inserted anyway. See the
> example below. What other options control this behaviour?
>
> void B::e()
> {
>    if ()
>    {
>       ;
>       if ()
>       {
> 	 ; // tab character at beginning of this line!
>       }
>       ;
>    }
> }
>

My C programming .el file has the following section - the 6th line is
probably what you are looking for - (setq indent-tabs-mode nil).

,----
| (defun my-c-mode-common-hook ()
|   (c-set-style "K&R")	     ; offset customizations not in my-c-style
|   (setq tab-width 3) ;; change this to taste, this is what K&R uses :)
|   (my-build-tab-stop-list tab-width)
|   (setq c-basic-offset tab-width)
|   (setq indent-tabs-mode nil)
| 
|   (defun find-tag-noconfirm ()
|     (interactive)
|     (find-tag (find-tag-default)))
| 
|   (defun find-tag-repeat ()
|     (interactive)
|     (find-tag nil t nil))
| 
|   (defun jump-man-page ()
|     (interactive)
|     (manual-entry (current-word)))
| 
|   (setq Man-notify-method 'newframe)
| 
|   (let ((dl '(
| 	    ([f1] . jump-man-page)
| 	    ([f5] . find-tag-noconfirm)
| 	    ([f6] . find-tag-repeat)
| 	    ([f7] . pop-tag-mark)
| 	    ([f2] . gdb-restore-windows)
| 	    ([f10] . compile)
| 	    ([f11] . next-error)
| 	    ([f12] . gdba))))
|     (dolist (i dl)
|       (define-key c-mode-map (car i) (cdr i))))
| )
| 
| (add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
`----

The last line is probably of interest to you.

-- 

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

* Re: Force spaces instead of tabs
  2006-10-10  7:04 Force spaces instead of tabs Martin
  2006-10-10  8:20 ` ext-chunye.wang
  2006-10-10 11:43 ` Hadron Quark
@ 2006-10-10 14:30 ` martin
  2006-10-10 23:46 ` Giorgos Keramidas
  3 siblings, 0 replies; 6+ messages in thread
From: martin @ 2006-10-10 14:30 UTC (permalink / raw)



>>>>> Martin  <loveslave@frustratedhousewives.zzn.com> writes:
    > Date: 10 Oct 2006 00:04:46 -0700
    > 
    > I need to have emacs indent C++ code using only spaces, and no tab
    > characters.
    > 
    > I edited the options in the Programming/Languages/C group so that:
    > C Basic Offset is 3
    > C Tab Always Indent is "always indents"
    > C Insert Tab Function is "insert-tab"
    > C Syntactic Indentation is non-nil
    > C Offsets Alist: substatement-open is 0
    > 
    > In many cases, the indentation is correct, but when I have several
    > levels of sub-statements, tab characters are inserted anyway. See the
    > example below. What other options control this behaviour?
    > 
    > void B::e()
    > {
    >    if ()
    >    {
    >       ;
    >       if ()
    >       {
    > 	 ; // tab character at beginning of this line!
    >       }
    >       ;
    >    }
    > }
    > 
    > 

Hi,

customize the variable indent-tabs-mode.

Martin
---
parozusa at web dot de

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

* Re: Force spaces instead of tabs
  2006-10-10  7:04 Force spaces instead of tabs Martin
                   ` (2 preceding siblings ...)
  2006-10-10 14:30 ` martin
@ 2006-10-10 23:46 ` Giorgos Keramidas
  3 siblings, 0 replies; 6+ messages in thread
From: Giorgos Keramidas @ 2006-10-10 23:46 UTC (permalink / raw)


On 10 Oct 2006 00:04:46 -0700, "Martin" <loveslave@frustratedhousewives.zzn.com> wrote:
> I need to have emacs indent C++ code using only spaces, and no tab
> characters.
>
> I edited the options in the Programming/Languages/C group so that:
> C Basic Offset is 3
> C Tab Always Indent is "always indents"
> C Insert Tab Function is "insert-tab"
> C Syntactic Indentation is non-nil
> C Offsets Alist: substatement-open is 0

I used the following set of local variables in files recently edited in
one of the repositories I work with:

    // Local variables:
    // mode: c++
    // c-basic-offset: 4
    // c-tab-always-indent: t
    // indent-tabs-mode: nil
    // End:

The only one that you seem to have missed is `indent-tabs-mode'.

> In many cases, the indentation is correct, but when I have several
> levels of sub-statements, tab characters are inserted anyway. See the
> example below. What other options control this behaviour?

The `indent-tabs-mode' variable controls whether Emacs will use TAB
characters when indenting text or program sources.  Setting it to nil
tells Emacs to only indent using SPC characters, as described in the
documentation of this variable.  Try: `C-h v indent-tabs-mode RET'.
You should see something like this:

,----------------------------------------------------------------
| indent-tabs-mode is a variable defined in `C source code'.
| Its value is nil
| Local in buffer *followup to Martin on gnu.emacs.help*; global value is t
| Automatically becomes buffer-local when set in any fashion.
| 
| This variable is safe as a file local variable if its value
| satisfies the predicate `booleanp'.
| 
| Documentation:
| *Indentation can insert tabs if this is non-nil.
| Setting this variable automatically makes it local to the current buffer.
| 
| You can customize this variable.
`----------------------------------------------------------------

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

end of thread, other threads:[~2006-10-10 23:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-10-10  7:04 Force spaces instead of tabs Martin
2006-10-10  8:20 ` ext-chunye.wang
2006-10-10  8:32   ` Martin
2006-10-10 11:43 ` Hadron Quark
2006-10-10 14:30 ` martin
2006-10-10 23:46 ` Giorgos Keramidas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).