 (defun wandbox-compile-region (from to)
   "Compile specified region."
   (interactive "r")
-  (let ((profile (wandbox-read-profile))
+  (let ((profile (or (wandbox-buffer-profile)
+                     (wandbox-find-profile :ext (file-name-extension (buffer-file-name)))
+                     (wandbox-read-profile)))
         (code (buffer-substring-no-properties from to)))
     (apply #'wandbox-compile :code code profile)))
 

                          (match-string 1 cmd)))))
          (wandbox-list-compilers)))

(defun wandbox-list-compilers ()
  "Return compilers available in wandbox."
  (unless wandbox-compilers

                               (if lang (wandbox-find-profile :lang lang))
                               (if name (wandbox-find-profile :name name))
                               (if (and file (file-exists-p file))
                                   (wandbox-fetch-as-profile file)))))
  (dolist (f wandbox-precompiled-hook)
    (setq profile (wandbox-merge-plist profile (apply f profile))))

