Taken / adapted from stuff in http://www.emacswiki.org/emacs/SearchAtPoint