[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: dired-do-touch
From: |
Matthew Mundell |
Subject: |
Re: dired-do-touch |
Date: |
23 Mar 2004 21:48:19 +0000 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50 |
> Eli Zaretskii <address@hidden> writes:
>
> > > From: Matthew Mundell <address@hidden>
> > > Date: 22 Mar 2004 23:45:14 +0000
> > >
> > > + if (set_file_times (SDATA (encoded_absname), t, t) < 0)
> > > + report_file_error ("Setting file times", Fcons (absname, Qnil));
> >
> > I think this will throw an error on Windows if the file is a
> > directory. So it would be good to single out that case on DOS_NT
> > systems.
Does the version below correctly handle the case?
> > Otherwise, thanks a lot!
Thanks. Here are change logs and the Dired "T" key binding, to go with
yesterday's patches.
2004-03-23 Matthew Mundell <address@hidden>
* dired-aux.el (dired-touch, dired-do-touch): New defuns.
* dired.el: Bind dired-do-touch to T.
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/dired.el,v
diff -u -r1.273 dired.el
--- lisp/dired.el 23 Mar 2004 05:20:11 -0000 1.273
+++ lisp/dired.el 23 Mar 2004 12:17:57 -0000
@@ -909,6 +909,7 @@
(define-key map "Q" 'dired-do-query-replace-regexp)
(define-key map "R" 'dired-do-rename)
(define-key map "S" 'dired-do-symlink)
+ (define-key map "T" 'dired-do-touch)
(define-key map "X" 'dired-do-shell-command)
(define-key map "Z" 'dired-do-compress)
(define-key map "!" 'dired-do-shell-command)
2004-03-23 Matthew Mundell <address@hidden>
* fileio.c (Qset_file_times): New variable.
(Fset_file_times): New function.
(lisp_time_argument): New declaration.
(syms_of_fileio): staticpro and intern new variable, defsubr new
function.
* editfns.c (lisp_time_argument): Provide externally.
===================================================================
RCS file: /cvsroot/emacs/emacs/src/fileio.c,v
diff -u -r1.499 fileio.c
--- src/fileio.c 18 Mar 2004 02:58:45 -0000 1.499
+++ src/fileio.c 23 Mar 2004 12:56:40 -0000
@@ -323,6 +323,7 @@
Lisp_Object Qfile_accessible_directory_p;
Lisp_Object Qfile_modes;
Lisp_Object Qset_file_modes;
+Lisp_Object Qset_file_times;
Lisp_Object Qfile_newer_than_file_p;
Lisp_Object Qinsert_file_contents;
Lisp_Object Qwrite_region;
@@ -3438,7 +3439,66 @@
XSETINT (value, (~ realmask) & 0777);
return value;
}
+
+extern int lisp_time_argument P_ ((Lisp_Object, time_t *, int *));
+
+DEFUN ("set-file-times", Fset_file_times, Sset_file_times, 1, 2, 0,
+ doc: /* Set access and modification times of file FILENAME.
+If optional second argument TIME is supplied then it is used instead
+of the current time. TIME must be in the format of
+`current-time'. */)
+ (filename, time)
+ Lisp_Object filename, time;
+{
+ Lisp_Object absname, encoded_absname;
+ Lisp_Object handler;
+ time_t sec;
+ int usec;
+
+ if (! lisp_time_argument (time, &sec, &usec))
+ error ("Invalid time specification");
+
+ absname = Fexpand_file_name (filename, current_buffer->directory);
+
+ /* If the file name has special constructs in it,
+ call the corresponding file handler. */
+ handler = Ffind_file_name_handler (absname, Qset_file_times);
+ if (!NILP (handler))
+ return call3 (handler, Qset_file_times, absname, time);
+
+ encoded_absname = ENCODE_FILE (absname);
+
+ {
+ EMACS_TIME t;
+
+ EMACS_SET_SECS (t, sec);
+ EMACS_SET_USECS (t, usec);
+
+#ifdef WINDOWSNT
+ {
+ DWORD attributes;
+ Lisp_Object filename;
+ /* Ensure file is writable while its modified time is set. */
+ filename = SDATA (encoded_absname);
+ attributes = GetFileAttributes (filename);
+ SetFileAttributes (filename, attributes & ~FILE_ATTRIBUTE_READONLY);
+ if (set_file_times (filename, t, t))
+ {
+ /* Restore original attributes. */
+ SetFileAttributes (filename, attributes);
+ report_file_error ("Setting file times", Fcons (absname, Qnil));
+ }
+ /* Restore original attributes. */
+ SetFileAttributes (filename, attributes);
+ }
+#else
+ if (set_file_times (SDATA (encoded_absname), t, t))
+ report_file_error ("Setting file times", Fcons (absname, Qnil));
+#endif
+ }
+ return Qnil;
+}
#ifdef __NetBSD__
#define unix 42
@@ -6339,6 +6399,7 @@
Qfile_accessible_directory_p = intern ("file-accessible-directory-p");
Qfile_modes = intern ("file-modes");
Qset_file_modes = intern ("set-file-modes");
+ Qset_file_times = intern ("set-file-times");
Qfile_newer_than_file_p = intern ("file-newer-than-file-p");
Qinsert_file_contents = intern ("insert-file-contents");
Qwrite_region = intern ("write-region");
@@ -6372,6 +6433,7 @@
staticpro (&Qfile_accessible_directory_p);
staticpro (&Qfile_modes);
staticpro (&Qset_file_modes);
+ staticpro (&Qset_file_times);
staticpro (&Qfile_newer_than_file_p);
staticpro (&Qinsert_file_contents);
staticpro (&Qwrite_region);
@@ -6595,6 +6657,7 @@
defsubr (&Sfile_regular_p);
defsubr (&Sfile_modes);
defsubr (&Sset_file_modes);
+ defsubr (&Sset_file_times);
defsubr (&Sset_default_file_modes);
defsubr (&Sdefault_file_modes);
defsubr (&Sfile_newer_than_file_p);
Re: dired-do-touch, Lars Hansen, 2004/03/21
- Re: dired-do-touch, Matthew Mundell, 2004/03/22
- Re: dired-do-touch, Eli Zaretskii, 2004/03/23
- Re: dired-do-touch,
Matthew Mundell <=
- Re: dired-do-touch, Eli Zaretskii, 2004/03/24
- Re: dired-do-touch, Kim F. Storm, 2004/03/24
- Re: dired-do-touch, Eli Zaretskii, 2004/03/24
- Re: dired-do-touch, Kim F. Storm, 2004/03/24
- Re: dired-do-touch, Matthew Mundell, 2004/03/24
- Re: dired-do-touch, Eli Zaretskii, 2004/03/25
Re: dired-do-touch, Matthew Mundell, 2004/03/24
Re: dired-do-touch, Richard Stallman, 2004/03/24
Re: dired-do-touch, Matthew Mundell, 2004/03/26
Re: dired-do-touch, Richard Stallman, 2004/03/27