LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 09-08-2004, 12:13 AM   #1
black
Member
 
Registered: Jul 2002
Location: nowhere
Distribution: GNU
Posts: 118

Rep: Reputation: 15
indent cpp file with emacs~


hi all~

i found emacs indentation went strange way when editing cpp file with it, below is what it did:
Code:
int Foo()
{
  int a;
  int b
    int c;
  int d;
}
as you can see first line within {} emacs indent two spaces and so did the second line, but if I omit the semicolon after b the third line will go four spaces instead, why ???
and, how can i make emacs indent 4 spaces not 2 here ?

thanx~
 
Old 09-08-2004, 12:21 AM   #2
redjokerx
Member
 
Registered: Aug 2004
Location: San Diego
Distribution: Slackware
Posts: 303

Rep: Reputation: 31
It's probably confused and thinks it's not delimited. Plus, why would you do that anyway ? If you think about it, if you do

Code:
if()
  blah
it will be tabbed so I guess it's for the best
 
Old 09-08-2004, 12:35 AM   #3
black
Member
 
Registered: Jul 2002
Location: nowhere
Distribution: GNU
Posts: 118

Original Poster
Rep: Reputation: 15
because i like distance of 4 spaces so far, strictly speaking, i prefer 4 spaces tab not spaces at all, unfortunately emacs really inserting spaces not tab when i pressed Tab key. how can i fix that please ?
 
Old 09-08-2004, 03:18 AM   #4
slackie1000
Senior Member
 
Registered: Dec 2003
Location: Brasil
Distribution: Arch
Posts: 1,037

Rep: Reputation: 46
Re: indent cpp file with emacs~

Quote:
Originally posted by black
hi all~

i found emacs indentation went strange way when editing cpp file with it, below is what it did:
Code:
int Foo()
{
  int a;
  int b
    int c;
  int d;
}
as you can see first line within {} emacs indent two spaces and so did the second line, but if I omit the semicolon after b the third line will go four spaces instead, why ???
and, how can i make emacs indent 4 spaces not 2 here ?

thanx~
hi there,

from the top of my head now...
can confirm later. hope some lisp guru can help.

in your .emacs file

Code:
(setq indent-tabs-mode 2)
regards

slackie1000
 
Old 09-08-2004, 04:24 AM   #5
black
Member
 
Registered: Jul 2002
Location: nowhere
Distribution: GNU
Posts: 118

Original Poster
Rep: Reputation: 15
it didnt help, i add it to the top of .emacs file but nothing changed, my .emacs file is something like this:
Code:
(setq indent-tabs-mode 2)
(custom-set-variables
  ;; custom-set-variables was added by Custom -- don't edit or cut/paste it!
  ;; Your init file should contain only one such instance.
 '(case-fold-search t)

...
any suggestions ?
 
Old 09-08-2004, 05:54 AM   #6
slackie1000
Senior Member
 
Registered: Dec 2003
Location: Brasil
Distribution: Arch
Posts: 1,037

Rep: Reputation: 46
Quote:
Originally posted by black
it didnt help, i add it to the top of .emacs file but nothing changed, my .emacs file is something like this:
Code:
(setq indent-tabs-mode 2)
(custom-set-variables
  ;; custom-set-variables was added by Custom -- don't edit or cut/paste it!
  ;; Your init file should contain only one such instance.
 '(case-fold-search t)

...
any suggestions ?
sorry for the wrong tip..

now i checked, at least for c it will work..

Code:
(setq c-basic-offset 4)
will do the trick

hope it helps

regards

slackie1000
 
Old 09-08-2004, 11:39 PM   #7
black
Member
 
Registered: Jul 2002
Location: nowhere
Distribution: GNU
Posts: 118

Original Poster
Rep: Reputation: 15
Quote:
Originally posted by slackie1000
sorry for the wrong tip..

now i checked, at least for c it will work..

Code:
(setq c-basic-offset 4)
will do the trick

hope it helps

regards

slackie1000
it works ! hey thanx man !
 
Old 09-09-2004, 12:08 AM   #8
black
Member
 
Registered: Jul 2002
Location: nowhere
Distribution: GNU
Posts: 118

Original Poster
Rep: Reputation: 15
and one more question, default tab size is 8 spaces far, how can i revert it to 4 spaces too ? many thanx~
 
Old 09-09-2004, 03:14 AM   #9
slackie1000
Senior Member
 
Registered: Dec 2003
Location: Brasil
Distribution: Arch
Posts: 1,037

Rep: Reputation: 46
Quote:
Originally posted by black
and one more question, default tab size is 8 spaces far, how can i revert it to 4 spaces too ? many thanx~
hi there,

i would like to introduce you to tab-stop

Code:
(setq tab-stop-list '(3 8 16))
or whatever you want.

After that a visit to www.emacswiki.org will help a lot. It is a quite complete wiki

Regards


slackie1000
 
Old 09-09-2004, 10:39 PM   #10
black
Member
 
Registered: Jul 2002
Location: nowhere
Distribution: GNU
Posts: 118

Original Poster
Rep: Reputation: 15
Quote:
Originally posted by slackie1000
hi there,

i would like to introduce you to tab-stop

Code:
(setq tab-stop-list '(3 8 16))
or whatever you want.

After that a visit to www.emacswiki.org will help a lot. It is a quite complete wiki

Regards


slackie1000
thanx for supply that site, i'll check it out soon. and is your code the same thing as command "edit-tab-stops" ? i fixed it but nothing works.
 
Old 09-10-2004, 12:43 AM   #11
slackie1000
Senior Member
 
Registered: Dec 2003
Location: Brasil
Distribution: Arch
Posts: 1,037

Rep: Reputation: 46
hi there,

to use the tab stop list you need to switch indent tab modes also in your .emacs file:
(setq-default indent-tabs-mode 1)
i think you can find all these informations at emacswiki.
hope it helps.

regards

slackie1000
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
where is the .emacs file in the emacs source code tarball? aizkorri Programming 2 01-13-2007 02:05 PM
emacs + execute .cpp jhon Programming 1 08-30-2004 04:36 AM
failed on modifying indent on emacs~ black Linux - Software 0 07-22-2004 11:59 PM
emacs - convert auto indent tabs to spaces? BrianK Linux - General 1 04-15-2004 10:14 PM
edb (emacs database) won't open file - emacs 20 & 21 tip184 Linux - Software 0 04-03-2004 07:31 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:29 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration