Backporting regexp-opt functionality to Emacs 23. WIP.

See https://github.com/JuliaLang/julia/issues/8537