From: Henrik Enberg <henrik+news@enberg.org>
Subject: Re: M-x compile for different file extensions
Date: Sat, 19 Oct 2002 20:23:40 +0200 [thread overview]
Message-ID: <87fzv2thhv.fsf@enberg.org> (raw)
In-Reply-To: iPgs9.26259$wU3.2299106@news0.telusplanet.net
"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
next prev parent reply other threads:[~2002-10-19 18:23 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-10-19 17:41 M-x compile for different file extensions wgh
2002-10-19 18:23 ` Henrik Enberg [this message]
2002-10-20 0:00 ` Ehud Karni
2002-10-21 18:40 ` kgold
2002-10-22 5:33 ` James Cozine
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87fzv2thhv.fsf@enberg.org \
--to=henrik+news@enberg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).