help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: distinguish .h files


From: Pascal J. Bourguignon
Subject: Re: distinguish .h files
Date: Wed, 08 Dec 2010 15:32:45 -0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)

Oleksandr Gavenko <gavenko@bifit.com.ua> writes:

> On 20.10.2010 18:48, Lennart Borgman wrote:
>> On Wed, Oct 20, 2010 at 5:37 PM, Andrea Crotti
>>>
>>> It's a bit annoying that the header files .h BUT for c++ are not
>>> automatically recognized (but of course understandable).
>>>
>>> I tried the following approach but it doesn't work, maybe the function
>>> is executed too early?
>>> Or what else can be the problem?
>>>
>>> --8<---------------cut here---------------start------------->8---
>>>   (defun is-cpp-header-file ()
>>>     "enable c++-mode when finding classes"
>>>     (when (re-search-forward "class ")
>>>       (c++-mode)))
>>>
>>>   ;;(add-hook 'c-mode-common-hook 'is-cpp-header-file)
>>> --8<---------------cut here---------------end--------------->8---
>>
>> Please have a look at
>>
>>    (info "(emacs) Choosing Modes")
>>
>    Third, Emacs tries to determine the major mode by looking at the
> text at the start of the buffer, based on the variable
> `magic-mode-alist'.  By default, this variable is `nil' (an empty
> list), so Emacs skips this step; however, you can customize it in your
> init file
>
> How long start of the buffer? Which variable control this behavior?

I would use find-file-hook.

(defun c++-.h-meat ()
  (interactive)
  (when (and (string= "h" (file-name-extension (buffer-file-name)))
             (progn (goto-char (point-min))
                    (re-search-forward "\\<class\\>")))
    (c++-mode)))

(add-hook 'find-file-hook 'c++-.h-meat)
    
-- 
__Pascal Bourguignon__                     http://www.informatimago.com/


reply via email to

[Prev in Thread] Current Thread [Next in Thread]