-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswitch-emacs-eval
executable file
·48 lines (36 loc) · 1.04 KB
/
switch-emacs-eval
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
me=`basename $0`
log () {
echo "`date` $me: $*" >> ~/.log/$me.log 2>&1
}
if [ -z "$DISPLAY" ]; then
echo "$me: Need \$DISPLAY set for $me to work; aborting." >&2
sleep 1 # ensure we see the message if we're in mutt
exit 1
fi
if ! fast-X11-display; then
# switch-feed-emacs seems to care about this scenario, but
# I can't remember why.
: No fast X11 display
exit 1
fi
: Assume we already have an emacs running. We could alternatively
: use quick-emacs at this point.
xdotool set_desktop 0 # prefer first desktop
focus-emacs-frame || exit $?
log "`current-window-id` / `current-window-name`"
code="$1"
shift
if [ -f "$code" ]; then
echo >&2 "Will eval file $code"
code="(load \"$code\")"
fi
if [[ $# -gt 0 ]]; then
# Escape double quotes
escaped_args=("${@//\"/\\\"}")
# Surround each arg with double quotes
quoted_args=("${escaped_args[@]/#*/\"&\"}")
code="(progn (setq emacsclient-args '(${quoted_args[@]})) $code)"
fi
log "$code"
emacsclient --quiet --no-wait --eval "$code"