Emacs Stuff

Change the default text editor in MacOS

$ BUNDLE=$(osascript -e 'id of app "Emacs Client"') # or just "Emacs" if not using emacs-plus
org.gnu.Emacs
$ defaults write com.apple.LaunchServices/com.apple.launchservices.secure LSHandlers -array-add "{LSHandlerContentType=public.plain-text; LSHandlerRoleAll=$BUNDLE;}"
<reboot>

emacs shell command on MacOS

If you start an emacs server in your .emacs, this will let you use emacsclient in a reasonable way. Name this script 'emacs' and put it in your path before any emacs binaries.

#!/usr/bin/env bash

pgrep '^Emacs$' > /dev/null || open -a Emacs.app
while ! [[ -S "$TMPDIR"/emacs"$(id -u)"/server ]]; do
    sleep 0.2
done
for file in "$@"; do
    # emacsclient might be /Applications/Emacs.app/Contents/MacOS/bin/emacsclient
    emacsclient -n -c "$file"
done

Emacs commands

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