   (inferior-erlang-prepare-for-input)
   (let* ((dir (inferior-erlang-compile-outdir))
 ;;; (file (file-name-nondirectory (buffer-file-name)))
-	 (noext (substring (buffer-file-name) 0 -4))
+	 (noext (substring (erlang-local-buffer-file-name) 0 -4))
 	 (opts (append (list (cons 'outdir dir))
 		       (if current-prefix-arg
 			   (list 'debug_info 'export_all))

	    erl-compile-expr)))

(defun inferior-erlang-compute-yecc-compile-command (module-name opts)
  (let ((file-name        (buffer-file-name))
	(erl-compile-expr (inferior-erlang-remove-any-trailing-dot
			   (inferior-erlang-compute-erl-compile-command
			    module-name opts))))

      (setq result (concat result sep (car strs)))
      (setq strs (cdr strs)))
    result))

(defun erlang-local-buffer-file-name ()
  ;; When editing a file remotely via tramp,
  ;; the buffer's file name may be for example
  ;; "/ssh:host.example.com:/some/path/x.erl"
  ;;
  ;; If I try to compile such a file using C-c C-k, an
  ;; erlang shell on the remote host is automatically
  ;; started if needed, but for it to successfully compile
  ;; the file, the c(...)  command that is sent must contain
  ;; the file name "/some/path/x.erl" without the
  ;; tramp-prefix "/ssh:host.example.com:".
  (cond ((null (buffer-file-name))
	 nil)
	((erlang-tramp-remote-file-p)
	 (erlang-tramp-get-localname))
	(t
	 (buffer-file-name))))

(defun erlang-tramp-remote-file-p ()
  (and (fboundp 'tramp-tramp-file-p)
       (tramp-tramp-file-p (buffer-file-name))))

(defun erlang-tramp-get-localname ()
  (let ((tramp-info (tramp-dissect-file-name (buffer-file-name))))
    (if (fboundp 'tramp-file-name-localname)
	(tramp-file-name-localname tramp-info)
      ;; In old versions of tramp, it was `tramp-file-name-path'
      ;; instead of the newer `tramp-file-name-localname'
      (tramp-file-name-path tramp-info))))

;; `next-error' only accepts buffers with major mode `compilation-mode'
;; or with the minor mode `compilation-minor-mode' activated.
