emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Minibuffer default values list


From: Juri Linkov
Subject: Re: Minibuffer default values list
Date: Mon, 12 Nov 2007 01:43:38 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.50 (gnu/linux)

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/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]