             (set-buffer-menubar current-menubar)
             (add-submenu nil fsharp-mode-xemacs-menu))))
 
+  (setq compile-command (fsharp-choose-compile-command (buffer-file-name)))
   (turn-on-fsharp-doc-mode)
-
   (run-hooks 'fsharp-mode-hook)
 
   (if fsharp-smart-indentation

  (make-local-variable 'indent-line-function)
  (make-local-variable 'add-log-current-defun-function)
  (make-local-variable 'underline-minimum-offset)

  (add-hook 'completion-at-point-functions #'ac-fsharp-completion-at-point)


      ;; fsharp-indent-offset.  Never turn it on, because the user must
      ;; have explicitly turned it off.
      (if (/= tab-width fsharp-indent-offset)
          (setq indent-tabs-mode nil)))))

(defun fsharp-choose-compile-command (file)
  "Format an appropriate compilation command, depending on several factors:
1. The presence of a makefile
2. The file type
3. The presence of an fsproj. "
  (let* ((fname    (file-name-nondirectory file))
         (ext      (file-name-extension file))
         (fsproj   (fsharp-mode/find-sln-or-fsproj file))
         (makefile (or (file-exists-p "Makefile") (file-exists-p "makefile"))))
    (cond
     (makefile          compile-command)
     ((equal ext "fsl") (concat "fslex "  file))
     ((equal ext "fsy") (concat "fsyacc " file))
     ;; For .fs files, try to find a project first.
     (fsproj            (concat fsharp-build-command " /nologo " fsproj))
     ((equal ext "fs")  (concat fsharp-compile-command " --nologo " file))
     (t                 compile-command))))

(defun fsharp-find-alternate-file ()
  (interactive)
