help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: M-x compile for different file extensions


From: Henrik Enberg
Subject: Re: M-x compile for different file extensions
Date: Sat, 19 Oct 2002 20:23:40 +0200
User-agent: Gnus/5.090008 (Oort Gnus v0.08) Emacs/21.3.50 (i686-pc-linux-gnu)

"wgh" <wgh@askme.ok> 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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]