[enhancement] provide option to auto-save all buffers when saving
I used another package which saves all file-visiting buffers when idle, now I'm switching to super-save because the focus-out-hook style works better with file watchers, e.g. web front-end transpilers. Meanwhile, I really miss the save-all-buffers feature. Would be nice to have an option to enable this, though it looks easily achievable by modifying super-save-command myself.
Here is the code to save all buffers I used, should you be interested: https://github.com/manateelazycat/lazycat-emacs/blob/ce87fb97286a187b66355a587a4230dea01d0de5/site-lisp/extensions/lazycat/auto-save.el#L120
That'd be trivial to add. We can just add something similar to the auto-save for a single file as shown here https://github.com/bbatsov/super-save/blob/master/super-save.el#L103
That being said I don't quite get the need for such a command - if you're already super-saving everything why would need a command that periodically saves all buffers? Usually the only buffer that can potentially be unsaved is the current one.
Sorry, I thought mouse-leave-buffer-hook only works when actually using the mouse, so I removed it from the super-save-hook-triggers. Adding it back makes "the only buffer potentially unsaved is the current one" true.
However I also found some problem with mouse-leave-buffer-hook: switch-to-buffer and other-window do trigger it, but neither winum-select-window-1 nor spacemacs/alternate-window triggers it, which I use more often when switching windows. Their definitions are as follows:
(defun spacemacs/alternate-window ()
"Switch back and forth between current and last window in the
current frame."
(interactive)
(let (;; switch to first window previously shown in this frame
(prev-window (get-mru-window nil t t)))
;; Check window was not found successfully
(unless prev-window (user-error "Last window not found."))
(select-window prev-window)))
(defun winum--switch-to-window (window)
"Switch to the window WINDOW and switch input focus if on a different frame."
(let ((frame (window-frame window)))
(when (and (frame-live-p frame)
(not (eq frame (selected-frame))))
(select-frame-set-input-focus frame))
(if (window-live-p window)
(select-window window)
(error "Got a dead window %S" window))))
As of the save-all-buffers feature, it makes file watchers trigger less constantly, reducing cpu/power use. Also I sometimes look at the file-saved indicator in mode-line to see "haved I undo-ed to last save?", so I want the saving happen when I switch to the browser, "I'm certain about the last few edits now, save them and see how the web page looks now". But sure, these aren't common needs and sound a bit paranoid. I'll think again and implement it myself or just ditch the idea.
@JJPandari @bbatsov I've implemented this feature, it will be optional and closed by default, see https://github.com/bbatsov/super-save/pull/20
@bbatsov I've implemented but not pushed this feature (to save all buffers). I found out that @cireu have already implemented it.
I can confirm that having an option to save all buffers can be interesting, specially when doing indirect buffer edits (like when editing greps with occur-mode and occur-edit-mode, or when running a project-wide search and replace project-query-replace-regexp, etc.). In these cases, we can indirectly edit several buffers without actually visiting or switching to these buffers.
I've implemented the feature (which defaults to nil, so I would keep the current workflow intact) in the new code base. I can open a PR or add it to the currently opened one.
Thanks again for this package.