-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup.sh
155 lines (137 loc) · 4.58 KB
/
setup.sh
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/bin/sh
# launch emacs without waiting in terminal
emacs_launch() {
# https://superuser.com/questions/358037/emacsclient-create-a-frame-if-a-frame-does-not-exist
# https://www.reddit.com/r/emacs/comments/8iq4ho/how_make_emacsclient_create_gui_frame_by_default/
# https://medium.com/@bobbypriambodo/blazingly-fast-spacemacs-with-persistent-server-92260f2118b7
# https://gist.github.com/alexmurray/337ac19014d769f4b219
# https://news.ycombinator.com/item?id=9395056
# https://emacs.stackexchange.com/questions/13485/something-like-delete-frame-but-that-would-also-delete-the-last-frame-like-al
# (visible-frame-list) v.s. (frame-list)
# emacsclient options for reference
# -a : alternative editior
# -c : create-frame
# -n : no-wait, return immediately, returns control back to the terminal
# -t : terminal
# -q : quite
# -e : eval the script
# -a "" : starts emacs daemon and reattaches
# NOTE:
# Emacs daemon always has a visible frame called F1
# TODO:
# Should start emacs "*scratch*" buffer or bring most recent frame into focus
# if no arguments is specified
emacsclient -n -e "(if (> (length (frame-list)) 1) 't)" | grep t 1>/dev/null 2>/dev/null
if [ "$?" = "1" ]; then
# if frame not exists, create new frame
new_frame_flag=-c
else
new_frame_flag=
fi
if [ "$DISPLAY" != "" ]; then
# dont wait on gui mode, just return immediately
wait_flag=-n
else
wait_flag=
fi
# NOTE:
# (select-frame-set-input-focus (selected-frame)) ;; raise frame and set input focus
# (other-frame 0) ;; raise frame and set input focus
# (raise-frame) ;; raise frame only
# (switch-to-buffer "*scratch*") ;; switch to scratch buffer
# (toggle-frame-fullscreen) ;; to fullscreen
# FIXME:
# In gnome3 app is not allowed to steal focus,
# and therefore (raise-window) has no effect,
# gotta find a way to enable this in this environment.
# TODO:
# Make a another version of emacs_launch that doesn't steal user's focus.
# if no file argument is given,
# create new frame or open existing frame, and set focus to that frame.
if [ -z ${@} ]; then
emacsclient ${new_frame_flag} ${wait_flag} -a "" -e '(select-frame-set-input-focus (selected-frame))'
else
emacsclient ${new_frame_flag} ${wait_flag} -a "" "${@}"
fi
}
emacs_run() {
# https://superuser.com/questions/358037/emacsclient-create-a-frame-if-a-frame-does-not-exist
# https://www.reddit.com/r/emacs/comments/8iq4ho/how_make_emacsclient_create_gui_frame_by_default/
# https://medium.com/@bobbypriambodo/blazingly-fast-spacemacs-with-persistent-server-92260f2118b7
# https://gist.github.com/alexmurray/337ac19014d769f4b219
# (visible-frame-list) v.s. (frame-list)
# emacsclient options for reference
# -a : alternative editior
# -c : create-frame
# -n : no-wait, return immediately, returns control back to the terminal
# -t : terminal
# -q : quite
# -e : eval the script
# -a "" : starts emacs daemon and reattaches
# NOTE:
# Emacs daemon always has a visible frame called F1
emacsclient -n -e "(if (> (length (frame-list)) 1) 't)" | grep t 1>/dev/null 2>/dev/null
# if frame not exists
if [ "$?" = "1" ]; then
emacsclient -c -a "" "${@}"
else
emacsclient -a "" "${@}"
fi
}
# emacsclient terminal
emacs_terminal() {
emacsclient -t -a "" "${@}"
}
# emacsclient gui
emacs_gui() {
emacsclient -c -a "" "${@}"
}
# emacsclient gui
emacs_gui_launch() {
emacsclient -c -n -a "" "${@}"
}
# save and kill
# write and quit
emacs_write_and_quit() {
emacsclient -e '(save-buffers-kill-emacs)' "${@}"
}
# quit
emacs_quit() {
emacsclient -e '(kill-emacs)' "${@}"
}
# predicate
emacs_predicate() {
# emacsclient -ca false -e '(delete-frame)'
emacsclient -q -a false -e t 1>/dev/null 2>/dev/null
}
# start or restart daemon
emacs_server() {
emacs_predicate || emacs --daemon "${@}"
}
# start emacs daemon in foreground
emacs_daemon() {
# TODO:
# Wait on daemon while there is already one.
# Maybe exit the daemon while this program is terminated.
emacs_predicate || emacs --fg-daemon "${@}"
}
emacs_restart() {
emacsclient -e '(restart-emacs)' -a "" "${@}"
}
emacs_vim() {
vi "${@}"
}
emacs_vi() {
vi "${@}"
}
alias e=emacs_launch
alias ee=emacs_run
alias et=emacs_terminal
alias eg=emacs_gui
alias es=emacs_server
alias er=emacs_restart
alias eq=emacs_quit
alias ep=emacs_predicate
alias ewq=emacs_write_and_quit
alias evi=emacs_vi
alias evim=emacs_vim