From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Richard G Riley Newsgroups: gmane.emacs.help Subject: Re: help with makefile command line Date: Fri, 28 Mar 2008 04:01:29 +0100 Organization: http://www.gnu.org/software/emacs/ Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1206675723 14943 80.91.229.12 (28 Mar 2008 03:42:03 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 28 Mar 2008 03:42:03 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Mar 28 04:42:34 2008 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Jf5U7-0002nY-PN for geh-help-gnu-emacs@m.gmane.org; Fri, 28 Mar 2008 04:42:32 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Jf5TW-0005X2-6u for geh-help-gnu-emacs@m.gmane.org; Thu, 27 Mar 2008 23:41:54 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!feeder.news-service.com!news.motzarella.org!motzarella.org!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 158 Original-X-Trace: feeder.motzarella.org U2FsdGVkX1/NOYge6S+JqZ+JxYvpRxAde9ckGzxGQcfjYWleYWhK4qGzh5oROr/O12i83c9BvzkxsQqnMDOGr2rfdDkbKuVSBp4vXiKGl88XXkt4lx7tZKeFqPXDrTM8lzK2S+UvHmUdai35sLZ6dg== Original-X-Complaints-To: Please send complaints to abuse@motzarella.org with full headers Original-NNTP-Posting-Date: Fri, 28 Mar 2008 03:01:35 +0000 (UTC) X-Auth-Sender: U2FsdGVkX198EV0M9KCCUOoSxXi8WnQG4YKCNBHQXjyJqAgFuYmM3A== Cancel-Lock: sha1:7jUF66OrotGkoKC6z+5/u7xqY2w= User-Agent: Gnus/5.110007 (No Gnus v0.7) Emacs/22.1 (gnu/linux) Original-Xref: shelby.stanford.edu gnu.emacs.help:157391 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:52761 Archived-At: stan writes: > Richard G Riley wrote: >> "Balaji V. Iyer" writes: >> >>> Hello Everyone, >>> I use the compile option extenstively in emacs. When I type "M-x >>> compile" the default line is "make -k" Many times I do not have a make >>> file thus I would lke the default line to be >>> >>> "gcc -ansi -O4 -Wall " >>> >>> How do I do this? >>> >>> I tried the following command but it doesn't seem to work (If anyone >>> have a better idea please let me know). >>> >>> (function >>> (lambda () >>> (unless (or (file-exists-p "makefile") >>> (file-exists-p "Makefile")) >>> (setq compile-command >>> (concat "gcc -Wall -O3 -o" >>> (file-name-sans-extension (file-name-nondirectory >>> buffer-file -name)) >>> " " >>> (file-name-nondirectory buffer-file-name)))))) > > > Seems like it might be easier to write a makefile :) Sorry. I'm not sure I understand. You snipped all my code. Did it not work for you? I use it on a daily basis. > > Do you really mean that you plan to not use makefiles? If not you > might I do use makefiles. It's in the code I gave to you. If the makefile is not there then it uses gcc directly which is what you said you wanted. Here it is again: ,---- | ;;allow compile window to vanish if no errors. | (add-hook 'compilation-finish-functions | (lambda (buf str) | (if (string-match "exited abnormally" str) | (next-error) | ;;no errors, make the compilation window go away in a few seconds | (run-at-time "2 sec" nil 'delete-windows-on (get-buffer-create "*compilation*")) | (message "No Compilation Errors!") | ) | )) | | (defun my-c-init() | | (line-number-mode 1) | | (setq compilation-window-height 16) | (setq compilation-finish-functions | (lambda (buf str) | (if (string-match "exited abnormally" str) | | ;;there were errors | (message "compilation errors, F11 to goto next error.") | | ;;no errors, make the compilation window go away in 0.5 seconds | ;; (run-at-time 5.0 nil 'delete-windows-on buf) | (message "NO COMPILATION ERRORS!")))) | | | (c-set-style "linux") | | (setq gdb-show-main t) | (setq gdb-many-windows t) | | (let ((dl '( | ([f1] . jump-man-page) | ; ([backtab] . semantic-complete-analyze-inline) | ;; ([f5] . find-tag-noconfirm) | ([f6] . find-tag-repeat) | ([f7] . pop-tag-mark) | ([f2] . gdb-restore-windows) | ([f3] . cscope-find-global-definition-no-prompting) | ([f4] . repeat) | ([f10] . (lambda()(interactive)(mycompile))) | ([f11] . next-error) | ([f12] . gdb)))) | (dolist (i dl) | | (define-key c-mode-base-map (car i) (cdr i)) | ;; (define-key c-mode-map (car i) (cdr i)) | ;; (define-key c++-mode-map (car i) (cdr i)) | )) | | (define-key c-mode-map | "\C-c\C-f" | 'php-search-documentation) | | (define-key c-mode-map | "\C-c\C-m" | 'php-browse-manual) | | (define-key c-mode-map | "\C-c\C-c" | 'c-browse-faq) | | (global-unset-key "\M-/") | (show-paren-mode 1) | | ) | | (add-hook 'c-mode-common-hook 'my-c-init) | | (defun mycompile() | | (unless (or (file-exists-p "makefile") | (file-exists-p "Makefile")) | (set (make-local-variable 'compile-command) | (let ((file (file-name-nondirectory buffer-file-name))) | (format "%s -o %s %s %s %s %s" | (or (getenv "CC") "gcc") | (file-name-sans-extension file) | (or (getenv "GTKFLAGS") "") | (or (getenv "CPPFLAGS")"-DDEBUG=9") | (or (getenv "CFLAGS") "-std=c99 -pedantic -Wall -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Wconversion -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wnested-externs -Winline -g") | file))) | | ) | (compile compile-command) | ) | `---- > just want to change the command on a session basis. You do know that you > can backspace over the make -k and simply type g++ -Wall -g file.cpp and > that will become the new command until you close emacs. I tend to do > that when working on small throwaway programs. Yes, I do know that. But why would I do that when I can automate it as above depending on whether there is a Makefile or not? > > Another idea, if you don't like what Eli suggested earlier is to come up > with a makefile template and use auto insert. I have a template that I > only need to basically change the list of files in and it save a lot of > time during the compile, run. scream. debug, edit cycle. > > Finally, you can edit the compile command for all time but it seems like > a bad idea. I'm not sure I understand. I have makefiles for most of my projects. If I don't have one it builds a compile and link command based on the c file name which is what you requested. Sorry I can't be more help. Did you try my code?