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: Harald Hanche-Olsen
Subject: Re: programming file-extensions in .emacs
Date: Wed, 27 Feb 2008 17:55:42 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (berkeley-unix)

+ 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


reply via email to

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