#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2006
    Posts
    233
    Rep Power
    29

    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?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2006
    Posts
    233
    Rep Power
    29
    An answer to this question was posted on LinuxQuestions.org thanks to user "ntubski".

    His post was as follows:
    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)))))

IMN logo majestic logo threadwatch logo seochat tools logo