forked from crazycode/reload-emacs.d
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
81 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
(defun client-save-kill-emacs(&optional display) | ||
" This is a function that can bu used to shutdown save buffers and | ||
shutdown the emacs daemon. It should be called using | ||
emacsclient -e '(client-save-kill-emacs)'. This function will | ||
check to see if there are any modified buffers or active clients | ||
or frame. If so an x window will be opened and the user will | ||
be prompted." | ||
|
||
(let (new-frame modified-buffers active-clients-or-frames) | ||
|
||
; if there are modified buffers or active clients or frames. | ||
(setq modified-buffers (modified-buffers-exist)) | ||
(setq active-clients-or-frames ( or (> (length server-clients) 1) | ||
(> (length (frame-list)) 1) | ||
)) | ||
|
||
; Create a new frame if prompts are needed. | ||
(when (or modified-buffers active-clients-or-frames) | ||
(when (not (eq window-system 'x)) | ||
(message "Initializing x windows system.") | ||
(x-initialize-window-system)) | ||
(when (not display) (setq display (getenv "DISPLAY"))) | ||
(message "Opening frame on display: %s" display) | ||
(select-frame (make-frame-on-display display '((window-system . x))))) | ||
|
||
; Save the current frame. | ||
(setq new-frame (selected-frame)) | ||
|
||
|
||
; When displaying the number of clients and frames: | ||
; subtract 1 from the clients for this client. | ||
; subtract 2 from the frames this frame (that we just created) and the default frame. | ||
(when ( or (not active-clients-or-frames) | ||
(yes-or-no-p (format "There are currently %d clients and %d frames. Exit anyway?" (- (length server-clients) 1) (- (length (frame-list)) 2)))) | ||
|
||
; If the user quits during the save dialog then don't exit emacs. | ||
; Still close the terminal though. | ||
(let((inhibit-quit t)) | ||
; Save buffers | ||
(with-local-quit | ||
(save-some-buffers)) | ||
|
||
(if quit-flag | ||
(setq quit-flag nil) | ||
; Kill all remaining clients | ||
(progn | ||
(dolist (client server-clients) | ||
(server-delete-client client)) | ||
; Exit emacs | ||
(kill-emacs))) | ||
)) | ||
|
||
; If we made a frame then kill it. | ||
(when (or modified-buffers active-clients-or-frames) (delete-frame new-frame)) | ||
) | ||
) | ||
|
||
|
||
(defun modified-buffers-exist() | ||
"This function will check to see if there are any buffers | ||
that have been modified. It will return true if there are | ||
and nil otherwise. Buffers that have buffer-offer-save set to | ||
nil are ignored." | ||
(let (modified-found) | ||
(dolist (buffer (buffer-list)) | ||
(when (and (buffer-live-p buffer) | ||
(buffer-modified-p buffer) | ||
(not (buffer-base-buffer buffer)) | ||
(or | ||
(buffer-file-name buffer) | ||
(progn | ||
(set-buffer buffer) | ||
(and buffer-offer-save (> (buffer-size) 0)))) | ||
) | ||
(setq modified-found t) | ||
) | ||
) | ||
modified-found | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters