backup.el 备份文件

(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)))

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值