Auto backup hook
Posted: Sat Aug 10, 2013 10:11 pm
Hi all!
I'm a Vim user trying to migrate to Emacs. When using Vim I wrote a simple code (in vimscript) where it saves me a copy of my working file (with the file name plus date and time) everytime I open or save it.
I tried doing it with Emacs but ended up in a loophole. Here's what I wrote so far:
The loophole happens because I add the function autobk-save to the before-save-hook and inside autobk-save I try to save the file, which calls the hook which calls the function again and again. So I think I need a way to tell the write-file function inside autobk-save to not use the hook, right? I tried sniffing around the file.el code but haven't found a clue the could help me. I know this is probably a bad code and maybe also a bad question, but I'm still a beginner with lisp and I'm open to any suggestions.
Thank you in advance
I'm a Vim user trying to migrate to Emacs. When using Vim I wrote a simple code (in vimscript) where it saves me a copy of my working file (with the file name plus date and time) everytime I open or save it.
I tried doing it with Emacs but ended up in a loophole. Here's what I wrote so far:
Code: Select all
(defvar autobk-default-dir "~/.emacsbk/")
(defun autobk-save ()
"func description"
(interactive)
(defvar autobk-orignal-file-name buffer-file-name)
(write-file (concat
autobk-default-dir
(buffer-name)
"_"
(shell-command-to-string "echo -n $(date +%Y-%m-%d)")
".bak"))
(write-file autobk-orignal-file-name)
(message buffer-file-name))
(add-hook 'before-save-hook 'autobk-save)
Thank you in advance