0

I have followed this answer's solution. My goal is to back up files right after I save them.

When I create a new file it is successfully backed up to the given path, but when I close and re-open Emacs the file that I was working on is not backed up or created. Please note that I have created new key bindings for saving and closing.

my setup:

(defvar --backup-directory (concat user-emacs-directory "backups_alper"))
(if (not (file-exists-p --backup-directory))
    (make-directory --backup-directory t))

(setq backup-directory-alist `(("." . ,--backup-directory))) (setq backup-by-copying t)

(setq backup-by-copying t ; don't clobber symlinks version-control t ; version numbers for backup files delete-old-versions t ; delete excess backup files silently delete-by-moving-to-trash t kept-old-versions 6 ; oldest versions to keep when a new numbered backup is made (default: 2) kept-new-versions 9 ; newest versions to keep when a new numbered backup is made (default: 2) auto-save-default t ; auto-save every buffer that visits a file auto-save-timeout 20 ; number of seconds idle time before auto-save (default: 30) auto-save-interval 200 ; number of keystrokes between auto-saves (default: 300) )

;; my save: (defun my-save-all () "My doc-string." (interactive) (let ((message-log-max nil) (inhibit-message t)) (save-some-buffers t)))

(defun save-all () (interactive) (my-save-all) (bk-kill-buffers "magit: project") (bk-kill-buffers "init.py") (bk-kill-buffers "*helm"))

(define-key ctl-x-map "\C-s" 'save-all)

;; closing emacs (defun my-kill-emacs () "save some buffers, then exit unconditionally" (interactive) (my-save-all) ;; (save-some-buffers nil t) (save-buffers-kill-terminal))

(global-set-key (kbd "C-x C-c") 'my-kill-emacs)

Drew
  • 77,472
  • 10
  • 114
  • 243
alper
  • 1,370
  • 1
  • 13
  • 35
  • See this SO answer https://stackoverflow.com/a/9452080/151019 – mmmmmm Jan 05 '21 at 17:11
  • I have added the answer to the .emacs file but it didn't make any affect @mmmmmm – alper Jan 05 '21 at 19:38
  • What did you bind to the new function? – mmmmmm Jan 05 '21 at 19:45
  • Could I bind it to my my-save-all() function? I try to run le::save-buffer-force-backupfunction but I am not sure where did it save the backup if it does – alper Jan 05 '21 at 19:52
  • The backup is saved according to backup-directory-alist – mmmmmm Jan 05 '21 at 20:03
  • Hm I check it out but still the file I am editing on is not backup into that directory :-(, there is only recentf and .emacs files are saved – alper Jan 05 '21 at 22:42
  • For (savehist-mode 1) I keep getting (void-variable pell-buffer) signal(void-variable (pell-buffer)) savehist-mode(1) that might be the main cause – alper Jan 14 '21 at 12:05

0 Answers0