aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJason Rumney2008-07-02 13:19:07 +0000
committerJason Rumney2008-07-02 13:19:07 +0000
commit6cf29fe81529606336b0d1ac167af5a62b9843a3 (patch)
treece0ce54a6ec8cad9315b1a7caaf5d3036e6325c2 /src
parent56fd9faa2f35556996de5777734663de5ad235e3 (diff)
downloademacs-6cf29fe81529606336b0d1ac167af5a62b9843a3.tar.gz
emacs-6cf29fe81529606336b0d1ac167af5a62b9843a3.zip
Changes from Toru Tsuneyoshi for using Trash can when deleting files.
* files.el (backup-extract-version): Handle versioned directories. (trash-directory): New variable. (move-file-to-trash): New function. * cus-start.el (delete-by-moving-to-trash): Declare for custom. * lisp.h (Qdelete_file, Qdelete_directory): Declare extern. * fileio.c (delete_by_moving_to_trash, Qmove_file_to_trash): New vars. (syms_of_fileio): Initialize and export them. (Fdelete_directory, Fdelete_file): Optionally delete via trash. * w32fns.c (FOF_NO_CONNECTED_ELEMENTS): Define if not already. (Fsystem_move_file_to_trash): New function. (syms_of_w32fns): Export it to lisp.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog12
-rw-r--r--src/fileio.c21
-rw-r--r--src/lisp.h2
-rw-r--r--src/w32fns.c59
4 files changed, 94 insertions, 0 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index fb3186d4d00..4c3faeaf442 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,15 @@
12008-07-02 Toru Tsuneyoshi <t_tuneyosi@hotmail.com>
2
3 * lisp.h (Qdelete_file, Qdelete_directory): Declare extern.
4
5 * fileio.c (delete_by_moving_to_trash, Qmove_file_to_trash): New vars.
6 (syms_of_fileio): Initialize and export them.
7 (Fdelete_directory, Fdelete_file): Optionally delete via trash.
8
9 * w32fns.c (FOF_NO_CONNECTED_ELEMENTS): Define if not already.
10 (Fsystem_move_file_to_trash): New function.
11 (syms_of_w32fns): Export it to lisp.
12
12008-07-01 Jason Rumney <jasonr@gnu.org> 132008-07-01 Jason Rumney <jasonr@gnu.org>
2 14
3 * w32font.c (w32font_text_extents): Don't count overhang as part 15 * w32font.c (w32font_text_extents): Don't count overhang as part
diff --git a/src/fileio.c b/src/fileio.c
index ffb65497a40..abe77e2e9ef 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -213,6 +213,13 @@ Lisp_Object Vdirectory_sep_char;
213int write_region_inhibit_fsync; 213int write_region_inhibit_fsync;
214#endif 214#endif
215 215
216/* Non-zero means call move-file-to-trash in Fdelete_file or
217 Fdelete_directory. */
218int delete_by_moving_to_trash;
219
220/* Lisp function for moving files to trash. */
221Lisp_Object Qmove_file_to_trash;
222
216extern Lisp_Object Vuser_login_name; 223extern Lisp_Object Vuser_login_name;
217 224
218#ifdef WINDOWSNT 225#ifdef WINDOWSNT
@@ -2674,6 +2681,9 @@ DEFUN ("delete-directory", Fdelete_directory, Sdelete_directory, 1, 1, "FDelete
2674 if (!NILP (handler)) 2681 if (!NILP (handler))
2675 return call2 (handler, Qdelete_directory, directory); 2682 return call2 (handler, Qdelete_directory, directory);
2676 2683
2684 if (delete_by_moving_to_trash)
2685 return call1 (Qmove_file_to_trash, directory);
2686
2677 encoded_dir = ENCODE_FILE (directory); 2687 encoded_dir = ENCODE_FILE (directory);
2678 2688
2679 dir = SDATA (encoded_dir); 2689 dir = SDATA (encoded_dir);
@@ -2707,6 +2717,9 @@ If file has multiple names, it continues to exist with the other names. */)
2707 if (!NILP (handler)) 2717 if (!NILP (handler))
2708 return call2 (handler, Qdelete_file, filename); 2718 return call2 (handler, Qdelete_file, filename);
2709 2719
2720 if (delete_by_moving_to_trash)
2721 return call1 (Qmove_file_to_trash, filename);
2722
2710 encoded_file = ENCODE_FILE (filename); 2723 encoded_file = ENCODE_FILE (filename);
2711 2724
2712 if (0 > unlink (SDATA (encoded_file))) 2725 if (0 > unlink (SDATA (encoded_file)))
@@ -6358,6 +6371,14 @@ A non-nil value may result in data loss! */);
6358 write_region_inhibit_fsync = 0; 6371 write_region_inhibit_fsync = 0;
6359#endif 6372#endif
6360 6373
6374 DEFVAR_BOOL ("delete-by-moving-to-trash", &delete_by_moving_to_trash,
6375 doc: /* Specifies whether to use the system's trash can.
6376When non-nil, the function `move-file-to-trash' will be used by
6377`delete-file' and `delete-directory'. */);
6378 delete_by_moving_to_trash = 0;
6379 Qmove_file_to_trash = intern ("move-file-to-trash");
6380 staticpro (&Qmove_file_to_trash);
6381
6361 defsubr (&Sfind_file_name_handler); 6382 defsubr (&Sfind_file_name_handler);
6362 defsubr (&Sfile_name_directory); 6383 defsubr (&Sfile_name_directory);
6363 defsubr (&Sfile_name_nondirectory); 6384 defsubr (&Sfile_name_nondirectory);
diff --git a/src/lisp.h b/src/lisp.h
index e126f575275..75a0fc37a8f 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -2935,6 +2935,8 @@ extern void syms_of_fileio P_ ((void));
2935extern void init_fileio_once P_ ((void)); 2935extern void init_fileio_once P_ ((void));
2936extern Lisp_Object make_temp_name P_ ((Lisp_Object, int)); 2936extern Lisp_Object make_temp_name P_ ((Lisp_Object, int));
2937EXFUN (Fmake_symbolic_link, 3); 2937EXFUN (Fmake_symbolic_link, 3);
2938extern Lisp_Object Qdelete_directory;
2939extern Lisp_Object Qdelete_file;
2938 2940
2939/* Defined in abbrev.c */ 2941/* Defined in abbrev.c */
2940 2942
diff --git a/src/w32fns.c b/src/w32fns.c
index c9a9a5ab359..011d647e722 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -63,6 +63,10 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
63#include "font.h" 63#include "font.h"
64#include "w32font.h" 64#include "w32font.h"
65 65
66#ifndef FOF_NO_CONNECTED_ELEMENTS
67#define FOF_NO_CONNECTED_ELEMENTS 0x2000
68#endif
69
66void syms_of_w32fns (); 70void syms_of_w32fns ();
67void globals_of_w32fns (); 71void globals_of_w32fns ();
68 72
@@ -6208,6 +6212,60 @@ If ONLY-DIR-P is non-nil, the user can only select directories. */)
6208} 6212}
6209 6213
6210 6214
6215/* Moving files to the system recycle bin.
6216 Used by `move-file-to-trash' instead of the default moving to ~/.Trash */
6217DEFUN ("system-move-file-to-trash", Fsystem_move_file_to_trash,
6218 Ssystem_move_file_to_trash, 1, 1, 0,
6219 doc: /* Move file or directory named FILENAME to the recycle bin. */)
6220 (filename)
6221 Lisp_Object filename;
6222{
6223 Lisp_Object handler;
6224 Lisp_Object encoded_file;
6225 Lisp_Object operation;
6226
6227 operation = Qdelete_file;
6228 if (!NILP (Ffile_directory_p (filename))
6229 && NILP (Ffile_symlink_p (filename)))
6230 {
6231 operation = Qdelete_directory;
6232 filename = Fdirectory_file_name (filename);
6233 }
6234 filename = Fexpand_file_name (filename, Qnil);
6235
6236 handler = Ffind_file_name_handler (filename, operation);
6237 if (!NILP (handler))
6238 return call2 (handler, operation, filename);
6239
6240 encoded_file = ENCODE_FILE (filename);
6241
6242 {
6243 const char * path;
6244 SHFILEOPSTRUCT file_op;
6245 char tmp_path[MAX_PATH + 1];
6246
6247 path = map_w32_filename (SDATA (encoded_file), NULL);
6248
6249 /* On Windows, write permission is required to delete/move files. */
6250 _chmod (path, 0666);
6251
6252 bzero (tmp_path, sizeof (tmp_path));
6253 strcpy (tmp_path, path);
6254
6255 bzero (&file_op, sizeof (file_op));
6256 file_op.hwnd = HWND_DESKTOP;
6257 file_op.wFunc = FO_DELETE;
6258 file_op.pFrom = tmp_path;
6259 file_op.fFlags = FOF_SILENT | FOF_NOCONFIRMATION | FOF_ALLOWUNDO
6260 | FOF_NOERRORUI | FOF_NO_CONNECTED_ELEMENTS;
6261 file_op.fAnyOperationsAborted = FALSE;
6262
6263 if (SHFileOperation (&file_op) != 0)
6264 report_file_error ("Removing old name", list1 (filename));
6265 }
6266 return Qnil;
6267}
6268
6211 6269
6212/*********************************************************************** 6270/***********************************************************************
6213 w32 specialized functions 6271 w32 specialized functions
@@ -7241,6 +7299,7 @@ only be necessary if the default setting causes problems. */);
7241 staticpro (&last_show_tip_args); 7299 staticpro (&last_show_tip_args);
7242 7300
7243 defsubr (&Sx_file_dialog); 7301 defsubr (&Sx_file_dialog);
7302 defsubr (&Ssystem_move_file_to_trash);
7244} 7303}
7245 7304
7246 7305