]> code.delx.au - gnu-emacs-elpa/blobdiff - dired-async.el
Don't recompute length fn-list, ensure operation is downcased for safety (#57).
[gnu-emacs-elpa] / dired-async.el
index 441e7fa637f641201ef436d080748b8c11037f98..3f5349daddcda9da85a40d10668043a00d542e6c 100644 (file)
 ;;; Commentary:
 
 ;; This file provide a redefinition of `dired-create-file' function,
-;; which must be loaded *after* dired-aux.el, performs copies,
-;; moves and all what is handled by `dired-create-file' in the background
-;; using a slave Emacs process, by means of the async.el module.
+;; performs copies, moves and all what is handled by `dired-create-file'
+;; in the background using a slave Emacs process,
+;; by means of the async.el module.
 ;; To use it, put this in your .emacs:
-;;
-;;   (eval-after-load "dired-aux"
-;;     '(require 'dired-async))
-;;
-;;
+
+;;     (dired-async-mode 1)
+
+;; This will enable async copy/rename etc...
+;; in dired and helm.
 
 ;;; Code:
 \f
@@ -68,19 +68,13 @@ Should take same args as `message'."
   :group 'dired-async
   :type 'string)
 
-(defcustom dired-async-be-async t
-  "When non--nil make `dired-create-file' async.
-This allow to turn off async features provided to this package."
-  :group 'dired-async
-  :type  'boolean)
-
 (defface dired-async-message
     '((t (:foreground "yellow")))
   "Face used for mode-line message."
   :group 'dired-async)
 
 (defface dired-async-mode-message
-    '((t (:background "Firebrick1")))
+    '((t (:foreground "Gold")))
   "Face used for `dired-async--modeline-mode' lighter."
   :group 'dired-async)
 
@@ -157,10 +151,11 @@ This allow to turn off async features provided to this package."
 
 See `dired-create-files' for the behavior of arguments."
   (setq dired-async-operation nil)
-  (let (dired-create-files-failures failures async-fn-list
-                                    skipped (success-count 0) (total (length fn-list))
-                                    (callback `(lambda (&optional ignore)
-                                                 (dired-async-after-file-create ,(length fn-list)))))
+  (let (dired-create-files-failures
+        failures async-fn-list
+        skipped (success-count 0)
+        (total (length fn-list))
+        callback)
     (let (to overwrite-query
              overwrite-backup-query)    ; for dired-handle-overwrite
       (dolist (from fn-list)
@@ -221,7 +216,15 @@ ESC or `q' to not overwrite any of the remaining files,
                         (push (dired-make-relative from) failures)
                         (dired-log "%s `%s' to `%s' failed"
                                    operation from to)))
-                  (push (cons from to) async-fn-list))))))
+                  (push (cons from to) async-fn-list)))))
+      (setq callback
+            `(lambda (&optional ignore)
+               (dired-async-after-file-create ,total)
+               (when (string= ,(downcase operation) "rename")
+                 (cl-loop for (file . to) in ',async-fn-list
+                          do (and (get-file-buffer file)
+                                  (with-current-buffer (get-file-buffer file)
+                                    (set-visited-file-name to nil t))))))))
     ;; Handle error happening in host emacs.
     (cond
       (dired-create-files-failures
@@ -265,14 +268,22 @@ ESC or `q' to not overwrite any of the remaining files,
       (setq dired-async-operation (list operation (length async-fn-list)))
       (message "%s proceeding asynchronously..." operation))))
 
+(defadvice dired-create-files (around dired-async)
+  (dired-async-create-files file-creator operation fn-list
+                            name-constructor marker-char))
+
 ;;;###autoload
 (define-minor-mode dired-async-mode
     "Do dired actions asynchronously."
   :group 'dired-async
   :global t
   (if dired-async-mode
-      (advice-add 'dired-create-files :override #'dired-async-create-files)
-      (advice-remove 'dired-create-files #'dired-async-create-files)))
+      (if (fboundp 'advice-add)
+          (advice-add 'dired-create-files :override #'dired-async-create-files)
+          (ad-activate 'dired-create-files))
+      (if (fboundp 'advice-remove)
+          (advice-remove 'dired-create-files #'dired-async-create-files)
+          (ad-deactivate 'dired-create-files))))
 
 
 (provide 'dired-async)