unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: efrem <oleg-zhukov@hotmail.ru>
To: help-gnu-emacs@gnu.org
Subject: Re: programming file-extensions in .emacs
Date: Wed, 27 Feb 2008 23:36:01 -0800 (PST)	[thread overview]
Message-ID: <c07d83b9-a10a-4297-90a1-ec730f1a0c54@p73g2000hsd.googlegroups.com> (raw)
In-Reply-To: pco3arebapd.fsf@shuttle.math.ntnu.no

On Feb 27, 7:55 pm, Harald Hanche-Olsen <han...@math.ntnu.no> wrote:
> + efrem <oleg-zhu...@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

It's good.
Thank you very much!
Best wishes
Oleg


      reply	other threads:[~2008-02-28  7:36 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
2008-02-28  7:36   ` efrem [this message]

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=c07d83b9-a10a-4297-90a1-ec730f1a0c54@p73g2000hsd.googlegroups.com \
    --to=oleg-zhukov@hotmail.ru \
    --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).