From: Harald Hanche-Olsen <hanche@math.ntnu.no>
To: help-gnu-emacs@gnu.org
Subject: Re: programming file-extensions in .emacs
Date: Wed, 27 Feb 2008 17:55:42 +0100 [thread overview]
Message-ID: <pco3arebapd.fsf@shuttle.math.ntnu.no> (raw)
In-Reply-To: 6d54fc34-7e67-4dd0-9c99-be7796283cdb@e25g2000prg.googlegroups.com
+ efrem <oleg-zhukov@hotmail.ru>:
> 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 <URL:http://www.math.ntnu.no/~hanche/>
- It is undesirable to believe a proposition
when there is no ground whatsoever for supposing it is true.
-- Bertrand Russell
next prev parent reply other threads:[~2008-02-27 16:55 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-27 14:17 programming file-extensions in .emacs efrem
2008-02-27 16:20 ` Jason Rumney
2008-02-27 16:25 ` Peter Dyballa
2008-02-27 16:55 ` Harald Hanche-Olsen [this message]
2008-02-28 7:36 ` efrem
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=pco3arebapd.fsf@shuttle.math.ntnu.no \
--to=hanche@math.ntnu.no \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).