Refactor auto-save of files

See committed documentation.
This commit is contained in:
syl20bnr 2015-06-18 23:54:07 -04:00
parent 4a19bd9d33
commit cd70f04827
7 changed files with 72 additions and 27 deletions

View File

@ -21,9 +21,15 @@
- elixir (split from =erlang-elixir=)
- erlang (split from =erlang-elixir=)
- github (split from =git=)
- ipython (ein) (thanks to CestDiego)
- ipython-notebook (ein) (thanks to CestDiego)
- latex (was =auctex=)
- version-control
*** Dotfile changes
- New variable =dotspacemacs-auto-save-file-location= which enable or
disable auto-saving of modified files. Possible values are =original= to
auto-save the file in-place, =cache= to auto-save the file to another
file stored in the cache directory and =nil= to disable auto-saving.
Default value is =cache=.
*** Layer changes
**** Spacemacs
- Add text alignment key bindings on ~SPC x a~ prefix (thanks to justbur and
@ -117,7 +123,7 @@
- Add support for =flycheck= (thanks to swaroopch)
**** Scala
- Set classpath directory of =ensime= to =.cache/ensime= (thanks to cyrillk)
**** Themes
**** Theme
- Add spacemacs-theme
*** Core
- New interactive function =spacemacs/switch-to-version=

View File

@ -87,9 +87,11 @@ with `:' and Emacs commands are executed with `<leader> :'.")
"If non nil then `ido' replaces `helm' for some commands. For now only
`find-files' (SPC f f) is replaced.")
(defvar dotspacemacs-autosave-file-directly nil
"If non-nil, auto-save to the file directly. If nil, just save
to auto-save file in `spacemacs-cache-directory'")
(defvar dotspacemacs-auto-save-file-location 'cache
"Location where to auto-save files. Possible values are `original' to
auto-save the file in-place, `cache' to auto-save the file to another
file stored in the cache directory and `nil' to disable auto-saving.
Default value is `cache'.")
(defvar dotspacemacs-enable-paste-micro-state t
"If non nil the paste micro-state is enabled. While enabled pressing `p`

View File

@ -33,6 +33,9 @@
(defconst spacemacs-cache-directory
(expand-file-name (concat user-emacs-directory ".cache/"))
"Spacemacs storage area for persistent files")
(defconst spacemacs-auto-save-directory
(expand-file-name (concat spacemacs-cache-directory "auto-save/"))
"Spacemacs auto-save directory")
(defconst spacemacs-docs-directory
(expand-file-name (concat user-emacs-directory "doc/"))
"Spacemacs documentation directory.")

View File

@ -96,9 +96,11 @@ before layers configuration."
;; By default the command key is `:' so ex-commands are executed like in Vim
;; with `:' and Emacs commands are executed with `<leader> :'.
dotspacemacs-command-key ":"
;; If non-nil, auto-save to the file directly. If nil, just save
;; to auto-save file in `spacemacs-cache-directory'
dotspacemacs-autosave-file-directly nil
;; Location where to auto-save files. Possible values are `original' to
;; auto-save the file in-place, `cache' to auto-save the file to another
;; file stored in the cache directory and `nil' to disable auto-saving.
;; Default value is `cache'.
dotspacemacs-auto-save-file-location 'cache
;; If non nil then `ido' replaces `helm' for some commands. For now only
;; `find-files' (SPC f f) is replaced.
dotspacemacs-use-ido nil

View File

@ -100,6 +100,10 @@
- [[#neotree-mode-line][NeoTree mode-line]]
- [[#bookmarks][Bookmarks]]
- [[#docview-mode][DocView mode]]
- [[#auto-saving][Auto-saving]]
- [[#frequency-of-auto-saving][Frequency of auto-saving]]
- [[#location-of-auto-saved-files][Location of auto-saved files]]
- [[#disable-auto-save][Disable auto-save]]
- [[#searching][Searching]]
- [[#with-an-external-tool][With an external tool]]
- [[#useful-key-bindings][Useful key bindings]]
@ -1297,7 +1301,7 @@ The mode can be toggled on and off with ~SPC t g~.
Since =helm= is used everywhere, by default Spacemacs uses =helm= to open files.
Some users prefer the =ido= way to navigate the file system because it can
remember the last selected directories and buffers and return is used to open
remember the last selected directories and buffers and ~RET~ is used to open
directories instead of ~TAB~ or ~C-z~ in =helm=. It is possible to use =ido=
instead of =helm= by setting the variable =dotspacemacs-use-ido= to =t= in your
dotfile.
@ -1538,6 +1542,31 @@ OpenDocument, and Microsoft Office documents.
| ~C-c C-c~ | toggle display text and image display |
| ~C-c C-t~ | open new buffer with doc's text contents |
** Auto-saving
*** Frequency of auto-saving
By default auto-saving of files is performed every 300 characters and
every 30 seconds of idle time which can be changed by setting to a
new value the variables =auto-save-inteval= and =auto-save-timeout=
respectively.
*** Location of auto-saved files
Auto-save of modified files can be performed in-place on the original file
itself /or/ in the cache directory (in this case the original file will remain
unsaved). By default Spacemacs auto-save the file in the cache directory.
To modify the location set the variable =dotspacemacs-auto-save-file-location=
to =original= or =cache=.
Local files are auto-saved in a sub-directory called =site= in the =cache=
directory whereas remote files editing via TRAMP are auto-saved in a
sub-directory called =dist=.
*** Disable auto-save
To disable auto-saving set the variable =dotspacemacs-auto-save-file-location=
to =nil=.
You can toggle auto-save in a buffer by calling the command =auto-save-mode=.
** Searching
*** With an external tool
=Spacemacs= can be interfaced with different search utilities like:

View File

@ -219,8 +219,27 @@ Can be installed with `brew install trash'."
make-backup-files nil
create-lockfiles nil)
(setq auto-save-file-name-transforms `((".*" ,spacemacs-cache-directory t)))
(add-hook 'auto-save-hook 'save-buffer-if-visiting-file)
;; Auto-save file
(setq auto-save-default (not (null dotspacemacs-auto-save-file-location)))
(setq auto-save-list-file-prefix (concat spacemacs-auto-save-directory))
;; always save TRAMP URLs to cache directory no matter what is the value
;; of `dotspacemacs-auto-save-file-location'
(let ((autosave-dir (concat spacemacs-auto-save-directory "dist/")))
(setq auto-save-file-name-transforms
`(("\\`/[^/]*:\\([^/]*/\\)*\\([^/]*\\)\\'" ,autosave-dir t)))
(unless (or (file-exists-p autosave-dir)
(null dotspacemacs-auto-save-file-location))
(make-directory autosave-dir t)))
;; Choose auto-save location
(case dotspacemacs-auto-save-file-location
(cache (let ((autosave-dir (concat spacemacs-auto-save-directory "site/")))
(add-to-list 'auto-save-file-name-transforms
`(".*" ,autosave-dir t) 'append)
(unless (file-exists-p autosave-dir)
(make-directory autosave-dir t))))
(original (setq auto-save-visited-file-name t))
(_ (setq auto-save-default nil
auto-save-list-file-prefix nil)))
(require 'uniquify)
;; When having windows with repeated filenames, uniquify them
@ -245,14 +264,6 @@ Can be installed with `brew install trash'."
savehist-autosave-interval 60)
(savehist-mode +1)
;; auto-save
(let
((autosave-dir (expand-file-name (concat spacemacs-cache-directory "autosave"))))
(unless (file-exists-p autosave-dir)
(make-directory autosave-dir))
(setq auto-save-list-file-prefix (concat autosave-dir "/")
auto-save-file-name-transforms `((".*" ,autosave-dir t))))
;; cache files
;; bookmarks
(setq bookmark-default-file (concat spacemacs-cache-directory "bookmarks")

View File

@ -1007,11 +1007,3 @@ the right."
(create-align-repeat-x "bar" "|")
(create-align-repeat-x "left-paren" "(")
(create-align-repeat-x "right-paren" ")" t)
(defun save-buffer-if-visiting-file (&optional args)
"Save the current buffer only if it is visiting a file"
(interactive)
(if (and dotspacemacs-autosave-file-directly
(buffer-file-name)
(buffer-modified-p))
(save-buffer args)))