(defconst +bufname+ "*copy-files*")
(defconst +proname+ "*backup-files*")
(defconst +tmpbufname+ "*tmp-files*")
(defun copy-file (process event)
(let* ((f (get-file))
(args "-rfv"))
(if (and (null f)
(not (null process)))
(process-over "<copy-file>" event 'find-baks)
(progn
(start-process +proname+ +bufname+ "cp" args f dest-bakdir)
(message "copy %s to %s" f dest-bakdir)
(set-process-sentinel (get-process +proname+) 'copy-file)))))
(defun find-baks (process event)
(let* ((args "-iname")
(bak-regx "*~"))
(if (not (null process))
(progn
(reset-filelist (get-tmp-files))
(process-over "<find-baks>" event 'del-baks))
(progn
(message "find %s %s %s" dest-bakdir args bak-regx)
(ignore-errors (kill-buffer +tmpbufname+))
(start-process +proname+ +tmpbufname+ "f:/software/bin/find.exe" dest-bakdir args bak-regx)
(message "find bak files in %s " dest-bakdir)
(set-process-sentinel (get-process +proname+) 'find-baks)))))
;; (fboundp 'find-baks)
(defun process-over (process event next-func)
(progn (princ
(format "Process: %s had the event `%s'" process event))
(if (fboundp next-func)
(funcall next-func nil nil)
(progn
(switch-to-buffer +bufname+)
(raise-frame)))))
(defun del-baks (process event)
(let* ((f (get-file))
(args "-rfv"))
(if (and (null f)
(not (null process)))
(process-over "<del-baks>" event 'zip-files)
(progn
(start-process +proname+ +bufname+ "rm" args f)
(set-process-sentinel (get-process +proname+) 'del-baks)))))
(defun get-tmp-files ()
(let ((oldbuf (current-buffer)))
(with-current-buffer (get-buffer "*tmp-files*")
(let ((str '())
(x (thing-at-point 'line)))
(while (not (eq (point-max) (point-min)))
(progn
(setq str (cons (substring x 0 -1) str))
(move-beginning-of-line 1)
(kill-line 1)
(goto-line 1)
(setq x (thing-at-point 'line))))
(kill-buffer (current-buffer))
str))))
(setq lexical-binding t)
(defconst backup-files '("~/.emacs" "~/.emacs.d"))
(defconst dest-bakdir "~/tmp/emacs_bak")
(defun make-backup-files (files)
(let ((fl files))
(defun get-file ()
(let ((x (car fl)))
(setq fl (cdr fl))
x))
(defun reset-filelist (flist)
(setq fl flist))))
(make-backup-files backup-files)
;; (reset-filelist backup-files)
;; (get-file )
(defun mybackup ()
"backup my emacs config files
files are listed in `backup-file' variable"
(interactive)
(let ((files backup-files))
(mkdir dest-bakdir t)
(delete-directory dest-bakdir t)
(mkdir dest-bakdir t)
(reset-filelist backup-files)
(copy-file nil nil)))
(defconst +proname+ "*backup-files*")
(defconst +tmpbufname+ "*tmp-files*")
(defun copy-file (process event)
(let* ((f (get-file))
(args "-rfv"))
(if (and (null f)
(not (null process)))
(process-over "<copy-file>" event 'find-baks)
(progn
(start-process +proname+ +bufname+ "cp" args f dest-bakdir)
(message "copy %s to %s" f dest-bakdir)
(set-process-sentinel (get-process +proname+) 'copy-file)))))
(defun find-baks (process event)
(let* ((args "-iname")
(bak-regx "*~"))
(if (not (null process))
(progn
(reset-filelist (get-tmp-files))
(process-over "<find-baks>" event 'del-baks))
(progn
(message "find %s %s %s" dest-bakdir args bak-regx)
(ignore-errors (kill-buffer +tmpbufname+))
(start-process +proname+ +tmpbufname+ "f:/software/bin/find.exe" dest-bakdir args bak-regx)
(message "find bak files in %s " dest-bakdir)
(set-process-sentinel (get-process +proname+) 'find-baks)))))
;; (fboundp 'find-baks)
(defun process-over (process event next-func)
(progn (princ
(format "Process: %s had the event `%s'" process event))
(if (fboundp next-func)
(funcall next-func nil nil)
(progn
(switch-to-buffer +bufname+)
(raise-frame)))))
(defun del-baks (process event)
(let* ((f (get-file))
(args "-rfv"))
(if (and (null f)
(not (null process)))
(process-over "<del-baks>" event 'zip-files)
(progn
(start-process +proname+ +bufname+ "rm" args f)
(set-process-sentinel (get-process +proname+) 'del-baks)))))
(defun get-tmp-files ()
(let ((oldbuf (current-buffer)))
(with-current-buffer (get-buffer "*tmp-files*")
(let ((str '())
(x (thing-at-point 'line)))
(while (not (eq (point-max) (point-min)))
(progn
(setq str (cons (substring x 0 -1) str))
(move-beginning-of-line 1)
(kill-line 1)
(goto-line 1)
(setq x (thing-at-point 'line))))
(kill-buffer (current-buffer))
str))))
(setq lexical-binding t)
(defconst backup-files '("~/.emacs" "~/.emacs.d"))
(defconst dest-bakdir "~/tmp/emacs_bak")
(defun make-backup-files (files)
(let ((fl files))
(defun get-file ()
(let ((x (car fl)))
(setq fl (cdr fl))
x))
(defun reset-filelist (flist)
(setq fl flist))))
(make-backup-files backup-files)
;; (reset-filelist backup-files)
;; (get-file )
(defun mybackup ()
"backup my emacs config files
files are listed in `backup-file' variable"
(interactive)
(let ((files backup-files))
(mkdir dest-bakdir t)
(delete-directory dest-bakdir t)
(mkdir dest-bakdir t)
(reset-filelist backup-files)
(copy-file nil nil)))