From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Matthew Mundell Newsgroups: gmane.emacs.devel Subject: Re: dired-do-touch Date: 26 Mar 2004 18:31:13 +0000 Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <874qsbe9zi.fsf@sno.mundell.ukfsn.org> References: <20040321165848.0DB3C662F8@imf.math.ku.dk> <405DDAF3.2080608@math.ku.dk> <87vfkwbg51.fsf@sno.mundell.ukfsn.org> <877jxbqlp8.fsf@sno.mundell.ukfsn.org> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1080326061 17449 80.91.224.253 (26 Mar 2004 18:34:21 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 26 Mar 2004 18:34:21 +0000 (UTC) Cc: eliz@gnu.org, emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Fri Mar 26 19:34:08 2004 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1B6w9g-00022m-00 for ; Fri, 26 Mar 2004 19:34:08 +0100 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.35 #1 (Debian)) id 1B6w9f-00066F-01 for ; Fri, 26 Mar 2004 19:34:08 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.30) id 1B6w8I-0006fd-Tu for emacs-devel@quimby.gnus.org; Fri, 26 Mar 2004 13:32:42 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.30) id 1B6w86-0006eM-Oz for emacs-devel@gnu.org; Fri, 26 Mar 2004 13:32:30 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.30) id 1B6w7V-0006UF-Or for emacs-devel@gnu.org; Fri, 26 Mar 2004 13:32:29 -0500 Original-Received: from [217.158.120.143] (helo=mail.ukfsn.org) by monty-python.gnu.org with esmtp (Exim 4.30) id 1B6w6z-0006Kz-Vi; Fri, 26 Mar 2004 13:31:22 -0500 Original-Received: from localhost (lucy.ukfsn.org [127.0.0.1]) by mail.ukfsn.org (Postfix) with ESMTP id AEC1AE6DE1; Fri, 26 Mar 2004 18:30:30 +0000 (GMT) Original-Received: from mail.ukfsn.org ([127.0.0.1]) by localhost (lucy.ukfsn.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 05647-11; Fri, 26 Mar 2004 18:30:30 +0000 (GMT) Original-Received: from sno.mundell.ukfsn.org (dsl213-218-238-16.as15444.net [213.218.238.16]) by mail.ukfsn.org (Postfix) with ESMTP id 370E1E6D60; Fri, 26 Mar 2004 18:30:30 +0000 (GMT) Original-Received: from sno.mundell.ukfsn.org ([10.0.0.3]) by sno.mundell.ukfsn.org with esmtp (Exim 3.36 #1 (Debian)) id 1B6w6s-0000a1-00; Fri, 26 Mar 2004 18:31:14 +0000 Original-To: rms@gnu.org Original-Lines: 179 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.4 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:20970 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:20970 Richard Stallman writes: > The changes in dired.el and fileio.c look ok to me. > The changes in dired-aux.el were omitted. The changes to dired-aux.el were the same as in the original post. Here are all the changes, with change logs. Fset_file_times in fileio.c now silently ignores failures on DOS_NT systems, at Eli's suggestion, and returns t or nil, at Kim's suggestion. 2004-03-23 Matthew Mundell * fileio.c (Fset_file_times): New function. Suggested by Lars Hansen . (Qset_file_times): New variable. (lisp_time_argument): New declaration. (syms_of_fileio): staticpro and intern new variable, defsubr new function. * editfns.c (lisp_time_argument): Provide externally. 2004-03-23 Matthew Mundell * 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-aux.el,v diff -u -r1.115 dired-aux.el --- lisp/dired-aux.el 23 Mar 2004 07:39:35 -0000 1.115 +++ lisp/dired-aux.el 26 Mar 2004 16:32:37 -0000 @@ -2139,6 +2139,29 @@ (backward-delete-char 1)) (message "%s" (buffer-string)))) +(defun dired-touch () + "Touch current file. Return file name on failure, else nil." + (let ((file (dired-get-filename)) + fail) + (condition-case err + (set-file-times file (current-time)) + (error (setq fail err))) + (if fail + (progn + (dired-log "Setting time on `%s' failed:\n%s\n" + file fail) + (dired-make-relative file))))) + +;;;###autoload +(defun dired-do-touch (&optional arg) + "Set the selected files' access and mod times to the current time. + +With non-zero prefix argument ARG, the command operates on the +next ARG files. Otherwise, it operates on all the marked files, +or the current file if none are marked." + (interactive "P") + (dired-map-over-marks-check (function dired-touch) arg 'touch nil)) + (provide 'dired-aux) ;;; arch-tag: 4b508de9-a153-423d-8d3f-a1bbd86f4f60 =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/dired.el,v diff -u -r1.276 dired.el --- lisp/dired.el 25 Mar 2004 10:40:59 -0000 1.276 +++ lisp/dired.el 26 Mar 2004 16:31:59 -0000 @@ -919,6 +919,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) =================================================================== 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 26 Mar 2004 16:34:06 -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,59 @@ 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 times of file FILENAME to TIME. +Set both access and modification times. +Return t on success, else nil. +Use the current time if TIME is nil. TIME is 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); + + if (set_file_times (SDATA (encoded_absname), t, t)) + { +#ifdef DOS_NT + struct stat st; + /* Setting times on a directory always fails. */ + if (stat (SDATA (encoded_absname), &st) == 0 + && (st.st_mode & S_IFMT) == S_IFDIR) + return Qnil; +#endif + report_file_error ("Setting file times", Fcons (absname, Qnil)); + return Qnil; + } + } + + return Qt; +} #ifdef __NetBSD__ #define unix 42 @@ -6339,6 +6392,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 +6426,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 +6650,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);