Emacs: Add test-emacs to kill-emacs-query-functions

master
Pierre Neidhardt 2019-01-29 10:38:50 +01:00
parent 6fb97bfcb3
commit a11427e0d6
1 changed files with 28 additions and 0 deletions

View File

@ -309,6 +309,34 @@ Works on whole buffer if region is unactive."
(tabify start end))
(setq tabify-regexp tabify-regexp-old))))
;; Inspired by https://github.com/abo-abo/oremacs.git.
(defun ambrevar/test-emacs ()
"Return nil on error, t on success so that it can be added to
`kill-emacs-query-functions'."
(interactive)
(let ((output
(shell-command-to-string
(format "emacs --batch --eval \"
(condition-case e
(progn
(load \\\"%s\\\")
(message \\\"-OK-\\\"))
(error
(message \\\"ERROR:\\\")
(signal (car e) (cdr e))))\""
user-init-file))))
(if (string-match "-OK-" output)
(progn
(when (called-interactively-p 'any)
(message "All is well"))
t)
(switch-to-buffer-other-window "*init file error*")
(erase-buffer)
(insert output)
(search-backward "ERROR:")
nil)))
(add-hook 'kill-emacs-query-functions 'ambrevar/test-emacs)
;;; TODO: Store window configurations in a buffer-name-indexed alist? Not
;;; sure that would ever be useful.
(defvar single-window--last-configuration nil "Last window configuration before calling `delete-other-windows'.")