From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tassilo Horn Newsgroups: gmane.emacs.help Subject: Re: distinguish .h files Date: Thu, 21 Oct 2010 12:37:30 +0200 Message-ID: <87k4lb7rx1.fsf@thinkpad.tsdh.de> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1287657509 27092 80.91.229.12 (21 Oct 2010 10:38:29 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 21 Oct 2010 10:38:29 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Oct 21 12:38:28 2010 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1P8sXU-0002OS-1i for geh-help-gnu-emacs@m.gmane.org; Thu, 21 Oct 2010 12:38:28 +0200 Original-Received: from localhost ([127.0.0.1]:53454 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P8sXT-0002QB-Fa for geh-help-gnu-emacs@m.gmane.org; Thu, 21 Oct 2010 06:38:27 -0400 Original-Received: from [140.186.70.92] (port=36291 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P8sWm-0002Na-MZ for help-gnu-emacs@gnu.org; Thu, 21 Oct 2010 06:37:46 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P8sWk-0002r2-PJ for help-gnu-emacs@gnu.org; Thu, 21 Oct 2010 06:37:44 -0400 Original-Received: from lo.gmane.org ([80.91.229.12]:46823) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P8sWk-0002qK-Ix for help-gnu-emacs@gnu.org; Thu, 21 Oct 2010 06:37:42 -0400 Original-Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1P8sWh-00026R-Ts for help-gnu-emacs@gnu.org; Thu, 21 Oct 2010 12:37:39 +0200 Original-Received: from tsdh.uni-koblenz.de ([141.26.67.142]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 21 Oct 2010 12:37:39 +0200 Original-Received: from tassilo by tsdh.uni-koblenz.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Thu, 21 Oct 2010 12:37:39 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 50 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: tsdh.uni-koblenz.de User-Agent: Gnus/5.110011 (No Gnus v0.11) Emacs/24.0.50 (gnu/linux) Cancel-Lock: sha1:pw374BZ33wUcwofj4EoKmpki+aA= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:75182 Archived-At: Oleksandr Gavenko 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 "\\_" nil t)))) (add-to-list 'magic-mode-alist '(c++-header-file-p . c++-mode)) --8<---------------cut here---------------end--------------->8--- Bye, Tassilo