       (file-name-as-directory buffer-dir))))
 
 (defun inferior-erlang-compute-compile-command (module-name opts)
+  (let ((ccfn erlang-compile-command-function-alist)
+	(res (inferior-erlang-compute-erl-compile-command module-name opts))
+	ccfn-entry
+	done)
+    (if (not (null (buffer-file-name)))
+	(while (and (not done) (not (null ccfn)))
+	  (setq ccfn-entry (car ccfn))
+	  (setq ccfn (cdr ccfn))
+	  (if (string-match (car ccfn-entry) (buffer-file-name))
+	      (let ((c-fn (cdr ccfn-entry)))
+		(setq done t)
+		(if (not (null c-fn))
+		    (setq result (funcall c-fn module-name opts)))))))
+    result))
+
+(defun inferior-erlang-compute-erl-compile-command (module-name opts)
   (let* ((out-dir-opt (assoc 'outdir opts))
 	 (out-dir     (cdr out-dir-opt)))
     (if erlang-compile-use-outdir

	 module-name (inferior-erlang-format-comma-opts
		      (remq out-dir-opt opts))
	 tmpvar tmpvar tmpvar2)))))

(defun inferior-erlang-format-comma-opts (opts)
  (if (null opts)

- a dotted pair
- a string
Example: '(bin_opt_info (i . \"/path1/include\") (i . \"/path2/include\"))")

(defvar erlang-compile-command-function-alist
  '((".erl\\'" . inferior-erlang-compute-erl-compile-command)
    (".xrl\\'" . inferior-erlang-compute-leex-compile-command)
    (".yrl\\'" . inferior-erlang-compute-yecc-compile-command)
    ("." . inferior-erlang-compute-erl-compile-command))
  "*Alist of filename patterns vs corresponding compilation functions.
Each element looks like (REGEXP . FUNCTION). Compiling a file whose name
matches REGEXP specifies FUNCTION to use to compute the compilation
command. The FUNCTION will be called with two arguments: module name and
default compilation options, like output directory. The FUNCTION
is expected to return a string.")

(defvar erlang-leex-compile-opts '()
  "*Options to pass to leex when compiling xrl files.
This is an elisp list of options. Each option can be either:
- an atom
- a dotted pair
- a string")

(defvar erlang-yecc-compile-opts '()
  "*Options to pass to yecc when compiling yrl files.
This is an elisp list of options. Each option can be either:
- an atom
- a dotted pair
- a string")

(eval-and-compile
  (defvar erlang-regexp-modern-p
