Skip to content

Instantly share code, notes, and snippets.

@lionicsheriff
Last active January 29, 2016 12:02
Show Gist options
  • Save lionicsheriff/44d50e8805dcd05dd3dc to your computer and use it in GitHub Desktop.
Save lionicsheriff/44d50e8805dcd05dd3dc to your computer and use it in GitHub Desktop.
;(use-package noflet :ensure t)
(provide 'auto-recover-mode)
(define-minor-mode auto-recover-mode
"more documentation"
:global t
(if auto-recover-mode
(progn
(advice-add 'after-find-file :around #'auto-recover-mode/after-find-file-no-warn)
(advice-add 'recover-this-file :around #'auto-recover-mode/always-yes)
(add-hook 'find-file-hook 'auto-recover-mode/always-recover-autosave-file))
(progn
(advice-remove 'after-find-file :around #'auto-recover-mode/after-find-file-no-warn)
(advice-remove 'recover-this-file #'auto-recover-mode/always-yes)
(remove-hook 'find-file-hook 'auto-recover-mode/always-recover-autosave-file))))
(defun auto-recover-mode/always-yes (function &rest args)
""
(require 'noflet)
(noflet
((y-or-n-p (prompt) t)
(yes-or-no-p (prompt) t))
(apply function args)))
(defun auto-recover-mode/after-find-file-no-warn (original-function &rest args)
""
(and (>= (list-length args) 2)
(setf (nth 1 args) nil))
(apply original-function args))
(defun auto-recover-mode/always-recover-autosave-file ()
""
(condition-case err (recover-this-file) (error nil)))
(provide 'hot-exit-mode)
(define-minor-mode hot-exit-mode
"Toggle session-thing.
Blah blah blah documentation"
:global t
(if hot-exit-mode
(progn
(fset 'save-buffers-kill-emacs 'hot-exit-mode/dont-save-buffers-kill-emacs))
(progn
(fset 'save-buffers-kill-emacs 'hot-exit-mode/original/save-buffer-kill-emacs))))
(defvar hot-exit-mode/original/save-buffer-kill-emacs (symbol-function 'save-buffer-kill-emacs))
(defun hot-exit-mode/dont-save-buffers-kill-emacs (&optional arg)
"Kill this Emacs process without offering to save buffers"
(interactive "P")
(and (or (not (fboundp 'process-list))
;; process-list is not defined on MSDOS.
(let ((processes (process-list))
active)
(while processes
(and (memq (process-status (car processes)) '(run stop open listen))
(process-query-on-exit-flag (car processes))
(setq active t))
(setq processes (cdr processes)))
(or (not active)
(progn (list-processes t)
(yes-or-no-p "Active processes exist; kill them and exit anyway? ")))))
;; Query the user for other things, perhaps.
(run-hook-with-args-until-failure 'kill-emacs-query-functions)
(or (null confirm-kill-emacs)
(funcall confirm-kill-emacs "Really exit Emacs? "))
(kill-emacs)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment