Skip to content

Instantly share code, notes, and snippets.

@jasonm23
Created May 15, 2014 02:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonm23/a2c94f44f3c9f58db279 to your computer and use it in GitHub Desktop.
Save jasonm23/a2c94f44f3c9f58db279 to your computer and use it in GitHub Desktop.
(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