It works great!
Thanks very much!

On Thu, Mar 8, 2012 at 3:40 AM, Thien-Thi Nguyen <ttn@gnuvola.org> wrote:
The previous code fails if COMMAND starts with a relative directory.
This version is more robust in that regard:

(defun compilation-compile-with-current-line (dir)
 "Extract the current line as a command and execute it in DIR."
 (interactive "DExecute command in directory: ")
 (let ((command (substring-no-properties (thing-at-point 'line) 0 -1)))
   ;; Do it this way instead of using "cd DIR; COMMAND"
   ;; to avoid outrageous prefixing on repeated invocations.
   (let ((default-directory (file-name-as-directory dir)))
     (compile command))))