0

I want to bind a key to save a timestamped backup of the current buffer to a specific directory. For example C-§ will save my current buffer to ~/Org/Backups/2017-01-01-foo.org.

Unfortunately every answer for something similar that I've seen looks unnecessary complicated and I would like to keep a simple binding for what should be a simple task.

  • 1
    Another option might be to allow Emacs to make backups automatically and set make-backup-file-name-function to control how backup files are named. – glucas Nov 9 '17 at 18:12
2

Here's my take on a command doing what you want, and also how to bind it to the desired key.

(defun save-timestamped-backup ()
  "Save a timestamped backup of current buffer to ~/Org/Backups"
  (interactive)
  (write-region (point-min) (point-max)
                (format "~/Org/Backups/%s-%s"
                        (format-time-string "%Y-%m-%d")
                        (buffer-name))))

(global-set-key (kbd "C-§") #'save-timestamped-backup)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.