Automatically saves all open file buffers or anything else when gnu Emacs loses focus under x.
123456789101112131415161718192021222324
(when(and(featurep'x)window-system)(defvaron-blur--saved-window-id0"Last known focused window.")(defvaron-blur--timernil"Timer refreshing known focused window.")(defunon-blur--refresh()"Runs on-blur-hook if emacs has lost focus."(let*((active-window(x-window-property"_NET_ACTIVE_WINDOW"nil"WINDOW"0nilt))(active-window-id(if(numberpactive-window)active-window(string-to-number(format"%x00%x"(caractive-window)(cdractive-window))16)))(emacs-window-id(string-to-number(frame-parameternil'outer-window-id))))(when(and(=emacs-window-idon-blur--saved-window-id)(not(=active-window-idon-blur--saved-window-id)))(run-hooks'on-blur-hook))(setqon-blur--saved-window-idactive-window-id)(run-with-timer1nil'on-blur--refresh)))(add-hook'on-blur-hook#'(lambda()(save-some-bufferst)))(on-blur--refresh))