aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEric S. Raymond2023-08-06 07:00:22 -0400
committerEric S. Raymond2023-08-06 09:31:39 -0400
commit10a7615b5d45bcd909bb03d67423b337dfe93b1e (patch)
tree125c1990b016f37bd7ba200d180d961515f7831c /src
parent2924541b8f17e31eea58b231d1af7c0c8844deff (diff)
downloademacs-10a7615b5d45bcd909bb03d67423b337dfe93b1e.tar.gz
emacs-10a7615b5d45bcd909bb03d67423b337dfe93b1e.zip
Separate filename-deletion mechanism from policy.
src/fileio.c: (delete-file-internal) Renamed from delete-file, parallel to delete-directory-internal; policy code moved to Lisp. src/files.el: (delete-file) New function, holds policy logic. calls delete-file-internal. This is a pure refactoring step, delete-file's behavior is unchanged. But the C core is a little simpler now.
Diffstat (limited to 'src')
-rw-r--r--src/fileio.c40
1 files changed, 9 insertions, 31 deletions
diff --git a/src/fileio.c b/src/fileio.c
index 63f4e698528..e49a4a3836b 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -2462,38 +2462,13 @@ DEFUN ("delete-directory-internal", Fdelete_directory_internal,
2462 return Qnil; 2462 return Qnil;
2463} 2463}
2464 2464
2465DEFUN ("delete-file", Fdelete_file, Sdelete_file, 1, 2, 2465DEFUN ("delete-file-internal", Fdelete_file_internal, Sdelete_file_internal, 1, 1, 0,
2466 "(list (read-file-name \
2467 (if (and delete-by-moving-to-trash (null current-prefix-arg)) \
2468 \"Move file to trash: \" \"Delete file: \") \
2469 nil default-directory (confirm-nonexistent-file-or-buffer)) \
2470 (null current-prefix-arg))",
2471 doc: /* Delete file named FILENAME. If it is a symlink, remove the symlink. 2466 doc: /* Delete file named FILENAME. If it is a symlink, remove the symlink.
2472If file has multiple names, it continues to exist with the other names. 2467If file has multiple names, it continues to exist with the other names. */)
2473TRASH non-nil means to trash the file instead of deleting, provided 2468 (Lisp_Object filename)
2474`delete-by-moving-to-trash' is non-nil.
2475
2476When called interactively, TRASH is t if no prefix argument is given.
2477With a prefix argument, TRASH is nil. */)
2478 (Lisp_Object filename, Lisp_Object trash)
2479{ 2469{
2480 Lisp_Object handler;
2481 Lisp_Object encoded_file; 2470 Lisp_Object encoded_file;
2482 2471
2483 if (!NILP (Ffile_directory_p (filename))
2484 && NILP (Ffile_symlink_p (filename)))
2485 xsignal2 (Qfile_error,
2486 build_string ("Removing old name: is a directory"),
2487 filename);
2488 filename = Fexpand_file_name (filename, Qnil);
2489
2490 handler = Ffind_file_name_handler (filename, Qdelete_file);
2491 if (!NILP (handler))
2492 return call3 (handler, Qdelete_file, filename, trash);
2493
2494 if (delete_by_moving_to_trash && !NILP (trash))
2495 return call1 (Qmove_file_to_trash, filename);
2496
2497 encoded_file = ENCODE_FILE (filename); 2472 encoded_file = ENCODE_FILE (filename);
2498 2473
2499 if (unlink (SSDATA (encoded_file)) != 0 && errno != ENOENT) 2474 if (unlink (SSDATA (encoded_file)) != 0 && errno != ENOENT)
@@ -2725,7 +2700,7 @@ This is what happens in interactive use with M-x. */)
2725 if (dirp) 2700 if (dirp)
2726 call2 (Qdelete_directory, file, Qt); 2701 call2 (Qdelete_directory, file, Qt);
2727 else 2702 else
2728 Fdelete_file (file, Qnil); 2703 call2 (Qdelete_file, file, Qnil);
2729 return unbind_to (count, Qnil); 2704 return unbind_to (count, Qnil);
2730} 2705}
2731 2706
@@ -6346,7 +6321,7 @@ syms_of_fileio (void)
6346 DEFSYM (Qcopy_file, "copy-file"); 6321 DEFSYM (Qcopy_file, "copy-file");
6347 DEFSYM (Qmake_directory_internal, "make-directory-internal"); 6322 DEFSYM (Qmake_directory_internal, "make-directory-internal");
6348 DEFSYM (Qmake_directory, "make-directory"); 6323 DEFSYM (Qmake_directory, "make-directory");
6349 DEFSYM (Qdelete_file, "delete-file"); 6324 DEFSYM (Qdelete_file_internal, "delete-file-internal");
6350 DEFSYM (Qfile_name_case_insensitive_p, "file-name-case-insensitive-p"); 6325 DEFSYM (Qfile_name_case_insensitive_p, "file-name-case-insensitive-p");
6351 DEFSYM (Qrename_file, "rename-file"); 6326 DEFSYM (Qrename_file, "rename-file");
6352 DEFSYM (Qadd_name_to_file, "add-name-to-file"); 6327 DEFSYM (Qadd_name_to_file, "add-name-to-file");
@@ -6610,6 +6585,9 @@ This includes interactive calls to `delete-file' and
6610 delete_by_moving_to_trash = 0; 6585 delete_by_moving_to_trash = 0;
6611 DEFSYM (Qdelete_by_moving_to_trash, "delete-by-moving-to-trash"); 6586 DEFSYM (Qdelete_by_moving_to_trash, "delete-by-moving-to-trash");
6612 6587
6588 /* Lisp function for interactive file delete with trashing */
6589 DEFSYM (Qdelete_file, "delete-file");
6590
6613 /* Lisp function for moving files to trash. */ 6591 /* Lisp function for moving files to trash. */
6614 DEFSYM (Qmove_file_to_trash, "move-file-to-trash"); 6592 DEFSYM (Qmove_file_to_trash, "move-file-to-trash");
6615 6593
@@ -6641,7 +6619,7 @@ This includes interactive calls to `delete-file' and
6641 defsubr (&Scopy_file); 6619 defsubr (&Scopy_file);
6642 defsubr (&Smake_directory_internal); 6620 defsubr (&Smake_directory_internal);
6643 defsubr (&Sdelete_directory_internal); 6621 defsubr (&Sdelete_directory_internal);
6644 defsubr (&Sdelete_file); 6622 defsubr (&Sdelete_file_internal);
6645 defsubr (&Sfile_name_case_insensitive_p); 6623 defsubr (&Sfile_name_case_insensitive_p);
6646 defsubr (&Srename_file); 6624 defsubr (&Srename_file);
6647 defsubr (&Sadd_name_to_file); 6625 defsubr (&Sadd_name_to_file);