Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add super-save layer that auto-saves buffers #4964

Closed
wants to merge 1 commit into from
Closed

Add super-save layer that auto-saves buffers #4964

wants to merge 1 commit into from

Conversation

mmainz
Copy link
Contributor

@mmainz mmainz commented Feb 4, 2016

This layer is inspired by Bozhidar Batsovs
super-save (https://github.com/bbatsov/super-save), but is adapted to
work with Spacemacs. Using the original package proved to be impractical
for integrating with Spacemacs, and since it is not a large package, the
functionality was reimplemented.
When you enable this layer, switching windows or Spacemacs losing focus
causes an automatic save to the current buffer.

I want to say I'm not very experienced in Emacs LISP, so if you see something weird in the code, it's probably because of that. Then again, there are only minor modifications to the original super-save code.

If for some reason you don't like to have this layer in the Spacemacs repository, no hard feelings. I can just put it in its own repository and use it from there. But I thought there might be other people like me that have forgotten how to save manually since using super-save :)

@robbyoconnor
Copy link
Contributor

Define your packages in packages-config.el

and initialize them in packages.el

I fixed the wizard but @syl20bnr is waiting a bit it seems

@robbyoconnor
Copy link
Contributor

See this example.

This layer is inspired by Bozhidar Batsovs
super-save (https://github.com/bbatsov/super-save), but is adapted to
work with Spacemacs. Using the original package proved to be impractical
for integrating with Spacemacs, and since it is not a large package, the
functionality was reimplemented.
When you enable this layer, switching windows or Spacemacs losing focus
causes an automatic save to the current buffer.
@mmainz
Copy link
Contributor Author

mmainz commented Feb 5, 2016

Thanks for the hint! I updated the PR. I amended the commit to satisfy the one commit rule.

@robbyoconnor
Copy link
Contributor

👍

@syl20bnr syl20bnr self-assigned this Feb 15, 2016
@thimios
Copy link

thimios commented Mar 18, 2016

👍

@robbyoconnor
Copy link
Contributor

What is the difference between this and what we currently have?

@joehillen
Copy link
Contributor

@robbyoconnor Spacemacs currently doesn't save the file if the buffer loses focus. That would be nice to have. It would save me a lot of mistaken compiles.

@robbyoconnor
Copy link
Contributor

Oh nevermind :)

@sirech
Copy link

sirech commented Apr 15, 2016

I come from prelude, and would love to have this layer in as well. I am not used to saving stuff manually anymore 👍

@joehillen
Copy link
Contributor

@sirech Please 👍 the PR. The maintainers looks that those numbers.

@syl20bnr
Copy link
Owner

syl20bnr commented Jun 6, 2016

@mmainz Thank you for the PR, it is on the top of my queue of PR to merge but first I want to know why the original package does not play well with Spacemacs, what issues did you fix with your own implementation ?

@mmainz
Copy link
Contributor Author

mmainz commented Jun 8, 2016

@syl20bnr I honestly forgot what the problem was :)
I'd have to check again. Maybe the original problem I tried to circumvent doesn't exist anymore, since super-save has been updated since I made this PR as well. I could try again to use the package instead once I find some time, but I'm currently busy moving, so it might take a while.

@syl20bnr
Copy link
Owner

syl20bnr commented Jun 9, 2016

@mmainz thank you for the answer, I will just merge this PR and check for you how we can improve it.

@zhengpd
Copy link

zhengpd commented Aug 29, 2016

Any update on this? It would be nice to auto save buffer when losing focus.

@sirech
Copy link

sirech commented Apr 4, 2017

This PR broke with the update to 0.200.8, as it relies on window-numbering, whereas winum is used by spacemacs now. I fixed it this way:

--- a/layers/super-save/packages.el
+++ b/layers/super-save/packages.el
@@ -10,7 +10,7 @@
 ;;; License: GPLv3

 (defconst super-save-packages
-  '(window-numbering))
+  '(winum))

 (defgroup super-save nil
   "Smart-saving of buffers."
Stage this hunk [y,n,q,a,d,/,j,J,g,e,?]? y
@@ -29,17 +29,17 @@
     "evil-window-down"
     "evil-window-left"
     "evil-window-right"
-    "select-window-by-number"
-    "select-window-0"
-    "select-window-1"
-    "select-window-2"
-    "select-window-3"
-    "select-window-4"
-    "select-window-5"
-    "select-window-6"
-    "select-window-7"
-    "select-window-8"
-    "select-window-9")
+    "winum-select-window-by-number"
+    "winum-select-window-0"
+    "winum-select-window-1"
+    "winum-select-window-2"
+    "winum-select-window-3"
+    "winum-select-window-4"
+    "winum-select-window-5"
+    "winum-select-window-6"
+    "winum-select-window-7"
+    "winum-select-window-8"
+    "winum-select-window-9")
   "A list of commands which would trigger `super-save-command'."
   :group 'super-save
   :type '(repeat string))
Stage this hunk [y,n,q,a,d,/,K,j,J,g,e,?]? y
@@ -87,7 +87,7 @@
    (super-save-mode (super-save-initialize))
    (t (super-save-stop))))

-(defun super-save/post-init-window-numbering ()
+(defun super-save/post-init-winum ()
   (super-save-mode +1))

 ;;; packages.el ends here

I guess it could be debatable whether waiting for winum to load is a good trigger of the package, or something else could be more reliable

@xged
Copy link

xged commented May 19, 2017

(defadvice switch-to-buffer (before save-buffer-now activate)
  (when buffer-file-name (save-buffer)))
(defadvice other-window (before other-window-now activate)
  (when buffer-file-name (save-buffer)))

The above snippet auto-saves upon every spacemacs/evil-mc-paste-after (p), which is bad. Will it not be the case with this layer?

@syl20bnr syl20bnr removed their assignment May 22, 2017
@delaanthonio
Copy link
Contributor

Why not add super-save to the Spacemacs distribution?

@Compro-Prasad
Copy link
Contributor

@mmainz Are you still on this?

@mmainz mmainz closed this Mar 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.