 	(substring base-name (match-beginning 1) (match-end 1))
       base-name)))
 
+;;; Return the module name of the file
+;;;     /tmp/foo/src/x.erl        --> x
+;;;     /tmp/foo/test/x_tests.erl --> x_tests
+(defun erlang-eunit-module-name (file-path)
+  (interactive)
+  (file-name-sans-extension (file-name-nondirectory file-path)))
+
 ;;; Return the directory name which is common to both src and test
 ;;;     /tmp/foo/src/x.erl        --> /tmp/foo
 ;;;     /tmp/foo/test/x_tests.erl --> /tmp/foo

      (concat dir file)
    (concat dir "/" file)))

;;; Run EUnit tests for the current module
(defun erlang-eunit-run-tests ()
  "Run the EUnit test suite for the current module.

With prefix arg, runs tests with the verbose flag set."
  (interactive)
  (let* ((module-name (erlang-add-quotes-if-needed
		       (erlang-eunit-source-module-name buffer-file-name)))
	 (opts        (if current-prefix-arg ", [verbose]" ""))
	 (command     (format "eunit:test(%s%s)." module-name opts)))
    (erlang-eunit-inferior-erlang-send-command command)))

;;; Compile source and EUnit test file and finally run EUnit tests for
;;; the current module
(defun erlang-eunit-compile-and-run-tests ()
  "Compile the source and test files and run the EUnit test suite.

With prefix arg, compiles for debug and runs tests with the verbose flag set."
  (interactive)
  (let ((src-filename  (erlang-eunit-src-filename  buffer-file-name))
	(test-filename (erlang-eunit-test-filename buffer-file-name)))


;;; Key bindings
;;;====================================================================

(defconst erlang-eunit-key-bindings
  '(("\C-c\C-et" erlang-eunit-toggle-src-and-test-file-other-window)
    ("\C-c\C-ek" erlang-eunit-compile-and-run-module-tests)
    ("\C-c\C-ej" erlang-eunit-compile-and-run-current-test)))

(defun erlang-eunit-add-key-bindings ()
  (dolist (binding erlang-eunit-key-bindings)
    (erlang-eunit-bind-key (car binding) (cadr binding))))

(defun erlang-eunit-bind-key (key function)
  (erlang-eunit-ensure-keymap-for-key key)
  (local-set-key key function))

(defun erlang-eunit-ensure-keymap-for-key (key-seq)
  (let ((prefix-keys (butlast (append key-seq nil)))
