From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kevin Rodgers Newsgroups: gmane.emacs.help Subject: Re: Changing the Compile-Command in C/C++ Mode Date: Fri, 27 Jan 2006 17:45:40 -0700 Message-ID: References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1138503497 30494 80.91.229.2 (29 Jan 2006 02:58:17 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 29 Jan 2006 02:58:17 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Jan 29 03:58:14 2006 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1F32lV-00054v-Vu for geh-help-gnu-emacs@m.gmane.org; Sun, 29 Jan 2006 03:58:10 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1F32oO-0002JO-PY for geh-help-gnu-emacs@m.gmane.org; Sat, 28 Jan 2006 22:01:09 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1F2xoD-0001lO-SU for help-gnu-emacs@gnu.org; Sat, 28 Jan 2006 16:40:38 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1F2wbM-0006tv-I1 for help-gnu-emacs@gnu.org; Sat, 28 Jan 2006 15:23:17 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1F2wLr-00018H-UE for help-gnu-emacs@gnu.org; Sat, 28 Jan 2006 15:07:16 -0500 Original-Received: from [80.91.229.2] (helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1F2eGN-0005yK-S8 for help-gnu-emacs@gnu.org; Fri, 27 Jan 2006 19:48:24 -0500 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1F2eDw-0002hE-FE for help-gnu-emacs@gnu.org; Sat, 28 Jan 2006 01:45:54 +0100 Original-Received: from 207.167.42.60 ([207.167.42.60]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 28 Jan 2006 01:45:52 +0100 Original-Received: from ihs_4664 by 207.167.42.60 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 28 Jan 2006 01:45:52 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-To: help-gnu-emacs@gnu.org Original-Lines: 41 Original-X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: 207.167.42.60 User-Agent: Mozilla Thunderbird 0.9 (X11/20041105) X-Accept-Language: en-us, en In-Reply-To: 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 Xref: news.gmane.org gmane.emacs.help:32886 Archived-At: Balaji V. Iyer wrote: > Hi Everyone, > I do not always use a make file and I would like the emacs (version > 21.2.1) to modify the compile-command line to "g++ -Wall -O4 filename.c. I > thought this script did the trick but it didn't. I do not get any syntax > error, but when I hit the M-x compile command I still get "make -k" > How can I fix this? If you have an alternative implementation, I am willing > to use that too. > > (function > (lambda () > (unless (or (file-exists-p "makefile") > (file-exists-p "Makefile")) > (make-local-variable 'compile-command) > (setq compile-command > (concat "gcc -Wall -O3 -o" > (file-name-sans-extension > (file-name-nondirectory buffer-file-name)) > " " > (file-name-nondirectory buffer-file-name)))))) If that's precisely what is in your .emacs, it doesn't accomplish anything because all you've done is define an anonymous function without ensuring that it will ever be called. Since that compile-command is only useful for C files, do what the doc string for compile-command suggests: (add-hook 'c-mode-hook (lambda () ...)) Better yet, rely on make's default rules and macros (e.g. CC and CFLAGS): (add-hook 'c-mode-hook (lambda () (set (make-local-variable 'compile-command) (concat "make " (file-name-sans-extension (file-name-nondirectory buffer-file-name)))))) -- Kevin Rodgers