From: Kevin Rodgers <ihs_4664@yahoo.com>
Subject: Re: Changing the Compile-Command in C/C++ Mode
Date: Fri, 27 Jan 2006 17:45:40 -0700 [thread overview]
Message-ID: <dreerp$bra$1@sea.gmane.org> (raw)
In-Reply-To: <!&!AAAAAAAAAAAYAAAAAAAAAP8kMXin0B5Bj/D/BqE7ALLCgAAAEAAAAITh2KjO4UxOmd3P0eYzEGoBAAAAAA==@ncsu.edu>
Balaji V. Iyer wrote:
> Hi Everyone,
> I do not always use a make file and I would like the emacs (version
> 21.2.1) to modify the compile-command line to "g++ -Wall -O4 filename.c. I
> thought this script did the trick but it didn't. I do not get any syntax
> error, but when I hit the M-x compile command I still get "make -k"
> How can I fix this? If you have an alternative implementation, I am willing
> to use that too.
>
> (function
> (lambda ()
> (unless (or (file-exists-p "makefile")
> (file-exists-p "Makefile"))
> (make-local-variable 'compile-command)
> (setq compile-command
> (concat "gcc -Wall -O3 -o"
> (file-name-sans-extension
> (file-name-nondirectory buffer-file-name))
> " "
> (file-name-nondirectory buffer-file-name))))))
If that's precisely what is in your .emacs, it doesn't accomplish
anything because all you've done is define an anonymous function without
ensuring that it will ever be called.
Since that compile-command is only useful for C files, do what the doc
string for compile-command suggests:
(add-hook 'c-mode-hook (lambda () ...))
Better yet, rely on make's default rules and macros (e.g. CC and CFLAGS):
(add-hook 'c-mode-hook
(lambda ()
(set (make-local-variable 'compile-command)
(concat "make "
(file-name-sans-extension
(file-name-nondirectory buffer-file-name))))))
--
Kevin Rodgers
prev parent reply other threads:[~2006-01-28 0:45 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-01-27 13:43 Changing the Compile-Command in C/C++ Mode Balaji V. Iyer
2006-01-28 0:45 ` Kevin Rodgers [this message]
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='dreerp$bra$1@sea.gmane.org' \
--to=ihs_4664@yahoo.com \
/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).