all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@jurta.org>
To: emacs-devel@gnu.org
Subject: Re: Minibuffer default values list
Date: Mon, 12 Nov 2007 01:43:38 +0200	[thread overview]
Message-ID: <874pfswepp.fsf@jurta.org> (raw)
In-Reply-To: <87zlycuhrd.fsf@jurta.org> (Juri Linkov's message of "Mon, 22 Oct 2007 03:22:15 +0300")

Another useful place for multiple default "future" values in dired
are commands: M dired-do-chmod, O dired-do-chown, G dired-do-chgrp,
T dired-do-touch.  The patch below puts a list of file attributes of
marked files to the default list of these commands.  It also adds
file attributes of the file with the mark, so it makes easy to set
the same attributes to another file by putting the mark on one file
and selecting its attribute from the default list of these commands
run on another file.

Index: lisp/dired-aux.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/dired-aux.el,v
retrieving revision 1.157
diff -c -r1.157 dired-aux.el
*** lisp/dired-aux.el	9 Nov 2007 09:45:23 -0000	1.157
--- lisp/dired-aux.el	11 Nov 2007 23:43:01 -0000
***************
*** 207,236 ****
     (directory-files dir)))
  \f
  
! (defun dired-touch-initial (files)
!   "Create initial input value for `touch' command."
!   (let (initial)
!     (while files
!       (let ((current (nth 5 (file-attributes (car files)))))
!         (if (and initial (not (equal initial current)))
!             (setq initial (current-time) files nil)
!           (setq initial current))
!         (setq files (cdr files))))
!     (format-time-string "%Y%m%d%H%M.%S" initial)))
  
  (defun dired-do-chxxx (attribute-name program op-symbol arg)
    ;; Change file attributes (mode, group, owner, timestamp) of marked files and
    ;; refresh their file lines.
    ;; ATTRIBUTE-NAME is a string describing the attribute to the user.
    ;; PROGRAM is the program used to change the attribute.
!   ;; OP-SYMBOL is the type of operation (for use in dired-mark-pop-up).
!   ;; ARG describes which files to use, as in dired-get-marked-files.
    (let* ((files (dired-get-marked-files t arg))
  	 (new-attribute
  	  (dired-mark-read-string
  	   (concat "Change " attribute-name " of %s to: ")
  	   (if (eq op-symbol 'touch) (dired-touch-initial files))
! 	   op-symbol arg files))
  	 (operation (concat program " " new-attribute))
  	 failures)
      (setq failures
--- 207,269 ----
     (directory-files dir)))
  \f
  
! (defun dired-do-chxxx-default (op-symbol files)
!   "Return default values for the prompt in `dired-do-chxxx'.
! The argument FILES contains a list of marked files.  This function
! also adds the file at the mark to refer to its attributes in the
! default list.  If OP-SYMBOL is `chown' or `chgrp', return a list of
! unique UID or GID strings of all files.  If OP-SYMBOL is `touch',
! return a list of the current time and file timestamps in reverse
! chronological order."
!   (let* ((files
! 	  (delq nil (cons
! 		     ;; file at mark to use its attributes (like `touch -r')
! 		     (if (if transient-mark-mode mark-active (mark t))
! 			 (save-excursion (goto-char (mark t))
! 					 (dired-get-filename t t)))
! 		     ;; marked files
! 		     files))))
!     (cond
!      ((eq op-symbol 'chmod)
!       (sort (delete-dups
! 	     (mapcar (lambda (file) (format "%o" (file-modes file))) files))
! 	    'string-lessp))
!      ((or (eq op-symbol 'chown) (eq op-symbol 'chgrp))
!       (sort (delete-dups
! 	     (mapcar (lambda (file)
! 		       (let ((attr (nth (if (eq op-symbol 'chown) 2 3)
! 					(file-attributes file))))
! 			 (if (integerp attr)
! 			     (number-to-string attr)
! 			   attr)))
! 		     files))
! 	    'string-lessp))
!      ((eq op-symbol 'touch)
!       (nreverse
!        (sort
! 	(delete-dups
! 	 (mapcar (lambda (time) (format-time-string "%Y%m%d%H%M.%S" time))
! 		 (cons (current-time)
! 		       (mapcar (lambda (file)
! 				 (nth 5 (file-attributes file)))
! 			       files))))
! 	'string-lessp))))))
  
  (defun dired-do-chxxx (attribute-name program op-symbol arg)
    ;; Change file attributes (mode, group, owner, timestamp) of marked files and
    ;; refresh their file lines.
    ;; ATTRIBUTE-NAME is a string describing the attribute to the user.
    ;; PROGRAM is the program used to change the attribute.
!   ;; OP-SYMBOL is the type of operation (for use in `dired-mark-pop-up').
!   ;; ARG describes which files to use, as in `dired-get-marked-files'.
    (let* ((files (dired-get-marked-files t arg))
+          (default (dired-do-chxxx-default op-symbol files))
  	 (new-attribute
  	  (dired-mark-read-string
  	   (concat "Change " attribute-name " of %s to: ")
  	   (if (eq op-symbol 'touch) (dired-touch-initial files))
! 	   op-symbol arg files
! 	   default))
  	 (operation (concat program " " new-attribute))
  	 failures)
      (setq failures
***************
*** 256,264 ****
  Symbolic modes like `g+w' are allowed."
    (interactive "P")
    (let* ((files (dired-get-marked-files t arg))
  	 (modes (dired-mark-read-string
  		 "Change mode of %s to: " nil
! 		 'chmod arg files))
  	 (num-modes (if (string-match "^[0-7]+" modes)
  			(string-to-number modes 8))))
      (dolist (file files)
--- 289,299 ----
  Symbolic modes like `g+w' are allowed."
    (interactive "P")
    (let* ((files (dired-get-marked-files t arg))
+          (default (dired-do-chxxx-default 'chmod files))
  	 (modes (dired-mark-read-string
  		 "Change mode of %s to: " nil
! 		 'chmod arg files
! 		 default))
  	 (num-modes (if (string-match "^[0-7]+" modes)
  			(string-to-number modes 8))))
      (dolist (file files)
***************
*** 359,372 ****
  ;; If the current file was used, the list has but one element and ARG
  ;; does not matter. (It is non-nil, non-integer in that case, namely '(4)).
  
! (defun dired-mark-read-string (prompt initial op-symbol arg files)
    ;; PROMPT for a string, with INITIAL input.
    ;; Other args are used to give user feedback and pop-up:
    ;; OP-SYMBOL of command, prefix ARG, marked FILES.
    (dired-mark-pop-up
     nil op-symbol files
     (function read-string)
!    (format prompt (dired-mark-prompt arg files)) initial))
  \f
  ;;; Cleaning a directory: flagging some backups for deletion.
  
--- 394,407 ----
  ;; If the current file was used, the list has but one element and ARG
  ;; does not matter. (It is non-nil, non-integer in that case, namely '(4)).
  
! (defun dired-mark-read-string (prompt initial op-symbol arg files &optional default)
    ;; PROMPT for a string, with INITIAL input.
    ;; Other args are used to give user feedback and pop-up:
    ;; OP-SYMBOL of command, prefix ARG, marked FILES.
    (dired-mark-pop-up
     nil op-symbol files
     (function read-string)
!    (format prompt (dired-mark-prompt arg files)) initial nil default))
  \f
  ;;; Cleaning a directory: flagging some backups for deletion.
  
Index: lisp/files.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/files.el,v
retrieving revision 1.940
diff -c -r1.940 files.el
*** lisp/files.el	10 Nov 2007 17:20:37 -0000	1.940
--- lisp/files.el	11 Nov 2007 23:43:25 -0000
***************
*** 5516,5522 ****
  ORIG-FILE is the original file of which modes will be change."
    (let* ((modes (or (if orig-file (file-modes orig-file) 0)
  		    (error "File not found")))
! 	 (value (read-string (or prompt "File modes (octal or symbolic): "))))
      (save-match-data
        (if (string-match "^[0-7]+" value)
  	  (string-to-number value 8)
--- 5516,5523 ----
  ORIG-FILE is the original file of which modes will be change."
    (let* ((modes (or (if orig-file (file-modes orig-file) 0)
  		    (error "File not found")))
! 	 (value (read-string (or prompt "File modes (octal or symbolic): ")
! 			     nil nil (format "%o" modes))))
      (save-match-data
        (if (string-match "^[0-7]+" value)
  	  (string-to-number value 8)

-- 
Juri Linkov
http://www.jurta.org/emacs/

  parent reply	other threads:[~2007-11-11 23:43 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-22  0:22 Minibuffer default values list Juri Linkov
2007-10-23  7:12 ` Richard Stallman
2007-10-28 10:57   ` Juri Linkov
2007-11-11 23:42     ` Juri Linkov
2007-11-12  5:59       ` Richard Stallman
2007-11-16  1:27         ` Substitute ? in dired without surrounding whitespace (was: Minibuffer default values list) Juri Linkov
2007-11-17 23:30           ` Richard Stallman
2007-11-17 23:57             ` Substitute ? in dired without surrounding whitespace Juri Linkov
2007-11-18 22:46               ` Richard Stallman
2007-11-19  0:48         ` Minibuffer default values list Juri Linkov
2007-11-22  2:28           ` Richard Stallman
2007-11-22 19:02             ` Juri Linkov
2007-11-23  4:35               ` Richard Stallman
2007-11-24 17:54                 ` Juri Linkov
2007-11-25  3:43                   ` Richard Stallman
2007-11-25 15:18                     ` mb-pos.el (was: Minibuffer default values list) Juri Linkov
2007-12-02 21:27                       ` Richard Stallman
2007-12-03  0:34                         ` Minibuffer default values list Juri Linkov
2007-12-03 18:43                           ` Richard Stallman
2007-11-25 15:19                     ` Subject: mb-depth.el (was: Minibuffer default values list) Juri Linkov
2008-07-31 17:28                       ` Juri Linkov
2008-07-31 18:08                         ` Drew Adams
2008-07-31 18:24                           ` Juanma Barranquero
2008-07-31 18:35                             ` Drew Adams
2008-08-01 12:34                               ` Juanma Barranquero
2008-08-01 16:27                                 ` Drew Adams
2008-08-01 17:09                                   ` mb-depth.el patch Drew Adams
2008-08-04 13:13                                     ` Juanma Barranquero
2007-11-23  4:35               ` Minibuffer default values list Richard Stallman
2007-11-23 15:05                 ` Stefan Monnier
     [not found]                   ` <E1IvwoM-0004oD-AU@fencepost.gnu.org>
     [not found]                     ` <jwvwss5ptqv.fsf-monnier+emacs@gnu.org>
2007-12-03 18:42                       ` Richard Stallman
2007-11-19  0:52         ` Juri Linkov
2007-11-19 19:02           ` Richard Stallman
2007-11-23  0:48             ` Juri Linkov
2007-11-11 23:43 ` Juri Linkov [this message]
2007-11-12  5:59   ` Richard Stallman
2007-11-11 23:45 ` Juri Linkov
2007-11-12  5:59   ` Richard Stallman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874pfswepp.fsf@jurta.org \
    --to=juri@jurta.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.