From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: stan Newsgroups: gmane.emacs.help Subject: Re: help with makefile command line Date: Fri, 28 Mar 2008 02:11:22 -0500 Organization: home Message-ID: References: NNTP-Posting-Host: lo.gmane.org X-Trace: ger.gmane.org 1206690044 13251 80.91.229.12 (28 Mar 2008 07:40:44 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 28 Mar 2008 07:40:44 +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 08:41:15 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 1Jf9D8-0006ln-3U for geh-help-gnu-emacs@m.gmane.org; Fri, 28 Mar 2008 08:41:14 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Jf9CW-0008LW-Ju for geh-help-gnu-emacs@m.gmane.org; Fri, 28 Mar 2008 03:40:36 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!postnews.google.com!news2.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx01.iad01.newshosting.com!newshosting.com!nntpserver.com!zeus.nntpserver.com!10.1.1.41.MISMATCH!pfilter-v0.1!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: slrn/0.9.8.0 (Linux) Original-Lines: 166 Original-NNTP-Posting-Date: 28 Mar 2008 06:50:49 GMT Original-X-Complaints-To: abuse@teranews.com Original-Xref: shelby.stanford.edu gnu.emacs.help:157392 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:52762 Archived-At: Richard G Riley wrote: > 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. Sorry I confused with my snip. I'm not the op. I have my setup working pretty much the way I want ( is anyone ever really satisfied?) > >> >> 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? Again, our streams got crossed at my snip. Both of our comments should have been directed to the OP and not each other. > >> >> 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? See above. I didn't snip this time for fear of losing you again :)