Change the default text editor in OSX

$ osascript -e 'id of app "Emacs"'
org.gnu.Emacs
$ defaults write com.apple.LaunchServices/com.apple.launchservices.secure LSHandlers -array-add '{LSHandlerContentType=public.plain-text; LSHandlerRoleAll=org.gnu.Emacs;}'
<reboot>

Emacs commands

M-|
Pipe a region to a shell command/pipe. Prefix with C-u to replace the region with the output.