compute/emacs-stuff.md
... ...
@@ -1,40 +1,27 @@
1 1
# Emacs Stuff
2 2
3
-### Make [Emacs](https://emacsformacosx.com/) work on OSX Catalina
4
-It's a bit of a mess. There's a security setting or something that nobody seems to be able to figure out, that stops Emacs opening files from Finder if it's already running.
3
+### Change the default text editor in MacOS
5 4
6
-To (hopefully temporarily) fix, and to make opening files faster anyway:
7
-
8
-Open up Automator from launchpad, New -> Application.
9
-Select Run Shell Script.
10
-Use `/bin/bash` as the shell from the dropdown, and pick `as arguments` in the 'Pass input' dropdown.
11
-Paste in the following:
12
-```
13
-if ! pgrep Emacs; then
14
- open -a Emacs.app "$1"
15
- sleep 1
16
- shift
17
-fi
18
-for f in "$@"; do
19
- /Applications/Emacs.app/Contents/MacOS/bin/emacsclient -c -n "$f"
20
-done
21 5
```
22
-and save it as 'Emacs-opener' or something in the Application folder. Use that app to open files instead of Emacs.app. Use the following as an emacs alias in your shell if you like:
23
-```
24
-emacs ()
25
-{
26
- open -a Emacs-opener.app "$@"
27
-}
6
+$ BUNDLE=$(osascript -e 'id of app "Emacs Client"') # or just "Emacs" if not using emacs-plus
7
+org.gnu.Emacs
8
+$ defaults write com.apple.LaunchServices/com.apple.launchservices.secure LSHandlers -array-add "{LSHandlerContentType=public.plain-text; LSHandlerRoleAll=$BUNDLE;}"
9
+<reboot>
28 10
```
29
-Finally, add `(start-server)` to your `~/.emacs`.
30
-
31
-### Change the default text editor in OSX
32 11
12
+### emacs shell command on MacOS
13
+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.
33 14
```
34
-$ osascript -e 'id of app "Emacs"'
35
-org.gnu.Emacs
36
-$ defaults write com.apple.LaunchServices/com.apple.launchservices.secure LSHandlers -array-add '{LSHandlerContentType=public.plain-text; LSHandlerRoleAll=org.gnu.Emacs;}'
37
-<reboot>
15
+#!/usr/bin/env bash
16
+
17
+pgrep '^Emacs$' > /dev/null || open -a Emacs.app
18
+while ! [[ -S "$TMPDIR"/emacs"$(id -u)"/server ]]; do
19
+ sleep 0.2
20
+done
21
+for file in "$@"; do
22
+ # emacsclient might be /Applications/Emacs.app/Contents/MacOS/bin/emacsclient
23
+ emacsclient -n -c "$file"
24
+done
38 25
```
39 26
40 27
### Emacs commands