[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: distinguish .h files
From: |
Tassilo Horn |
Subject: |
Re: distinguish .h files |
Date: |
Thu, 21 Oct 2010 12:37:30 +0200 |
User-agent: |
Gnus/5.110011 (No Gnus v0.11) Emacs/24.0.50 (gnu/linux) |
Oleksandr Gavenko <gavenko@bifit.com.ua> writes:
Hi Oleksandr,
>> 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 don't know exactly, but in general only the first line is relevant,
with some shebang like
#!/bin/bash
But read a bit on:
,----[ (info "(emacs)Choosing Modes") ]
| Alternatively, an element of `magic-mode-alist' may have the form
|
| (MATCH-FUNCTION . MODE-FUNCTION)
|
| where MATCH-FUNCTION is a Lisp function that is called at the beginning
| of the buffer; if the function returns non-`nil', Emacs set the major
| mode wit MODE-FUNCTION.
`----
This should do the trick:
--8<---------------cut here---------------start------------->8---
(defun c++-header-file-p ()
"Return non-nil, if in a C++ header."
(and (string-match "\\.h$"
(or (buffer-file-name)
(buffer-name)))
(save-excursion
(re-search-forward "\\_<class\\_>" nil t))))
(add-to-list 'magic-mode-alist
'(c++-header-file-p . c++-mode))
--8<---------------cut here---------------end--------------->8---
Bye,
Tassilo
- distinguish .h files, Andrea Crotti, 2010/10/20
- Re: distinguish .h files, Lennart Borgman, 2010/10/20
- Re: distinguish .h files, Oleksandr Gavenko, 2010/10/21
- Re: distinguish .h files,
Tassilo Horn <=
- Re: distinguish .h files, Tassilo Horn, 2010/10/21
- Re: distinguish .h files, Andrea Crotti, 2010/10/21
- Re: distinguish .h files, Oleksandr Gavenko, 2010/10/21
- Re: distinguish .h files, Andrea Crotti, 2010/10/21
- Re: distinguish .h files, Oleksandr Gavenko, 2010/10/21
- Re: distinguish .h files, Andrea Crotti, 2010/10/21
- Re: distinguish .h files, Tassilo Horn, 2010/10/21
- Re: distinguish .h files, Andrea Crotti, 2010/10/21
- Re: distinguish .h files, Tassilo Horn, 2010/10/21
- Re: distinguish .h files, Oleksandr Gavenko, 2010/10/21