[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: best way to add commands to c-mode??....
From: |
Michael Slass |
Subject: |
Re: best way to add commands to c-mode??.... |
Date: |
Wed, 23 Oct 2002 19:46:27 GMT |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 |
seberino@spawar.navy.mil writes:
>Is this the simplest way to add commands to c-mode?...
>
>(defun cs-c-mode() (interactive)
> (c-mode)
> (c-set-style "K&R")
> (setq c-basic-offset 3)
> (local-set-key "\C-d" 'cs-kill-line))
>
>
>Did I have to define a new mode/function to add
>these 3 commands??
>
The most common paradigm is
1) define a function that does all your c-mode customizations
2) add your function to one of the c-mode hooks
(defun cs-c-mode-setup ()
(c-set-style "K&R")
(setq c-basic-offset 3)
(local-set-key "\C-d" 'cs-kill-line))
(add-hook 'c-mode-hook 'cs-c-mode-setup)
One of the last things c-mode does when it starts is to run all the
functions listed in the c-mode-hook variable.
Check out the documentation for hooks in the emacs manual
C-h i m emacs <RET> m hook <RET>
which talks about exactly what you're trying to do.
Also, if you're using a newer emacs, there is another hook that's used
for all c-like modes. Once you've loaded c-mode, try
M-x apropos <RET> c.*common to see the names of the variables.
--
Mike Slass