Refactor Emacs module into stable and pretest

And use pretest.