Created
May 15, 2014 02:57
-
-
Save jasonm23/a2c94f44f3c9f58db279 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun operate-on-point-or-region (fn) | |
"Get the current unspaced string at point, or the current region, if selected, and replace it with the return value of fn - an ordinary defun." | |
(let (pos1 pos2 meat) | |
(if (and transient-mark-mode mark-active) | |
(setq pos1 (region-beginning) | |
pos2 (region-end)) | |
(setq pos1 (car (bounds-of-thing-at-point 'symbol)) | |
pos2 (cdr (bounds-of-thing-at-point 'symbol)))) | |
(setq meat (funcall fn (buffer-substring-no-properties pos1 pos2))) | |
(delete-region pos1 pos2) | |
(insert meat))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment