0

delete-directoryフラグを有効にした関数の奇妙な動作がありますdelete-by-removing-to-trashmove-file-to-trashディレクトリに適用するのではなく、ファイルを 1 つずつ削除します。その結果、emacs は大きなディレクトリをゆっくりと削除し、削除後にゴミ箱に多くのファイルが残るため、ディレクトリを復元することは不可能です。

例: ディレクトリ構造:

ddd/
   ccc/
       1.txt

を削除した後、ゴミ箱には 3 つのファイルがありますddd

trash/
    ddd/
    ccc/
    1.txt

1つの代わりに:

trash/
    ddd/
  • emacs はディレクトリを再帰的にトラバースするため、非常に低速です。
  • 削除したディレクトリを復元できません。

私が必要としているのは、のとまったく同じ動作ですmove-file-to-trash。ただし、透明にする必要があります (つまり、dired モードでは 'D x')。問題を解決するには?一時的な解決策として、「delete-directory」の作成アドバイス機能を参照してください。

4

3 に答える 3

1

これが私のシステム全体です。底を見ると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 に関連付けられているコマンドライン プログラムが必要であることに言及する必要があります。trashGNOME を使用しない場合は、trash-cli パッケージからこれを置き換えることができます。

于 2010-04-16T06:46:44.580 に答える
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))
于 2010-04-10T13:30:52.820 に答える
0

私の「答え」は次のとおりM-x report-emacs-bugです。バグレポートは誰にとっても役立ちます。Emacs Dev は実際にバグがあるかどうかを判断し、関係者全員がレポートから学びます。

于 2011-08-21T16:55:27.970 に答える