all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Trying to bind a new key in C mode
@ 2005-02-12  0:09 Jim Hunter
  2005-02-12  2:41 ` August
       [not found] ` <mailman.1836.1108176936.2841.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 3+ messages in thread
From: Jim Hunter @ 2005-02-12  0:09 UTC (permalink / raw)


I would like to bind C-c c to run the 'compile' function in C mode 
(and, ultimately, C-c r to run 'recompile'), but cannot get it to
work.  Unfortunately, I know nothing about Lisp, so I simply copied
the example from the Emacs info page "Local Keymaps" and modified it
to this (in my .emacs file):

(add-hook 'c-mode-hook
		'(lambda ()
		   (define-key c-mode-map "\C-cc" 'compile)))

Any help would be greatly appreciated

Jim Hunter

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Trying to bind a new key in C mode
  2005-02-12  0:09 Trying to bind a new key in C mode Jim Hunter
@ 2005-02-12  2:41 ` August
       [not found] ` <mailman.1836.1108176936.2841.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 3+ messages in thread
From: August @ 2005-02-12  2:41 UTC (permalink / raw)


On fre, 2005-02-11 at 18:09 -0600, Jim Hunter wrote:
> I would like to bind C-c c to run the 'compile' function in C mode 
> (and, ultimately, C-c r to run 'recompile'), but cannot get it to
> work.  Unfortunately, I know nothing about Lisp, so I simply copied
> the example from the Emacs info page "Local Keymaps" and modified it
> to this (in my .emacs file):
> 
> (add-hook 'c-mode-hook
> 		'(lambda ()
> 		   (define-key c-mode-map "\C-cc" 'compile)))
> 

Try

(add-hook 'c-mode-hook
          '(lambda () (local-set-key "\C-cc" 'compile)))

Since compiling and running a program are such common operations I
instead have the following definitions in my `.emacs'. The global key
settings apply to all buffers in all modes.

(global-set-key [f11] 'compile)
(global-set-key [f12] 'my-shell-command)

(defun my-shell-command ()
  "Similar to `shell-command', but shows previous command as initial
contents or (if there is no previous command) guesses the name of the
program you want to run based on the name of the current buffer and
inserts that as initial contents."
  (interactive)
  (shell-command 
   (read-from-minibuffer "Shell command: " 
                         (let ((f (buffer-file-name)))
                           (when f
                             (let ((bin (file-name-sans-extension 
                                         (file-name-nondirectory f))))
                               (cond (shell-command-history 
                                      (car shell-command-history))
                                     (t
                                      (concat "./" bin " &"))))))
                         nil nil 'shell-command-history)))

-- 
August

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Trying to bind a new key in C mode
       [not found] ` <mailman.1836.1108176936.2841.help-gnu-emacs@gnu.org>
@ 2005-02-12 17:59   ` Jim Hunter
  0 siblings, 0 replies; 3+ messages in thread
From: Jim Hunter @ 2005-02-12 17:59 UTC (permalink / raw)


August <fusionfive@comhem.se> writes:

> On fre, 2005-02-11 at 18:09 -0600, Jim Hunter wrote:
> > I would like to bind C-c c to run the 'compile' function in C mode 
> > (and, ultimately, C-c r to run 'recompile'), but cannot get it to
> > work.  Unfortunately, I know nothing about Lisp, so I simply copied
> > the example from the Emacs info page "Local Keymaps" and modified it
> > to this (in my .emacs file):
> > 
> > (add-hook 'c-mode-hook
> > 		'(lambda ()
> > 		   (define-key c-mode-map "\C-cc" 'compile)))
> > 
> 
> Try
> 
> (add-hook 'c-mode-hook
>           '(lambda () (local-set-key "\C-cc" 'compile)))
> 
[snip]

Thanks very much for the reply.  When your example also didn't work,
I realized that cc-mode might be loading before that part of .emacs was
processed.  Moving the add-hook call before my desktop was loaded fixed
it -- both for your example and the original example.

Thanks again!

Jim

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-02-12 17:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-02-12  0:09 Trying to bind a new key in C mode Jim Hunter
2005-02-12  2:41 ` August
     [not found] ` <mailman.1836.1108176936.2841.help-gnu-emacs@gnu.org>
2005-02-12 17:59   ` Jim Hunter

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.