Refactor emacs-nw script