* programming file-extensions in .emacs
@ 2008-02-27 14:17 efrem
2008-02-27 16:20 ` Jason Rumney
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: efrem @ 2008-02-27 14:17 UTC (permalink / raw)
To: help-gnu-emacs
Hello,
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.
The next function does work but It needs to type of "M-x mykeys"(I
don't like it!). I could put these setting into corresponding xxx.elc
files but I prefer to have these definitions in my .emacs file.
If I remove the 2 first lines of this code then it does not work:
error.
What is the way to change this code it runs properly without any
typings like "M-x mykeys": the .emacs must do these settings itself?
Thank you in advance
Oleg
(defun mykeys ()
(interactive)
(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)
))
))
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: programming file-extensions in .emacs
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
2 siblings, 0 replies; 5+ messages in thread
From: Jason Rumney @ 2008-02-27 16:20 UTC (permalink / raw)
To: help-gnu-emacs
On 27 Feb, 14:17, efrem <oleg-zhu...@hotmail.ru> wrote:
> 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.
...
> What is the way to change this code it runs properly without any
> typings like "M-x mykeys": the .emacs must do these settings itself?
(add-hook 'fortran-mode-hook 'mykeys)
(add-hook 'c++-mode-hook 'mykeys)
The latter could be replaced with c-mode-common-hook if you want to
extend this to all C like programming languages.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: programming file-extensions in .emacs
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
2 siblings, 0 replies; 5+ messages in thread
From: Peter Dyballa @ 2008-02-27 16:25 UTC (permalink / raw)
To: efrem; +Cc: help-gnu-emacs
Am 27.02.2008 um 15:17 schrieb 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.
Can you think of hooks for fortran-mode or f90-mode or C++-mode that
would automatically extend the local keymap bindings?
--
Greetings
Pete
Clovis' Consideration of an Atmospheric Anomaly:
The perversity of nature is nowhere better demonstrated
than by the fact that, when exposed to the same atmosphere,
bread becomes hard while crackers become soft.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: programming file-extensions in .emacs
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
2 siblings, 1 reply; 5+ messages in thread
From: Harald Hanche-Olsen @ 2008-02-27 16:55 UTC (permalink / raw)
To: help-gnu-emacs
+ 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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: programming file-extensions in .emacs
2008-02-27 16:55 ` Harald Hanche-Olsen
@ 2008-02-28 7:36 ` efrem
0 siblings, 0 replies; 5+ messages in thread
From: efrem @ 2008-02-28 7:36 UTC (permalink / raw)
To: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2008-02-28 7:36 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 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).