help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: programming file-extensions in .emacs


From: efrem
Subject: Re: programming file-extensions in .emacs
Date: Wed, 27 Feb 2008 23:36:01 -0800 (PST)
User-agent: G2/1.0

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 via email to

[Prev in Thread] Current Thread [Next in Thread]