comparison src/fileio.c @ 108806:511da81b16c5

Change delete-by-moving-to-trash so Lisp calls explicitly request trashing. * src/fileio.c (Fdelete_file): Change meaning of optional arg to mean whether to trash. (internal_delete_file, Frename_file): Callers changed. (delete_by_moving_to_trash): Doc fix. (Fdelete_directory_internal): Don't move to trash. * src/callproc.c (delete_temp_file): * src/buffer.c (Fkill_buffer): Callers changed. * src/lisp.h: Update prototype. * lisp/diff.el (diff-sentinel): * lisp/epg.el (epg--make-temp-file, epg-decrypt-string) (epg-verify-string, epg-sign-string, epg-encrypt-string): * lisp/jka-compr.el (jka-compr-partial-uncompress) (jka-compr-call-process, jka-compr-write-region): * lisp/server.el (server-sentinel): Remove optional arg from delete-file, reverting 2010-05-03 change. * lisp/dired.el (dired-delete-file): New arg TRASH. (dired-internal-do-deletions): New arg TRASH. Use progress reporter. (dired-do-flagged-delete, dired-do-delete): Use trash. * lisp/files.el (delete-directory): New arg TRASH. * lisp/speedbar.el (speedbar-item-delete): Allow trashing. * lisp/net/ange-ftp.el (ange-ftp-del-tmp-name, ange-ftp-delete-file) (ange-ftp-rename-remote-to-remote) (ange-ftp-rename-local-to-remote) (ange-ftp-rename-remote-to-local, ange-ftp-load) (ange-ftp-compress, ange-ftp-uncompress): Remove optional arg from `delete-file'. (ange-ftp-delete-directory): Add optional arg to `delete-file', to allow trashing. * lisp/net/tramp-compat.el (tramp-compat-delete-file): Rewrite to handle new TRASH arg of `delete-file'. * lisp/net/tramp-fish.el (tramp-fish-handle-delete-directory) (tramp-fish-handle-delete-file) (tramp-fish-handle-make-symbolic-link) (tramp-fish-handle-process-file): Use null TRASH arg in `tramp-compat-delete-file' call. * lisp/net/tramp-ftp.el (tramp-ftp-file-name-handler): Use null TRASH arg in `tramp-compat-delete-file' call. * lisp/net/tramp-gvfs.el (tramp-gvfs-handle-delete-file): Rename arg. (tramp-gvfs-handle-write-region): Use null TRASH arg in `tramp-compat-delete-file' call. * lisp/net/tramp-imap.el (tramp-imap-handle-delete-file): Rename arg. (tramp-imap-do-copy-or-rename-file): Use null TRASH arg in `tramp-compat-delete-file' call. * lisp/net/tramp-smb.el (tramp-smb-handle-copy-file) (tramp-smb-handle-file-local-copy, tramp-smb-handle-rename-file) (tramp-smb-handle-write-region): Use null TRASH arg in tramp-compat-delete-file call. (tramp-smb-handle-delete-directory): Use tramp-compat-delete-file. (tramp-smb-handle-delete-file): Rename arg. * lisp/net/tramp.el (tramp-handle-delete-file): Change FORCE arg to TRASH. (tramp-handle-make-symbolic-link, tramp-handle-load) (tramp-do-copy-or-rename-file-via-buffer) (tramp-do-copy-or-rename-file-directly) (tramp-do-copy-or-rename-file-out-of-band) (tramp-handle-process-file, tramp-handle-call-process-region) (tramp-handle-shell-command, tramp-handle-file-local-copy) (tramp-handle-insert-file-contents, tramp-handle-write-region) (tramp-delete-temp-file-function): Use null TRASH arg in tramp-compat-delete-file call.
author Chong Yidong <cyd@stupidchicken.com>
date Thu, 27 May 2010 19:30:11 -0400
parents 0f1244b4539c
children 6515310887ec
comparison
equal deleted inserted replaced
108805:78199a49c4bf 108806:511da81b16c5
2178 Lisp_Object handler; 2178 Lisp_Object handler;
2179 Lisp_Object encoded_dir; 2179 Lisp_Object encoded_dir;
2180 2180
2181 CHECK_STRING (directory); 2181 CHECK_STRING (directory);
2182 directory = Fdirectory_file_name (Fexpand_file_name (directory, Qnil)); 2182 directory = Fdirectory_file_name (Fexpand_file_name (directory, Qnil));
2183
2184 if (delete_by_moving_to_trash)
2185 return call1 (Qmove_file_to_trash, directory);
2186
2187 encoded_dir = ENCODE_FILE (directory); 2183 encoded_dir = ENCODE_FILE (directory);
2188
2189 dir = SDATA (encoded_dir); 2184 dir = SDATA (encoded_dir);
2190 2185
2191 if (rmdir (dir) != 0) 2186 if (rmdir (dir) != 0)
2192 report_file_error ("Removing directory", list1 (directory)); 2187 report_file_error ("Removing directory", list1 (directory));
2193 2188
2194 return Qnil; 2189 return Qnil;
2195 } 2190 }
2196 2191
2197 DEFUN ("delete-file", Fdelete_file, Sdelete_file, 1, 2, 2192 DEFUN ("delete-file", Fdelete_file, Sdelete_file, 1, 2,
2198 "(list (read-file-name \"Delete file: \" nil default-directory \ 2193 "(list (read-file-name \
2199 (confirm-nonexistent-file-or-buffer)) \ 2194 (if (and delete-by-moving-to-trash (null current-prefix-arg)) \
2200 current-prefix-arg)", 2195 \"Move file to trash: \" \"Delete file: \") \
2196 nil default-directory (confirm-nonexistent-file-or-buffer)) \
2197 (null current-prefix-arg))",
2201 doc: /* Delete file named FILENAME. If it is a symlink, remove the symlink. 2198 doc: /* Delete file named FILENAME. If it is a symlink, remove the symlink.
2202 If file has multiple names, it continues to exist with the other names. 2199 If file has multiple names, it continues to exist with the other names.
2203 2200 TRASH non-nil means to trash the file instead of deleting, provided
2204 If optional arg FORCE is non-nil, really delete the file regardless of 2201 `delete-by-moving-to-trash' is non-nil.
2205 `delete-by-moving-to-trash'. Otherwise, \"deleting\" actually moves 2202
2206 it to the system's trash can if `delete-by-moving-to-trash' is non-nil. 2203 When called interactively, TRASH is t if no prefix argument is given.
2207 Interactively, FORCE is non-nil if called with a prefix arg. */) 2204 With a prefix argument, TRASH is nil. */)
2208 (filename, force) 2205 (filename, trash)
2209 Lisp_Object filename; 2206 Lisp_Object filename;
2210 Lisp_Object force; 2207 Lisp_Object trash;
2211 { 2208 {
2212 Lisp_Object handler; 2209 Lisp_Object handler;
2213 Lisp_Object encoded_file; 2210 Lisp_Object encoded_file;
2214 struct gcpro gcpro1; 2211 struct gcpro gcpro1;
2215 2212
2224 2221
2225 handler = Ffind_file_name_handler (filename, Qdelete_file); 2222 handler = Ffind_file_name_handler (filename, Qdelete_file);
2226 if (!NILP (handler)) 2223 if (!NILP (handler))
2227 return call2 (handler, Qdelete_file, filename); 2224 return call2 (handler, Qdelete_file, filename);
2228 2225
2229 if (delete_by_moving_to_trash && NILP (force)) 2226 if (delete_by_moving_to_trash && !NILP (trash))
2230 return call1 (Qmove_file_to_trash, filename); 2227 return call1 (Qmove_file_to_trash, filename);
2231 2228
2232 encoded_file = ENCODE_FILE (filename); 2229 encoded_file = ENCODE_FILE (filename);
2233 2230
2234 if (0 > unlink (SDATA (encoded_file))) 2231 if (0 > unlink (SDATA (encoded_file)))
2242 { 2239 {
2243 return Qt; 2240 return Qt;
2244 } 2241 }
2245 2242
2246 /* Delete file FILENAME, returning 1 if successful and 0 if failed. 2243 /* Delete file FILENAME, returning 1 if successful and 0 if failed.
2247 FORCE means to ignore `delete-by-moving-to-trash'. */ 2244 This ignores `delete-by-moving-to-trash'. */
2248 2245
2249 int 2246 int
2250 internal_delete_file (Lisp_Object filename, Lisp_Object force) 2247 internal_delete_file (Lisp_Object filename)
2251 { 2248 {
2252 Lisp_Object tem; 2249 Lisp_Object tem;
2253 2250
2254 tem = internal_condition_case_2 (Fdelete_file, filename, force, 2251 tem = internal_condition_case_2 (Fdelete_file, filename, Qnil,
2255 Qt, internal_delete_file_1); 2252 Qt, internal_delete_file_1);
2256 return NILP (tem); 2253 return NILP (tem);
2257 } 2254 }
2258 2255
2259 DEFUN ("rename-file", Frename_file, Srename_file, 2, 3, 2256 DEFUN ("rename-file", Frename_file, Srename_file, 2, 3,
2343 && NILP (symlink_target) 2340 && NILP (symlink_target)
2344 #endif 2341 #endif
2345 ) 2342 )
2346 call2 (Qdelete_directory, file, Qt); 2343 call2 (Qdelete_directory, file, Qt);
2347 else 2344 else
2348 Fdelete_file (file, Qt); 2345 Fdelete_file (file, Qnil);
2349 unbind_to (count, Qnil); 2346 unbind_to (count, Qnil);
2350 } 2347 }
2351 else 2348 else
2352 report_file_error ("Renaming", list2 (file, newname)); 2349 report_file_error ("Renaming", list2 (file, newname));
2353 } 2350 }
5915 write_region_inhibit_fsync = 0; 5912 write_region_inhibit_fsync = 0;
5916 #endif 5913 #endif
5917 5914
5918 DEFVAR_BOOL ("delete-by-moving-to-trash", &delete_by_moving_to_trash, 5915 DEFVAR_BOOL ("delete-by-moving-to-trash", &delete_by_moving_to_trash,
5919 doc: /* Specifies whether to use the system's trash can. 5916 doc: /* Specifies whether to use the system's trash can.
5920 When non-nil, the function `move-file-to-trash' will be used by 5917 When non-nil, certain file deletion commands use the function
5921 `delete-file' and `delete-directory'. */); 5918 `move-file-to-trash' instead of deleting files outright.
5919 This includes interactive calls to `delete-file' and
5920 `delete-directory' and the Dired deletion commands. */);
5922 delete_by_moving_to_trash = 0; 5921 delete_by_moving_to_trash = 0;
5923 Qdelete_by_moving_to_trash = intern_c_string ("delete-by-moving-to-trash"); 5922 Qdelete_by_moving_to_trash = intern_c_string ("delete-by-moving-to-trash");
5924 Qmove_file_to_trash = intern_c_string ("move-file-to-trash"); 5923 Qmove_file_to_trash = intern_c_string ("move-file-to-trash");
5925 staticpro (&Qmove_file_to_trash); 5924 staticpro (&Qmove_file_to_trash);
5926 Qcopy_directory = intern_c_string ("copy-directory"); 5925 Qcopy_directory = intern_c_string ("copy-directory");