Code Monkey home page Code Monkey logo

super-save's Introduction

License GPL 3 MELPA MELPA Stable Build Status

super-save

super-save auto-saves your buffers, when certain events happen - e.g. you switch between buffers, an Emacs frame loses focus, etc. You can think of it as both something that augments and replaces the standard auto-save-mode.

Installation

Available on all major package.el community maintained repos - MELPA Stable and MELPA repos.

MELPA Stable is recommended as it has the latest stable version. MELPA has a development snapshot for users who don't mind breakage but don't want to run from a git checkout.

You can install super-save using the following command:

M-x package-install [RET] super-save [RET]

or if you'd rather keep it in your dotfiles:

(unless (package-installed-p 'super-save)
  (package-refresh-contents)
  (package-install 'super-save))

If the installation doesn't work try refreshing the package list:

M-x package-refresh-contents

use-package

If you're into use-package you can use the following snippet:

(use-package super-save
  :ensure t
  :config
  (super-save-mode +1))

Emacs Prelude

super-save started its life as the extraction of a similar functionality I had originally developed for Emacs Prelude and the package is bundled with Prelude.

Usage

Add the following to your Emacs config to enable super-save:

(super-save-mode +1)

If you want to enable the additional feature of auto-saving buffers when Emacs is idle, add the following as well:

(setq super-save-auto-save-when-idle t)

At this point you can probably switch off the built-in auto-save-mode (unless you really care about its backups):

(setq auto-save-default nil)

Configuration

super-save will save files on command (e.g. switch-to-buffer) and hook triggers (e.g. focus-out-hook).

Both of those are configurable via super-save-triggers and super-save-hook-triggers. Here's a couple of examples:

;; add integration with ace-window
(add-to-list 'super-save-triggers 'ace-window)

;; save on find-file
(add-to-list 'super-save-hook-triggers 'find-file-hook)

You can turn off super-save for remote files like this:

(setq super-save-remote-files nil)

Sometimes you might want to exclude specific files from super-save. You can achieve this via super-save-exclude, for example:

(setq super-save-exclude '(".gpg"))

You can add predicate to super-save-predicates, this predicates must not take arguments and return nil, when current buffer shouldn't save. If predicate don't know needle of save file, then predicate must return t. Following example stop super-save, when current file in Markdown mode:

(add-to-list 'super-save-predicates (lambda ()
                                        (not (eq major-mode 'markdown-mode))))

When saving a file automatically, Emacs will display a message in the *Messages* buffer and in the echo area. If you want to suppress these messages, you can set super-save-silent to t.

;; Save silently
(setq super-save-silent t)

The super-save-delete-trailing-whitespace variable can be used to enable deleting trailing white spaces before saving (via Emacs' delete-trailing-whitespace).

;; Enable deleting trailing white spaces before saving
(setq super-save-delete-trailing-whitespace t)

;; Enable deleting trailing white spaces before saving (except for the current line)
(setq super-save-delete-trailing-whitespace 'except-current-line)

By default, super-save will automatically save only the current buffer, if you want to save all open buffers you can set super-save-all-buffers to t.

Setting this to t can be interesting when you make indirect buffer edits, like when editing greps results with occur-mode and occur-edit-mode, or when running a project-wide search and replace with project-query-replace-regexp and so on. In these cases, we can indirectly edit several buffers without actually visiting or switching to these buffers. Hence, this option allow to automatically save these buffers, even when they aren't visible in any window.

License

Copyright © 2015-2023 Bozhidar Batsov and contributors.

Distributed under the GNU General Public License; type C-h C-c to view it.

super-save's People

Contributors

abougouffa avatar bbatsov avatar grammati avatar marcwebbie avatar semeninrussia avatar swananddhawan avatar tejasbubane avatar wilfred avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

super-save's Issues

Tag a v0.1

Add a tag so that we get one on melpa.stable :)

(maybe after adding the autoload cookies cf #1)

Impossible to disable `super-save-mode`

My Environment

Issue

M-x super-save-mode has no effect in any buffer: it just keeps saving no matter what. To disable it, I need to change my configurations and reboot. Evaluating (super-save-mode +1) or (setq super-save-mode nil) has absolutely no effect.

This is my use-package declaration for super-save:

(use-package super-save
  :defer nil
  :ensure t
  :config
  (setq auto-save-default nil
        auto-save-file-name-transforms `((".*" "~/.emacs.d/var/temp" t))
        auto-save-interval 300
        auto-save-timeout 30
        auto-save-visited-mode t
        super-save-exclude '(".py")
        super-save-auto-save-when-idle t
        super-save-idle-duration 1
        super-save-triggers
        '(balance-windows
          evil-window-next
          evil-window-prev
          eyebrowse-close-window-config
          eyebrowse-create-window-config
          my/no-highlight
          eyebrowse-next-window-config
          eyebrowse-prev-window-config
          eyebrowse-switch-to-window-config-1
          eyebrowse-switch-to-window-config-2
          eyebrowse-switch-to-window-config-3
          eyebrowse-switch-to-window-config-4
          eyebrowse-switch-to-window-config-5
          eyebrowse-switch-to-window-config-6
          eyebrowse-switch-to-window-config-7
          eyebrowse-switch-to-window-config-8
          eyebrowse-switch-to-window-config-9
          next-buffer
          org-babel-execute-src-block
          other-window
          previous-buffer
          split-window-below
          split-window-horizontally
          start-process-shell-command
          switch-to-buffer
          treemacs-select-window
          windmove-down
          windmove-left
          windmove-right
          windmove-up))

  (super-save-mode +1))

bypass save hooks

would it be possible for super-save to not trigger save hooks — reserving those for when a file is manually saved?

for my specific use-case, i'm using org-roam which binds:

(add-hook 'after-save-hook #'org-roam-db-autosync--try-update-on-save-h nil t)

the db autosync is cpu intensive so there's a periodic bit of a lag when i have super-save-auto-save-when-idle turned on (which I would like to keep).

is there a way i can adjust the org-roam hook and/or configure super-save to make the two mutually exclusive?

Any workarounds for using super-save along with lv-message?

I'm running into an issue with lsp-mode which is described in emacs-lsp/lsp-mode#1322. lsp-mode uses lv-message instead of message to print some information, and this seems to trigger saving with super-save. I don't want to disable any super-save triggers, so I'm wondering if there's any good way to work around this issue (i.e. is it possible to detect if certain functions resulted in the trigger and ignore it in some cases?).

I've currently worked around this issue in lsp-mode by adding (setq lsp-signature-function 'message) to my config file. But I'd prefer to remove this in the future so I can get the default lv-message functionality.

Can't use default spacemacs shortcuts to change windows

Hi @bbatsov.
First of all, thank you for this awesome plugin.
I'm using spacemacs and after installing super-save i can't change windows using the default shortcuts.
I get the following error when i press SPC w h(Move to window on the left) or SPC w l(Move to window on the right):

Debugger entered--Lisp error: (wrong-number-of-arguments (1 . &rest) 0) super-save-command-advice() apply(super-save-command-advice nil) windmove-right() evil-window-right(1) call-interactively(evil-window-right nil nil) command-execute(evil-window-right)

I tried some workarounds but none of them worked.
Do you have any ideia of what is causing this?

Thank you very much.

Can super-save save silently?

Runtime Environment

  • MX Linux 17
  • GNU Emacs 27.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.11)
    of 2018-11-28
  • Evil version 1.2.13
  • .emacs.d
  • packages
  • super-save-20180929.727/

Since I already have a modification indicator in the modeline, I'd like to hide the saving messages in the echo area.

Save when idle not working?

Is the super-save package also intended to work in non-GUI Emacs (terminal) when using the idle option?

I followed the installation instructions, including refreshing the packages.

Added the following to my init.el:

 (add-to-list 'load-path "~/.emacs.d/elpa/super-save-20160426.729")
 (require 'super-save)
 (super-save-mode +1)
 (setq super-save-auto-save-when-idle t)

When switching buffers it saves, but when the default 5 seconds of idle time passed, it never saves buffers.

Any help would be appreciated.

Diego.

Usage of (save-excursion) SF interferes with format-on-save configuration in Clojure/Cider setups

This is technically not a bug in super-save but rather an oddity of (save-excursion), but in my Prelude setup it's coming from super-save so I am wondering if it's possible to tinker with super-save to work around it.

Expected behavior

When triggering super-save hooks with a format-on-save hook ((add-hook 'before-save-hook 'cider-format-buffer) in init.el), the file should format and the cursor should stay in its appropriate place, just like it stays there when you run cider-format-buffer or basic-buffer-save without super-save

Actual behavior

Triggering the super-save hook (e.g., navigating to a different application) saves and formats the document, but the cursor yeets to the beginning of the buffer

Steps to reproduce the problem

  1. Install and setup super-save as per the instructions (or by installing Prelude), and add focus-out to the trigger list
  2. Add (add-hook 'before-save-hook 'cider-format-buffer) to init.el to format on save
  3. Test by manually saving and see that the format hook runs
  4. Test the described behavior by navigating to a different application and returning
  5. The cursor should be at the beginning of the buffer

Environment & Version information

super-save version

Version: 20231209.1044

Emacs version

29.1

Operating system

macOS Sonoma 14.1.2

Replace advises with hooks?

Currently super-save advises a couple of Emacs functions to catch buffer switching, but I think we could replace these advises with two hooks:

  • window-configuration-change-hook: This hook will trigger—among other things—when a window gets to display a different buffer, i.e. if the user switches to a different buffer within the current window. This would replace the switch-to-buffer advise.
  • buffer-list-update-hook: This hook triggers whenever the buffer list changes, which occurs—among other things–upon calls to select-window, i.e. when the user switches to a different window.

Empty .gz files sometimes

GNU Emacs 26.1, macOS/Ubuntu

When I open some emacs lib files (.el.gz), super-save may empty the file contents sometimes.

Evaluating "super-save-exclude" doesn't seem to work

My Environment

Issue

I have the following to prevent super-save from working on Python files:

(setq super-save-exclude '(".py"))

But it does not work, super-save remain active. In fact, super-save seems to remain active in all modes, in all circumstances, even after I hit M-x super-save-mode. Altering super-save-duration requires a full reboot (I use emacsclient).

This is my use-package declaration for super-save:

(use-package super-save
  :defer nil
  :ensure t
  :config

  (setq auto-save-default nil
        auto-save-file-name-transforms `((".*" "~/.emacs.d/var/temp" t))
        auto-save-interval 300
        auto-save-timeout 30
        auto-save-visited-mode t
        super-save-exclude '(".py")
        super-save-auto-save-when-idle t
        super-save-idle-duration 1
        super-save-triggers
        '(balance-windows
          evil-window-next
          evil-window-prev
          eyebrowse-close-window-config
          eyebrowse-create-window-config
          my/no-highlight
          eyebrowse-next-window-config
          eyebrowse-prev-window-config
          eyebrowse-switch-to-window-config-1
          eyebrowse-switch-to-window-config-2
          eyebrowse-switch-to-window-config-3
          eyebrowse-switch-to-window-config-4
          eyebrowse-switch-to-window-config-5
          eyebrowse-switch-to-window-config-6
          eyebrowse-switch-to-window-config-7
          eyebrowse-switch-to-window-config-8
          eyebrowse-switch-to-window-config-9
          next-buffer
          org-babel-execute-src-block
          other-window
          previous-buffer
          split-window-below
          split-window-horizontally
          start-process-shell-command
          switch-to-buffer
          treemacs-select-window
          windmove-down
          windmove-left
          windmove-right
          windmove-up))

  (super-save-mode +1))

[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

Can I have different values for "super-save-idle-duration" according to mode?

Runtime Environment

  • MX Linux 18
  • dotfiles
  • GNU Emacs 27.0.50
  • Org mode version 9.2.3
  • Evil version 1.2.14
  • ~/.emacs.d
  • super-save 20180929.727

Issue

I'm unable to do it in this way:

(defun my/set-save ()
  (interactive)
  (setq super-save-idle-duration 2))
(add-hook 'web-mode-hook 'my/web-mode-hooks)

Even though the variable is actually set, is has no effect on the saving behavior. setq-local doesn't work either.

That's my use-package for super-save:

(use-package super-save
  :ensure t
  :config

  (setq super-save-triggers
        '(switch-to-buffer
          other-window
          windmove-up
          windmove-down
          windmove-left
          windmove-right
          next-buffer
          previous-buffer
          evil-window-prev
          evil-window-next
          eyebrowse-next-window-config
          eyebrowse-prev-window-config
          eyebrowse-create-window-config))

  (setq super-save-auto-save-when-idle t)

  (setq auto-save-default nil)
  (super-save-mode +1))

org-mode capture prevents saving when emacs looses focus

I found this problem out at the worst possible way: writing a long text over a period of time and having emacs to crash when exiting the capture frame with C-c C-c. While writing, I kept changing focus between a PDF and the capture buffer. The file was never saved.

I've just tested it and the buffer the org capture is adding text to never gets saved unless I explicitly move focus to the main buffer.

The capture template I am using should not have anything special in it: ("n" "note" entry (file+olp+datetree "~/Dropbox/org/reference.org") "* %?\n :PROPERTIES:\n :CREATED: %U\n :END: \n%i")

Is there a way to get super-save respond to the org-mode capture buffer losing focus?

super-save disable when file header is present.

Hi
while using org-crypt and when super-save is enabled the entries in org-mode file gets encrypted every time based on super-save settings/triggers. As I have (org-crypt-use-before-save-magic) turned on.

For auto-save we have header like:

-- buffer-auto-save-file-name: nil; --

which will disable auto-save for the particular file worked on.

How can we achieve the same with super-save? i.e disable super-save for just the file working on.
tips and pointers appreciated. thanks.

ow mode

Sorry, this issue was created in error, please delete it!

Changing "super-save-idle-duration" has no effect unless I reboot

My Environment

Issue

Setting and evaluating super-save-idle-duration to any value has no effect whatsoever. The only way to change it is to reboot Emacs completely. It is also not possible to use setq-local to set different values for different modes.

This is my use-package declaration for super-save:

(use-package super-save
  :defer nil
  :ensure t
  :config
  (setq auto-save-default nil
        auto-save-file-name-transforms `((".*" "~/.emacs.d/var/temp" t))
        auto-save-interval 300
        auto-save-timeout 30
        auto-save-visited-mode t
        super-save-exclude '(".py")
        super-save-auto-save-when-idle t
        super-save-idle-duration 1
        super-save-triggers
        '(balance-windows
          evil-window-next
          evil-window-prev
          eyebrowse-close-window-config
          eyebrowse-create-window-config
          my/no-highlight
          eyebrowse-next-window-config
          eyebrowse-prev-window-config
          eyebrowse-switch-to-window-config-1
          eyebrowse-switch-to-window-config-2
          eyebrowse-switch-to-window-config-3
          eyebrowse-switch-to-window-config-4
          eyebrowse-switch-to-window-config-5
          eyebrowse-switch-to-window-config-6
          eyebrowse-switch-to-window-config-7
          eyebrowse-switch-to-window-config-8
          eyebrowse-switch-to-window-config-9
          next-buffer
          org-babel-execute-src-block
          other-window
          previous-buffer
          split-window-below
          split-window-horizontally
          start-process-shell-command
          switch-to-buffer
          treemacs-select-window
          windmove-down
          windmove-left
          windmove-right
          windmove-up))

  (super-save-mode +1))

not working in org-mode (doom-emacs)

Tested with this config:

(use-package! super-save
  :ensure t
  :config
  (super-save-mode +1))

(setq super-save-auto-save-when-idle t)

Works with .md files just fine, but .org files not unfortunately... Was testing windmove-left/right and out of focus events, all the same though.

Thought at first this has something to do with the triggering event but I tried all kinds of stuff, reinstallation and other peoples config.

Also tried removing all other packages and configs, so my doom emacs it was pretty vanilla. Also had a look at the init.el but couldn't find anything obvious that would affect this.

Don't know what else to try...

Super-save not triggered

I have commands from two packages that I use regularly that do not trigger super-save. Typically my current buffer is unsaved:

  1. magit-status from magit (magit does not see latest changes)
  2. quickrun from quickrun (copies and runs the code from the current unsaved buffer so the problem is not serious)

Could you please either advise how to add code to include them or add fixes to the distribution code.

Disable super-save when used with Tramp

I noticed that having super-save enabled in buffers that use Tramp (e.g. when editing a file over ssh) can be very annoying and cause significant delays. What do you think about adding an option to automatically disable super-save in such buffers?

[Feature Request] add super-save-exclude

I think it will be great if we can exclude some file from super-save. Other package had this feature, e.g recentf-exclude, dimmer, etc.

Disabling super-save in certain file can be achieved using file header #10, but it didn't automatically re-enable when we switch to other file.

Thank you for super-save, using this for years.

super-save isn't working with the window-numbering package

Hello,

I'm using Spacemacs and it has a feature to number all Emacs windows from 1, 2, 3... using the window-numbering package: https://github.com/nschum/window-numbering.el

When editing a file with super-save is enabled, the file is not automatically saved when I move the cursor to a new window by using the select-window-... function from window-numbering.el package.

Given the code of the core function of select-window-by-number as follow, can you advise how to hook super-save with the code that changes the window (setq window (aref windows i))?

(defun select-window-by-number (i &optional arg)
  "Select window given number I by `window-numbering-mode'.
If prefix ARG is given, delete the window instead of selecting it."
  (interactive "P")
  (let ((windows (car (gethash (selected-frame) window-numbering-table)))
        window)
    (if (and (>= i 0) (< i 10)
             (setq window (aref windows i)))
        (if arg
            (delete-window window)
          (select-window window))
      (error "No window numbered %s" i))))

Thanks!

Super save triggers

Although there's a variable defining which commands trigger auto save (super-save-triggers) there are still two hard-coded triggers on super-save-initialize (on mouse-leave-buffer-hook and focus-out-hook respectively). These could also be customizable (for users that only want the idle trigger, for example).

Disabling super-save-max-buffer-size (confusing new behavior)

Hi,

What would be a good way to not use super-save-max-buffer-size? For the past few days I've been confused why a file I often edit was not saving how it used too — after some investigation I see that it is because (I think) of the new super-save-max-buffer-size from this commit #37.

I can't set it to nil to disable. I guess I can just make it a really big number but that doesn't feel so neat.

Thanks. One of my favorite little Emacs packages.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.