From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Daniel Wright Newsgroups: gmane.emacs.help Subject: compile-command customisation Date: Wed, 23 Feb 2005 13:51:27 +0100 Message-ID: Reply-To: Daniel Wright NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1109164104 3249 80.91.229.2 (23 Feb 2005 13:08:24 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 23 Feb 2005 13:08:24 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Feb 23 14:08:24 2005 Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1D3wFR-00083h-Tp for geh-help-gnu-emacs@m.gmane.org; Wed, 23 Feb 2005 14:08:14 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1D3wWn-0005y7-PZ for geh-help-gnu-emacs@m.gmane.org; Wed, 23 Feb 2005 08:26:09 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1D3wRT-0003ZW-Vo for help-gnu-emacs@gnu.org; Wed, 23 Feb 2005 08:20:40 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1D3wRL-0003WK-RD for help-gnu-emacs@gnu.org; Wed, 23 Feb 2005 08:20:35 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1D3wRH-0003Md-0I for help-gnu-emacs@gnu.org; Wed, 23 Feb 2005 08:20:27 -0500 Original-Received: from [64.233.184.197] (helo=wproxy.gmail.com) by monty-python.gnu.org with esmtp (Exim 4.34) id 1D3vzG-0001Ab-Gx for help-gnu-emacs@gnu.org; Wed, 23 Feb 2005 07:51:30 -0500 Original-Received: by wproxy.gmail.com with SMTP id 50so1617228wri for ; Wed, 23 Feb 2005 04:51:28 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:mime-version:content-type:content-transfer-encoding; b=MkGRq29CtA/sqC+QdZv9OajqksAvWf0L7BpcH1nOu8/dU9WDwxtGhQ77SliHEMj1ldt7Is+LJ44Idf/lRHyOcu5vn3wFXruiUFcaw+veyOAc9Y0/LceuThCIFGKeMm6MA7QCXj+LQsqN23TaIGXmDmbe2L7XtTZ4wIX6KSyztms= Original-Received: by 10.54.35.64 with SMTP id i64mr21454wri; Wed, 23 Feb 2005 04:51:28 -0800 (PST) Original-Received: by 10.54.51.22 with HTTP; Wed, 23 Feb 2005 04:51:27 -0800 (PST) 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:24276 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:24276 Hi all, 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): (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 :) Cheers, Daniel