From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: dkcombs@panix.com (David Combs) Newsgroups: gmane.emacs.help Subject: Re: How to open a file in sh-mode Date: Thu, 11 Sep 2008 01:35:55 +0000 (UTC) Organization: Public Access Networks Corp. Message-ID: References: <64d8ebaf-0c89-4e9d-9aee-86b4e9414449@o40g2000prn.googlegroups.com> NNTP-Posting-Host: lo.gmane.org X-Trace: ger.gmane.org 1221097242 17632 80.91.229.12 (11 Sep 2008 01:40:42 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 11 Sep 2008 01:40:42 +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 Sep 11 03:41:37 2008 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.50) id 1KdbBf-0003rR-Fn for geh-help-gnu-emacs@m.gmane.org; Thu, 11 Sep 2008 03:41:35 +0200 Original-Received: from localhost ([127.0.0.1]:46376 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KdbAf-0005tS-Bp for geh-help-gnu-emacs@m.gmane.org; Wed, 10 Sep 2008 21:40:33 -0400 Original-Path: news.stanford.edu!newsfeed.stanford.edu!panix!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 82 Original-NNTP-Posting-Host: panix1.panix.com Original-X-Trace: reader1.panix.com 1221096955 10193 166.84.1.1 (11 Sep 2008 01:35:55 GMT) Original-X-Complaints-To: abuse@panix.com Original-NNTP-Posting-Date: Thu, 11 Sep 2008 01:35:55 +0000 (UTC) X-Newsreader: trn 4.0-test76 (Apr 2, 2001) Original-Xref: news.stanford.edu gnu.emacs.help:162062 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:57403 Archived-At: In article <64d8ebaf-0c89-4e9d-9aee-86b4e9414449@o40g2000prn.googlegroups.com>, Xah wrote: >On Aug 14, 12:53 am, "Francis Moreau" wrote: >> Hello, >> >> I'm trying to open a file with emacs automatically set on sh-mode. >> The file name can't be used to guess that emacs should be in sh-mode >> when opening it. > >If the file content's first line starts with “#!”, then you could use >the magic-mode-alist. > Xah -- question about the characters in your posts: If I or someone sees eg a url in one of your posts, and wants to go to that url (because you've suggested doing that, maybe), it's a little difficult to just cut-n-paste your string, what with all the extra control or whatever they are characters mixed in. What is that stuff, why is it there, and is it really necessary for you to include it. Thanks, David >----------------------------------- >How Emacs Choose Modes > >Emacs determines what mode to use primarily by 2 mechanisms, in order: >(1) Check the first line in the file, using “magic-mode-alist”. (2) >Check the file name's suffix, using “auto-mode-alist”. > >The “magic-mode-alist” is a list that emacs use to match the first >line of a file with a mode. For example, if you want files that begin >with the line “always use nxml-mode, then add the following to your “.emacs”: > >(add-to-list > 'magic-mode-alist > '(" >The magic-mode-alist is a list. In the above example, the string with >the “DOCTYPE” is a regex, used to match the first line of a file. > >If emacs goes thru magic-mode-alist and didn't find any match, then >it'll use auto-mode-alist to check on file name suffix. The “auto-mode- >alist” associates a file name suffix with a mode. For example, if you >want files ending in “.js” to always open with js2-mode, then do: > >(add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode)) > >Note: The double backslash in the string “\\.js\\'” is used to escape >the backslash. So, the regex engine just got “\.js\'”. The “\.” is to >match a period. The “\'” is one of emacs special regex syntax, to >match end of a string. (See also: Text Pattern Matching in Emacs) > >Reference: Elisp Manual: Regexp-Backslash. > >You can see what are the values of magic-mode-alist or auto-mode-alist >by typing “Alt+x describe-variable”. > >There are few minor details about how emacs determines what mode to >load, but the above should cover vast majority of needs. For detail, >see emacs manual. > >Reference: (info "(emacs)Choosing Modes"). > >-------------------------------------------- >above from: >http://xahlee.org/emacs/emacs_installing_packages.html > > Xah >∑ http://xahlee.org/ > >☄