From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Henrik Enberg Newsgroups: gmane.emacs.help Subject: Re: M-x compile for different file extensions Date: Sat, 19 Oct 2002 20:23:40 +0200 Organization: Le Petomane Appreciation Society Sender: help-gnu-emacs-admin@gnu.org Message-ID: <87fzv2thhv.fsf@enberg.org> References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1035052235 29635 80.91.224.249 (19 Oct 2002 18:30:35 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Sat, 19 Oct 2002 18:30:35 +0000 (UTC) Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 182yMp-0007hT-01 for ; Sat, 19 Oct 2002 20:30:31 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10) id 182yNg-0001RI-00; Sat, 19 Oct 2002 14:31:24 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!skynet.be!skynet.be!fu-berlin.de!uni-berlin.de!h130n2fls32o1112.telia.COM!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 33 Original-NNTP-Posting-Host: h130n2fls32o1112.telia.com (213.65.65.130) Original-X-Trace: fu-berlin.de 1035052162 26386803 213.65.65.130 (16 [125297]) User-Agent: Gnus/5.090008 (Oort Gnus v0.08) Emacs/21.3.50 (i686-pc-linux-gnu) Cancel-Lock: sha1:YktsNggvw4+aN4tKBWq9kQhdIJo= Original-Xref: shelby.stanford.edu gnu.emacs.help:106209 Original-To: help-gnu-emacs@gnu.org Errors-To: help-gnu-emacs-admin@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.help:2758 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:2758 "wgh" writes: > Is there a way to have M-x compile to automatically detect > what command to use depending on the file extension of the > current buffer being edited? Naturally, here's a silly example that uses different compiler depending on whether it's a C or C++ file. It also uses a Makefile if there is one present in the same directory. (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 (if (eq major-mode 'c++-mode) "g++ -Wall -o " "gcc -O2 -Wall -o ") (file-name-sans-extension file) " " file)))))) You can also type the compile command in the minibuffer. > Because I don't really see the advantage of using M-x compile > if I can get away with fewer keystrokes in Bash doing the > exact same thing (i.e. typing the compile command, pressing > the up arrow if I need to recompile, etc.) `compile' does more than just running the compiler. Read the node "Building" in the Emacs manual. -- Booting... /vmemacs.el