;;; wdired.el --- Rename files editing their names in dired buffers
-;; Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
+;; Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
;; Filename: wdired.el
;; Author: Juan León Lahoz García <juanleon1@gmail.com>
;; This file is part of GNU Emacs.
-;; GNU Emacs is free software; you can redistribute it and/or
-;; modify it under the terms of the GNU General Public License as
-;; published by the Free Software Foundation; either version 2, or (at
-;; your option) any later version.
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
-;; This program is distributed in the hope that it will be useful, but
-;; WITHOUT ANY WARRANTY; without even the implied warranty of
-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-;; General Public License for more details.
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING. If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
(eval-when-compile (require 'cl))
(require 'dired)
(autoload 'dired-do-create-files-regexp "dired-aux")
-(autoload 'dired-call-process "dired-aux")
(defgroup wdired nil
"Mode to rename files by editing their names in dired buffers."
"If t, the \"up\" and \"down\" movement works as in Dired mode.
That is, always move the point to the beginning of the filename at line.
-If `sometimes, only move to the beginning of filename if the point is
-before it, and `track-eol' is honored. This behavior is very handy
+If `sometimes', only move to the beginning of filename if the point is
+before it, and `track-eol' is non-nil. This behavior is very handy
when editing several filenames.
If nil, \"up\" and \"down\" movement is done as in any other buffer."
you can keep the <x> key pressed to give execution permissions to
everybody to that file.
-If `advanced, the bits are freely editable. You can use
+If `advanced', the bits are freely editable. You can use
`string-rectangle', `query-replace', etc. You can put any value (even
newlines), but if you want your changes to be useful, you better put a
intelligible value.
(define-key map "\C-c\C-c" 'wdired-finish-edit)
(define-key map "\C-c\C-k" 'wdired-abort-changes)
(define-key map "\C-c\C-[" 'wdired-abort-changes)
+ (define-key map "\C-x\C-q" 'wdired-exit)
(define-key map "\C-m" 'ignore)
(define-key map "\C-j" 'ignore)
(define-key map "\C-o" 'ignore)
(unless (eq beg end)
(if old
(setq file (get-text-property beg 'old-name))
- (setq end (next-single-property-change (1+ beg) 'end-name))
+ ;; In the following form changed `(1+ beg)' to `beg' so that
+ ;; the filename end is found even when the filename is empty.
+ ;; Fixes error and spurious newlines when marking files for
+ ;; deletion.
+ (setq end (next-single-property-change beg 'end-name))
(setq file (buffer-substring-no-properties (1+ beg) end)))
(and file (setq file (wdired-normalize-filename file))))
(if (or no-dir old)
(set-buffer-modified-p nil)
(setq buffer-undo-list nil))
+(defun wdired-exit ()
+ "Exit wdired and return to dired mode.
+Just return to dired mode if there are no changes. Otherwise,
+ask a yes-or-no question whether to save or cancel changes,
+and proceed depending on the answer."
+ (interactive)
+ (if (buffer-modified-p)
+ (if (y-or-n-p (format "Buffer %s modified; save changes? "
+ (current-buffer)))
+ (wdired-finish-edit)
+ (wdired-abort-changes))
+ (wdired-change-to-dired-mode)
+ (set-buffer-modified-p nil)
+ (setq buffer-undo-list nil)
+ (message "(No changes need to be saved)")))
+
;; Rename a file, searching it in a modified dired buffer, in order
;; to be able to use `dired-do-create-files-regexp' and get its
;; "benefits".
(if (and
(buffer-modified-p)
(not (y-or-n-p "Buffer changed. Discard changes and kill buffer? ")))
- (error nil)))
+ (error "Error.")))
(defun wdired-next-line (arg)
"Move down lines then position at filename or the current column.
See `wdired-use-dired-vertical-movement'. Optional prefix ARG
says how many lines to move; default is one line."
(interactive "p")
- (next-line arg)
+ (with-no-warnings (next-line arg))
(if (or (eq wdired-use-dired-vertical-movement t)
(and wdired-use-dired-vertical-movement
(< (current-column)
See `wdired-use-dired-vertical-movement'. Optional prefix ARG
says how many lines to move; default is one line."
(interactive "p")
- (previous-line arg)
+ (with-no-warnings (previous-line arg))
(if (or (eq wdired-use-dired-vertical-movement t)
(and wdired-use-dired-vertical-movement
(< (current-column)
(if move (goto-char (1- beg)))))
(and target (wdired-normalize-filename target))))
+(declare-function make-symbolic-link "fileio.c")
;; Perform the changes in the target of the changed links.
(defun wdired-do-symlink-changes ()
(new-bit "-")
(pos-prop (- (point) (- (current-column) wdired-col-perm))))
(if (eq (char-after (point)) ?-)
- (setq new-bit
+ (setq new-bit
(if (= (% (- (current-column) wdired-col-perm) 3) 0) "r"
(if (= (% (- (current-column) wdired-col-perm) 3) 1) "w"
"x"))))
(progn
(setq perm-tmp
(int-to-string (wdired-perms-to-number perms-new)))
- (unless (equal 0 (dired-call-process dired-chmod-program
- t perm-tmp filename))
+ (unless (equal 0 (process-file dired-chmod-program
+ nil nil nil perm-tmp filename))
(setq errors (1+ errors))
(dired-log (concat dired-chmod-program " " perm-tmp
" `" filename "' failed\n\n"))))