86
|
1
|
(defun stumpwm-connect () |
|
2
|
"Start slime and connect to the lisp image that is running the |
|
3
|
swank server. Must have \"(require 'swank) |
|
4
|
(swank:create-server)\" in your .stumpwmrc " |
|
5
|
(interactive) |
|
6
|
(slime-connect "127.0.0.1" 4005) |
|
7
|
(with-current-buffer (current-buffer) |
|
8
|
(rename-buffer "*sbcl-stumpwm-repl*") |
|
9
|
(slime-eval '(in-package :stumpwm)))) |
|
10
|
|
|
11
|
(defun stumpwm-disconnect () |
|
12
|
"Disconnects from the swank server currently open." |
|
13
|
(with-current-buffer |
|
14
|
(switch-to-buffer "*sbcl-stumpwm-repl*") |
|
15
|
(slime-disconnect))) |
|
16
|
;;Lifted (with stylistic changes) from http://www.emacswiki.org/emacs/EmacsAsDaemon#toc9 |
|
17
|
(defun modified-buffers-exist () |
|
18
|
"This function will check to see if there are any buffers |
|
19
|
that have been modified. It will return true if there are |
|
20
|
and nil otherwise. Buffers that have buffer-offer-save set to |
|
21
|
nil are ignored." |
|
22
|
(let (modified-found) |
|
23
|
(dolist (buffer (buffer-list)) |
|
24
|
(when (and (buffer-live-p buffer) |
|
25
|
(buffer-modified-p buffer) |
|
26
|
(not (buffer-base-buffer buffer)) |
|
27
|
(or |
|
28
|
(buffer-file-name buffer) |
|
29
|
(progn |
|
30
|
(set-buffer buffer) |
|
31
|
(and buffer-offer-save (> (buffer-size) 0))))) |
|
32
|
(setq modified-found t))) |
|
33
|
modified-found)) |
|
34
|
|
|
35
|
(defun stumpwm-daemon-shutdown-emacs (&optional display) |
|
36
|
" This is a function that can bu used to shutdown save buffers and |
|
37
|
shutdown the emacs daemon. It should be called using |
|
38
|
emacsclient -e '(stumpwm-daemon-shutdown-emacs)'. This function will |
|
39
|
check to see if there are any modified buffers or active clients |
|
40
|
or frame. If so an x window will be opened and the user will |
|
41
|
be prompted." |
|
42
|
|
|
43
|
(let (new-frame modified-buffers active-clients-or-frames) |
|
44
|
; Check if there are modified buffers or active clients or frames. |
|
45
|
(setq modified-buffers (modified-buffers-exist)) |
|
46
|
(setq active-clients-or-frames ( or (> (length server-clients) 1) |
|
47
|
(> (length (frame-list)) 1))) |
|
48
|
; Create a new frame if prompts are needed. |
|
49
|
(when (or modified-buffers active-clients-or-frames) |
|
50
|
(when (not (eq window-system 'x)) |
|
51
|
(message "Initializing x windows system.") |
|
52
|
(x-initialize-window-system)) |
|
53
|
(when (not display) (setq display (getenv "DISPLAY"))) |
|
54
|
(message "Opening frame on display: %s" display) |
|
55
|
(select-frame (make-frame-on-display display '((window-system . x))))) |
|
56
|
; Save the current frame. |
|
57
|
(setq new-frame (selected-frame)) |
|
58
|
; When displaying the number of clients and frames: |
|
59
|
; subtract 1 from the clients for this client. |
|
60
|
; subtract 2 from the frames this frame (that we just created) and the default frame. |
|
61
|
(when ( or (not active-clients-or-frames) |
|
62
|
(yes-or-no-p (format "There are currently %d clients and %d frames. Exit anyway?" |
|
63
|
(- (length server-clients) 1) (- (length (frame-list)) 2)))) |
|
64
|
; If the user quits during the save dialog then don't exit emacs. |
|
65
|
; Still close the terminal though. |
|
66
|
(let((inhibit-quit t)) |
|
67
|
; Save buffers |
|
68
|
(with-local-quit |
|
69
|
(save-some-buffers)) |
|
70
|
(if quit-flag |
|
71
|
(setq quit-flag nil) |
|
72
|
; Kill all remaining clients |
|
73
|
(progn |
|
74
|
(dolist (client server-clients) |
|
75
|
(server-delete-client client)) |
|
76
|
; Exit emacs |
|
77
|
(kill-emacs))))) |
|
78
|
; If we made a frame then kill it. |
|
79
|
(when (or modified-buffers active-clients-or-frames) (delete-frame new-frame)))) |