From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Kevin Rodgers Newsgroups: gmane.emacs.help Subject: Re: compile-command customisation Date: Wed, 23 Feb 2005 08:48:27 -0700 Message-ID: <383mueF5i9chfU1@individual.net> 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 1109173671 5804 80.91.229.2 (23 Feb 2005 15:47:51 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 23 Feb 2005 15:47:51 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Feb 23 16:47:50 2005 Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1D3yjb-000227-FT for geh-help-gnu-emacs@m.gmane.org; Wed, 23 Feb 2005 16:47:31 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1D3z0y-00013W-NG for geh-help-gnu-emacs@m.gmane.org; Wed, 23 Feb 2005 11:05:28 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 61 Original-X-Trace: individual.net M5Q/Ykw9AA8zmwICCVr4jwAYHrkpAorY/1mBGBTsK4C+GQ9uw= User-Agent: Mozilla Thunderbird 0.9 (X11/20041105) X-Accept-Language: en-us, en In-Reply-To: Original-Xref: shelby.stanford.edu gnu.emacs.help:128742 Original-To: help-gnu-emacs@gnu.org 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:24279 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:24279 Daniel Wright wrote: > Sorry to flog a dead horse: this subject has been discussed recently. > But I found the compile-command customisation so fantastic, it took me > to a new level of emacs power, (from the emacs wiki): > > (add-hook 'c-mode-common-hook > (lambda () > (unless (file-exists-p "Makefile") > (set (make-local-variable 'compile-command) > (let ((file (file-name-nondirectory buffer-file-name))) > (concat "gcc -g -Wall -W -o " (file-name-sans-extension file) > " " file)))))) > > But let's say you want to write a little test c/c++ program that you > don't want to include in your Makefile, but still have in the > project's directory (i.e. there is a Makefile there). Then the above > version of the function won't work, so I've playing with the following > (which searches through the Makefile): It doesn't work because of the presence of a Makefile, right? But make has many built-in default rules, including rules that allow you to build an executable from its C or C++ source. In fact, there is a similar code snippet in compile-command's doc string, and just last week I was considering submitting a bug report that the Makefile test is not useful in the mode hook. Note also that make's default rules are parameterized by macros, e.g. CC, CPPFLAGS, CFLAGS, CXXFLAGS, and LDFLAGS, which in turn get their default values from your environment. So all you should really need is CC=gcc and CFLAGS="-g -W -Wall", plus this: (add-hook 'c-mode-common-hook (lambda () (set (make-local-variable 'compile-command) (format "make %s" (file-name-sans-extension (file-name-nondirectory buffer-file-name)))))) > (add-hook 'c-mode-common-hook > (lambda () > (let ((count 0) (file (file-name-nondirectory buffer-file-name))) > (if (file-exists-p "Makefile") > (progn > (find-file "Makefile") > (while (search-forward (file-name-sans-extension file) nil t count) > (setq count (1+ count))) > (find-file file))) > (unless (> count 1) > (progn > (set (make-local-variable 'compile-command) > (concat "gcc -g -Wall -W -o " (file-name-sans-extension file) > " " file))))))) > > I was wondering what you all think. I started with emacs lisp this > week, so I don't mind if you tell me how bad it is, as long as you > tell us how it could be done better :) I think that less is more. -- Kevin Rodgers