Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


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

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


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:
(setq compile-command (concat "javac " (buffer-name)))
I cd to the folder, and run emacs

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

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

How to I get this to use the correct buffer name for the active buffer?
Old 10-02-2006, 11:49 AM   #2
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:
(let ((compile-command
          (setq cmnd (concat "javac " buffer-name)))))
Alternately, might I suggest using SETF instead of SETQ?
Old 10-02-2006, 03:25 PM   #3
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()
(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 03:40 PM.
Old 10-02-2006, 05:58 PM   #4
Senior Member
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,388

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
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:
(add-hook 'java-mode-hook
	    (set (make-local-variable 'compile-command) (concat "javac " (buffer-name)))))
Old 10-02-2006, 09:32 PM   #5
Registered: Nov 2005
Location: New Jersey, USA
Distribution: SuSE
Posts: 492

Original Poster
Rep: Reputation: 31

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 12:59 PM
Lisp/Emacs: How to do a macro on a buffer-name with another extension LuisG Linux - Software 3 10-25-2004 10:26 PM
emacs and lisp jonathanz1980 Linux - Software 4 09-24-2004 11:00 AM
emacs and lisp jonathanz1980 Programming 4 09-24-2004 10:30 AM
Lisp, emacs-lisp aizkorri Programming 1 09-04-2002 07:16 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:21 PM.

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