I am trying to set up Emacs so that when I choose "Compile.." in the menu, Emacs executes "make filename" on the command line. I am trying something like:
(setq compile-command (concat "make " (file-name-sans-extension
buffer-file-name)))
but it doesn't work - it looks like Emacs is is looking for a file-name for the *scratch*
buffer, which doesn't have one. Does anyone know how to fix this?
Thanks.
UPDATE: as suggested by Cheeso, a hook fixes the problem. Here is a version that works for me:
(defun cur-file ()
(file-name-sans-extension
(file-name-nondirectory (buffer-file-name (current-buffer)))))
(add-hook 'c++-mode-hook
(lambda()
(set (make-local-variable 'compile-command)
(concat "make " (cur-file)))))