|
From: | Kevin Rodgers |
Subject: | Re: Changing the Compile-Command in C/C++ Mode |
Date: | Fri, 27 Jan 2006 17:45:40 -0700 |
User-agent: | Mozilla Thunderbird 0.9 (X11/20041105) |
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 in Thread] | Current Thread | [Next in Thread] |