From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: August Newsgroups: gmane.emacs.help Subject: Re: Trying to bind a new key in C mode Date: Sat, 12 Feb 2005 03:41:49 +0100 Message-ID: <1108176109.6148.14.camel@c83-250-206-179.bredband.comhem.se> References: <87is4y3agp.fsf@paradigmshift.homelinux.net> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1108176038 1323 80.91.229.2 (12 Feb 2005 02:40:38 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 12 Feb 2005 02:40:38 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Feb 12 03:40:37 2005 Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1CznCx-0007lK-5G for geh-help-gnu-emacs@m.gmane.org; Sat, 12 Feb 2005 03:40:31 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1CznS0-0005TL-8m for geh-help-gnu-emacs@m.gmane.org; Fri, 11 Feb 2005 21:56:04 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1CznRN-0005K9-BT for help-gnu-emacs@gnu.org; Fri, 11 Feb 2005 21:55:25 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1CznRI-0005HU-Nw for help-gnu-emacs@gnu.org; Fri, 11 Feb 2005 21:55:22 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1CznRI-0005HK-I6 for help-gnu-emacs@gnu.org; Fri, 11 Feb 2005 21:55:20 -0500 Original-Received: from [81.228.10.109] (helo=av7-2-sn4.m-sp.skanova.net) by monty-python.gnu.org with esmtp (Exim 4.34) id 1CznDs-0002S8-QF for help-gnu-emacs@gnu.org; Fri, 11 Feb 2005 21:41:29 -0500 Original-Received: by av7-2-sn4.m-sp.skanova.net (Postfix, from userid 502) id 2286237E44; Sat, 12 Feb 2005 03:41:27 +0100 (CET) Original-Received: from smtp4-1-sn4.m-sp.skanova.net (smtp4-1-sn4.m-sp.skanova.net [81.228.10.181]) by av7-2-sn4.m-sp.skanova.net (Postfix) with ESMTP id 123F037E42 for ; Sat, 12 Feb 2005 03:41:27 +0100 (CET) Original-Received: from c83-250-206-179.bredband.comhem.se (c83-250-206-179.bredband.comhem.se [83.250.206.179]) by smtp4-1-sn4.m-sp.skanova.net (Postfix) with ESMTP id F1C5F37E42 for ; Sat, 12 Feb 2005 03:41:26 +0100 (CET) Original-To: help-gnu-emacs@gnu.org In-Reply-To: <87is4y3agp.fsf@paradigmshift.homelinux.net> X-Mailer: Evolution 2.0.2 (2.0.2-3) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org X-MailScanner-To: geh-help-gnu-emacs@m.gmane.org Xref: main.gmane.org gmane.emacs.help:24044 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:24044 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