LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 02-25-2008, 02:33 PM   #1
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
How do you change default emacs behavior on .h files?


I almost always program in C++ vs C.

I typically use ".h" for header files.

emacs sees .h files as C files rather than C++ files, and therefore does syntax highlighting and indenting based on C rather than C++.

How can I change the default to C++? This is a fairly vanilla install of emacs & I don't have admin privs on this machine. Can I change my local elisp file to change this behavior? Maybe I need to start using a .emacs? Maybe it's simpler than that?

Thanks
 
Old 02-25-2008, 05:43 PM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
I know too little of elisp to provide a real solution, but renaming header files to *.hpp makes emacs think it is C++.
 
Old 02-25-2008, 07:36 PM   #3
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Original Poster
Rep: Reputation: 51
Quote:
Originally Posted by Hko View Post
I know too little of elisp to provide a real solution, but renaming header files to *.hpp makes emacs think it is C++.
yeah, I know. I just prefer .h over .hpp.
 
Old 02-26-2008, 07:59 PM   #4
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,541

Rep: Reputation: 878Reputation: 878Reputation: 878Reputation: 878Reputation: 878Reputation: 878Reputation: 878
put this in .emacs file
Code:
(setq auto-mode-alist (cons '("\\.h\\'" . c++-mode) auto-mode-alist))
or (this loads cl.el which can increase startup time)
Code:
(push '("\\.h\\'" . c++-mode) auto-mode-alist)
Or you can put
Code:
 // -*- mode: c++ -*-
as the first line of the .h file.

Or you can put
Code:
/*                                                                                                                                                                                                                  
*** Local Variables: **                                                                                                                                                                                             
*** mode: c++ **                                                                                                                                                                                               
*** End: **                                                                                                                                                                                                         
 */
At the end of the file.

Quote:
Can I change my local elisp file to change this behavior? Maybe I need to start using a .emacs?
A .emacs is a local elisp file, not sure what you mean here?
 
Old 02-26-2008, 08:11 PM   #5
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Original Poster
Rep: Reputation: 51
Quote:
Originally Posted by ntubski View Post
put this in .emacs file
Code:
(setq auto-mode-alist (cons '("\\.h\\'" . c++-mode) auto-mode-alist))
or (this loads cl.el which can increase startup time)
Code:
(push '("\\.h\\'" . c++-mode) auto-mode-alist)
Or you can put
Code:
 // -*- mode: c++ -*-
as the first line of the .h file.

Or you can put
Code:
/*                                                                                                                                                                                                                  
*** Local Variables: **                                                                                                                                                                                             
*** mode: c++ **                                                                                                                                                                                               
*** End: **                                                                                                                                                                                                         
 */
At the end of the file.
awesome, these are all great options.

Quote:
A .emacs is a local elisp file, not sure what you mean here?
I was confused. For some reason, I didn't think I'd created a .emacs file on this machine, but I had (and have put things in it... how soon we forget).

Thanks!

Last edited by BrianK; 02-26-2008 at 08:16 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
ipblock default behavior FolkTheory Linux - Security 3 12-01-2007 01:30 PM
default behavior for Konsole and other x-type terminals muttdawg Slackware 5 09-02-2007 06:31 PM
Emacs default browser monkeymind Slackware 2 01-02-2007 01:21 AM
change default app for certain files (Mac OS X) beezum88 Other *NIX 1 11-23-2006 11:35 PM
Change default ls behavior bgfay Linux - Newbie 5 06-21-2004 10:04 PM


All times are GMT -5. The time now is 09:35 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration