2010-04-06 78 views
0

有一個奇怪的行爲delete-directory函數與啓用標誌delete-by-removing-to-trash。它將逐個刪除文件,而不是將move-file-to-trash應用於目錄。因此emacs緩慢刪除大目錄,刪除後垃圾桶中有很多文件,因此不可能恢復該目錄。問題在'刪除目錄'啓用'刪除刪除到垃圾'

例子: 目錄結構:

ddd/ 
    ccc/ 
     1.txt 

中有三個文件在垃圾桶刪除ddd後:

trash/ 
    ddd/ 
    ccc/ 
    1.txt 

,而不是一個:

trash/ 
    ddd/ 
  • 這是非常慢,因爲emacs遞歸地遍歷目錄。
  • 我無法恢復已刪除的目錄。

我需要的是和move-file-to-trash完全一樣的行爲。但它應該是透明的(即在直達模式下'D x')。如何解決問題?作爲臨時解決方案,我看到了「delete-directory」的製作建議功能。

+0

作爲臨時解決辦法我使用: (setq刪除逐移動到垃圾箱噸)
(defadvice dired-刪除文件(約 激活-移動到垃圾箱 激活 編譯) (如果通過移動到垃圾刪除 (移動文件到垃圾箱(ad-get-arg 0)) ad-do-it)) – Andreo 2010-04-10 13:25:57

回答

1

作爲臨時解決辦法,我使用:

(setq delete-by-moving-to-trash t) 

(defadvice dired-delete-file (around 
           activate-move-to-trash 
           activate 
           compile) 
    (if delete-by-moving-to-trash 
     (move-file-to-trash (ad-get-arg 0)) 
    ad-do-it)) 
1

這裏是我的整個系統。如果你看看底部,你會看到Andreo's幾乎相同的defadvice

;;; trash-settings.el - Intelligent integration with system trash 

;; Use the system trash, except for temp files and stuff 
(require 'cl) 

(defcustom system-trash-exclude-names 
    nil 
    "List of file names to exclude from system trash. 
The names in this variable are matched only against the basename 
of the file to be deleted." 
    :type '(repeat string) 
    :group 'trash) 

(defcustom system-trash-exclude-paths 
    nil 
    "List of absolute paths to exclude from system trash. 
If a path to a directory is excluded, then all the contents of that directory are also excluded." 
    :type '(repeat string) 
    :group 'trash) 

(defcustom system-trash-exclude-matches 
    nil 
    "List of regexps or functions matching file names to exclude from system trash. 
The matches are only applied against the file name, not the path." 
    :type '(repeat (choice regexp function)) 
    :group 'trash) 

(defcustom system-trash-exclude-path-matches 
    nil 
    "List of regexps or functions matching paths to exclude from system trash. 
The matches are applied against the full path." 
    :type '(repeat (choice regexp function)) 
    :group 'trash) 

(defun call-process-discard-output (program &rest args) 
    "Execute program with args without saving any output. 
In particular, no temp files are created." 
    (eval (append `(call-process ,program nil nil nil) args))) 

(defun string-begins-with-p (string beginning) 
    "Return t if and only if string begins with beginning" 
    (string-match-p (concat "^" (regexp-quote beginning)) string)) 

(defun file-excluded-from-system-trash-p (path) 
    "Returns non-nil if file name is excluded from trash." 
    (let ((basename (file-name-nondirectory path))) 
    (or 
    (some (apply-partially 'string= basename) 
      system-trash-exclude-names) 
    (some (apply-partially 'string-begins-with-p path) 
      system-trash-exclude-paths) 
    (some (lambda (match) 
      (funcall 
       (cond ((stringp match) 'string-match-p) 
        ((functionp protected-match) 'funcall) 
        (t 'ignore)) 
       match 
       basename)) 
      system-trash-exclude-matches) 
    (some (lambda (match) 
      (funcall 
       (cond ((stringp match) 'string-match-p) 
        ((functionp protected-match) 'funcall) 
        (t 'ignore)) 
       match 
       path)) 
      system-trash-exclude-path-matches)))) 

(defun trash-or-rm (filename) 
    "Attempt to move a file to the trash. If this fails, simply delete it. 
This guarantees that any deletable file will either be trashed or deleted. 
If the file is excluded from the trash, it is simply deleted." 
    (unless (file-excluded-from-system-trash-p filename) 
    (ignore-errors 
     (call-process-discard-output "gvfs-trash" filename))) 
    (when (file-exists-p filename) 
    (call-process-discard-output "rm" "-rf" filename))) 

(defalias 'system-move-file-to-trash 'trash-or-rm) 

(defadvice delete-directory (around no-recursive-trash activate) 
    "When trashing a directory, there's no need to trash its contents first." 
    (if delete-by-moving-to-trash 
    (move-file-to-trash directory) 
    ad-do-it)) 

(defadvice dired-delete-file (around no-recursive-trash activate) 
    "When trashing a directory, there's no need to trash its contents first. 
There's also no need to ask, because it's undoable." 
    (if delete-by-moving-to-trash 
     (move-file-to-trash file) 
    ad-do-it)) 

編輯:我要指出,我的上述解決方案需要gvfs-trash命令行程序,它與GNOME相關。如果您不使用GNOME,則可以使用trash-cli軟件包中的trash替換它。

0

我的「答案」是:M-x report-emacs-bug。錯誤報告幫助每個人。 Emacs Dev將確定是否存在實際的錯誤,並且所涉及的每個人都將從報告中學習。