extract useful function

stolen from otfrom/otfrom-org-emacs repo