contrib/cfengine.el: add 25.1 compatibility code and clean up

Please test this with older Emacs 24 releases you may have lying around.  I've tested with 24.4 and 25.1 (not released).  This patch includes GPL code from the Emacs repository, so please go there if you want the full history.

I am officially dropping Emacs 23 and XEmacs support (it's been a while!), unless someone else is willing to maintain the compatibility code.  The `prog-mode` workarounds in particular are a pain.