LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-02-2006, 10:36 AM   #1
jantman
Member
 
Registered: Nov 2005
Location: New Jersey, USA
Distribution: SuSE
Posts: 492

Rep: Reputation: 31
Emacs Lisp - buffer name as part of compile-command


Hello,

I'm trying to setup GNU emacs to do some SIMPLE java work for me.

I'm working in a given folder, and want to just edit and compile programs in this one folder.

In my .emacs, I have:
Code:
(setq compile-command (concat "javac " (buffer-name)))
I cd to the folder, and run emacs sample.java

I edit the file, and then in emacs, I M-x compile.

The problem, is that in the minibuffer, it shows:
Compile command: javac *scratch*

instead of javac sample.java

Why is this? The buffer *scratch* is (by default) open, but is NOT in the one visible window - sample.java is.

How to I get this to use the correct buffer name for the active buffer?
 
Old 10-02-2006, 10:49 AM   #2
indienick
Senior Member
 
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853

Rep: Reputation: 65
hmm.....might I suggest setting it like this:
Code:
(let ((compile-command
          (setq cmnd (concat "javac " buffer-name)))))
Alternately, might I suggest using SETF instead of SETQ?
 
Old 10-02-2006, 02:25 PM   #3
mfeat
Member
 
Registered: Aug 2003
Location: Akron, OH
Distribution: Fedora Core 3
Posts: 185

Rep: Reputation: 30
i've used the following to compile c programs by binding to the F4 key, it saves the file and then compiles it. probably would work the same replacing the cc command with javac.

(global-set-key [f4] 'wcompile)

(defun wcompile()
(interactive)
(save-buffer)
(compile (concat "cc " buffer-file-name))
)


over time i found it is more flexible to just map the F4 key to compile which allows you to put in whatever command you want at the prompt (at the bottom), that way you can do any set of commands such as compile & run with the output piped to a bunch of other commands (ie: sort, grep, awk, sed, etc). the command (or set of commands separated by semicolons) that you put in remains in the command buffer and each time you run compile it will be there to either rerun or modify. it's a handy way of having a command prompt within emacs.

Last edited by mfeat; 10-02-2006 at 02:40 PM.
 
Old 10-02-2006, 04:58 PM   #4
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
The problem is that compile-command gets set when the your .emacs is loaded, what you need to do is add a hook that will run every time you open a java file:
Code:
(add-hook 'java-mode-hook
	  (lambda()
	    (set (make-local-variable 'compile-command) (concat "javac " (buffer-name)))))
 
Old 10-02-2006, 08:32 PM   #5
jantman
Member
 
Registered: Nov 2005
Location: New Jersey, USA
Distribution: SuSE
Posts: 492

Original Poster
Rep: Reputation: 31
ntubski,

thanks, that's exactly what I needed. And now that I think about it (and read up on hooks) I understand the *scratch* issue.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Emacs LISP - function and keymap? jantman Programming 5 09-28-2006 11:59 AM
Lisp/Emacs: How to do a macro on a buffer-name with another extension LuisG Linux - Software 3 10-25-2004 09:26 PM
emacs and lisp jonathanz1980 Linux - Software 4 09-24-2004 10:00 AM
emacs and lisp jonathanz1980 Programming 4 09-24-2004 09:30 AM
Lisp, emacs-lisp aizkorri Programming 1 09-04-2002 06:16 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration