[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
compile-command customisation
From: |
Daniel Wright |
Subject: |
compile-command customisation |
Date: |
Wed, 23 Feb 2005 13:51:27 +0100 |
Hi all,
Sorry to flog a dead horse: this subject has been discussed recently.
But I found the compile-command customisation so fantastic, it took me
to a new level of emacs power, (from the emacs wiki):
(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 "gcc -g -Wall -W -o " (file-name-sans-extension
file)
" " file))))))
But let's say you want to write a little test c/c++ program that you
don't want to include in your Makefile, but still have in the
project's directory (i.e. there is a Makefile there). Then the above
version of the function won't work, so I've playing with the following
(which searches through the Makefile):
(add-hook 'c-mode-common-hook
(lambda ()
(let ((count 0) (file (file-name-nondirectory buffer-file-name)))
(if (file-exists-p "Makefile")
(progn
(find-file "Makefile")
(while (search-forward (file-name-sans-extension file) nil
t count)
(setq count (1+ count)))
(find-file file)))
(unless (> count 1)
(progn
(set (make-local-variable 'compile-command)
(concat "gcc -g -Wall -W -o " (file-name-sans-extension
file)
" " file)))))))
I was wondering what you all think. I started with emacs lisp this
week, so I don't mind if you tell me how bad it is, as long as you
tell us how it could be done better :)
Cheers,
Daniel
- compile-command customisation,
Daniel Wright <=
- Re: compile-command customisation, Stefan Monnier, 2005/02/23
- Re: compile-command customisation, Kevin Rodgers, 2005/02/23
- Re: compile-command customisation, Thien-Thi Nguyen, 2005/02/23
- Re: compile-command customisation, Daniel Wright, 2005/02/24
- Re: compile-command customisation, Daniel Wright, 2005/02/24
- Re: compile-command customisation, Daniel Wright, 2005/02/24
- Re: compile-command customisation, Stefan Monnier, 2005/02/25