From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Harald Hanche-Olsen Newsgroups: gmane.emacs.help Subject: Re: programming file-extensions in .emacs Date: Wed, 27 Feb 2008 17:55:42 +0100 Organization: Norwegian university of science and technology Message-ID: References: <6d54fc34-7e67-4dd0-9c99-be7796283cdb@e25g2000prg.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1204134053 29233 80.91.229.12 (27 Feb 2008 17:40:53 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 27 Feb 2008 17:40:53 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Feb 27 18:41:18 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 1JUQHE-0002pm-7J for geh-help-gnu-emacs@m.gmane.org; Wed, 27 Feb 2008 18:41:08 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JUQGi-0005PM-0s for geh-help-gnu-emacs@m.gmane.org; Wed, 27 Feb 2008 12:40:36 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!goblin1!goblin2!goblin.stu.neva.ru!news.net.uni-c.dk!hist.no!uio.no!ntnu.no!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 47 Original-NNTP-Posting-Host: fiinbeck.math.ntnu.no Original-X-Trace: kuling.itea.ntnu.no 1204131342 389 129.241.15.140 (27 Feb 2008 16:55:42 GMT) Original-X-Complaints-To: usenet@itea.ntnu.no Original-NNTP-Posting-Date: Wed, 27 Feb 2008 16:55:42 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (berkeley-unix) Cancel-Lock: sha1:mc5LLqX2P5U2VBgtjTo4gKyqjrw= Original-Xref: shelby.stanford.edu gnu.emacs.help:156547 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:51918 Archived-At: + efrem : > I'd like to change the .emacs file in order to > make some key-setting for the cases of xxxx.f and xxxx.cc files. Then take advantage of the work that emacs already does for you, and change the key definitions for the corresponding modes. *.f and *.cc are edited using fortran-mode and c++-mode respectively. And these modes, when activated, cause the running of hooks name fortran-mode-hook and c++-mode-hook respectively. So instead of > (let (fname suffix) > (setq fname (buffer-file-name)) > (setq suffix (file-name-extension fname)) > (if (equal suffix "cc") > (progn > (global-set-key [f2] 'insert-cout1) > (global-set-key [f3] 'insert-cout4) > )) > (if (equal suffix "f") > (progn > (global-set-key [f8] 'nn3) > (global-set-key [f9] 'delete-backward-char) > )) you may try this in your .emacs: (defun set-my-c++-keys () (local-set-key [f2] 'insert-cout1) (local-set-key [f3] 'insert-cout4)) (add-hook 'c++-mode-hook 'set-my-c++-keys) (defun set-my-fortran-keys () (local-set-key [f8] 'nn3) (local-set-key [f9] 'delete-backward-char)) (add-hook 'fortran-mode-hook 'set-my-fortran-keys) Note that I use local-set-key. There is little point, I think, in polluting the global keymap with mode specific bindings. -- * Harald Hanche-Olsen - It is undesirable to believe a proposition when there is no ground whatsoever for supposing it is true. -- Bertrand Russell