From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: Re: Minibuffer default values list Date: Mon, 12 Nov 2007 01:43:38 +0200 Organization: JURTA Message-ID: <874pfswepp.fsf@jurta.org> References: <87zlycuhrd.fsf@jurta.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1194824996 27605 80.91.229.12 (11 Nov 2007 23:49:56 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 11 Nov 2007 23:49:56 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Nov 12 00:50:00 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1IrMYr-0006Fc-Hr for ged-emacs-devel@m.gmane.org; Mon, 12 Nov 2007 00:49:54 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IrMYf-0008HH-ES for ged-emacs-devel@m.gmane.org; Sun, 11 Nov 2007 18:49:41 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IrMYc-0008Gk-2B for emacs-devel@gnu.org; Sun, 11 Nov 2007 18:49:38 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IrMYb-0008GN-4c for emacs-devel@gnu.org; Sun, 11 Nov 2007 18:49:37 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IrMYb-0008GK-0q for emacs-devel@gnu.org; Sun, 11 Nov 2007 18:49:37 -0500 Original-Received: from relay01.kiev.sovam.com ([62.64.120.200]) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1IrMYa-0004VX-5O for emacs-devel@gnu.org; Sun, 11 Nov 2007 18:49:36 -0500 Original-Received: from [83.170.232.243] (helo=smtp.svitonline.com) by relay01.kiev.sovam.com with esmtp (Exim 4.67) (envelope-from ) id 1IrMYY-0003U7-2C for emacs-devel@gnu.org; Mon, 12 Nov 2007 01:49:34 +0200 In-Reply-To: <87zlycuhrd.fsf@jurta.org> (Juri Linkov's message of "Mon, 22 Oct 2007 03:22:15 +0300") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.50 (gnu/linux) X-Scanner-Signature: 347b60a7d50e4b51b7e2953e35c97cdf X-DrWeb-checked: yes X-SpamTest-Envelope-From: juri@jurta.org X-SpamTest-Group-ID: 00000000 X-SpamTest-Header: Not Detected X-SpamTest-Info: Profiles 1761 [Nov 09 2007] X-SpamTest-Info: helo_type=3 X-SpamTest-Info: {HEADERS: header Content-Type found without required header Content-Transfer-Encoding} X-SpamTest-Method: none X-SpamTest-Rate: 19 X-SpamTest-Status: Not detected X-SpamTest-Status-Extended: not_detected X-SpamTest-Version: SMTP-Filter Version 3.0.0 [0255], KAS30/Release X-detected-kernel: by monty-python.gnu.org: FreeBSD 4.8-5.1 (or MacOS X 10.2-10.3) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:82988 Archived-At: 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))) ! (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))) ! (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)) ;;; 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)) ;;; 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/