unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#6817: (Feature request w/ patch) wdired should create directories needed for destination files
@ 2010-08-06 21:26 Phil Sung
  2016-02-26  6:44 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 5+ messages in thread
From: Phil Sung @ 2010-08-06 21:26 UTC (permalink / raw)
  To: 6817

[-- Attachment #1: Type: text/plain, Size: 482 bytes --]

It is sometimes useful in wdired to be able to move files into
directories that don't yet exist, e.g. when one is reorganizing files
and directories. The attached patch (against git HEAD), based on
previous work by Joakim Verona (source:
http://www.emacswiki.org/emacs/WDired), makes wdired create parent
directories needed as necessary for the destination files, conditional
on the variable `wdired-create-parent-directories'.

What do others think of this feature?

Regards,
Phil

[-- Attachment #2: wdired-create-parent-directories.patch --]
[-- Type: text/x-patch, Size: 1661 bytes --]

diff --git a/lisp/wdired.el b/lisp/wdired.el
index 375bc26..c8997f3 100644
--- a/lisp/wdired.el
+++ b/lisp/wdired.el
@@ -168,6 +168,16 @@ program `dired-chmod-program', which must exist."
 		 (other :tag "Bits freely editable" advanced))
   :group 'wdired)
 
+(defcustom wdired-create-parent-directories nil
+  "If non-nil, create parent directories of destination files.
+
+If non-nil, when you rename a file to a destination path within a
+nonexistent directory, wdired will create any parent directories
+necessary. When nil, attempts to rename a file into a nonexistent
+directory will fail."
+  :type 'boolean
+  :group 'wdired)
+
 (defvar wdired-mode-map
   (let ((map (make-sparse-keymap)))
     (define-key map "\C-x\C-s" 'wdired-finish-edit)
@@ -478,6 +488,8 @@ non-nil means return old filename."
               (require 'dired-aux)
               (condition-case err
                   (let ((dired-backup-overwrite nil))
+                    (and wdired-create-parent-directories
+                         (wdired-create-parentdirs file-new))
                     (dired-rename-file file-ori file-new
                                        overwrite))
                 (error
@@ -487,6 +499,11 @@ non-nil means return old filename."
                             err)))))))))
     errors))
 
+(defun wdired-create-parentdirs (file-new)
+  "Create parent directories for FILE-NEW if they don't exist."
+  (and (not (file-exists-p (file-name-directory file-new)))
+       (message "Creating directory for file %s" file-new)
+       (make-directory (file-name-directory file-new) t)))
 
 (defun wdired-exit ()
   "Exit wdired and return to dired mode.

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* bug#6817: (Feature request w/ patch) wdired should create directories needed for destination files
  2010-08-06 21:26 bug#6817: (Feature request w/ patch) wdired should create directories needed for destination files Phil Sung
@ 2016-02-26  6:44 ` Lars Ingebrigtsen
  2016-02-26 17:49   ` Ingo Lohmar
  0 siblings, 1 reply; 5+ messages in thread
From: Lars Ingebrigtsen @ 2016-02-26  6:44 UTC (permalink / raw)
  To: Phil Sung; +Cc: 6817

Phil Sung <philbert@gmail.com> writes:

> It is sometimes useful in wdired to be able to move files into
> directories that don't yet exist, e.g. when one is reorganizing files
> and directories. The attached patch (against git HEAD), based on
> previous work by Joakim Verona (source:
> http://www.emacswiki.org/emacs/WDired), makes wdired create parent
> directories needed as necessary for the destination files, conditional
> on the variable `wdired-create-parent-directories'.
>
> What do others think of this feature?

[...]

> +(defcustom wdired-create-parent-directories nil
> +  "If non-nil, create parent directories of destination files.
> +
> +If non-nil, when you rename a file to a destination path within a
> +nonexistent directory, wdired will create any parent directories
> +necessary. When nil, attempts to rename a file into a nonexistent
> +directory will fail."
> +  :type 'boolean
> +  :group 'wdired)

[...]

> +(defun wdired-create-parentdirs (file-new)
> +  "Create parent directories for FILE-NEW if they don't exist."
> +  (and (not (file-exists-p (file-name-directory file-new)))
> +       (message "Creating directory for file %s" file-new)
> +       (make-directory (file-name-directory file-new) t)))

I think this makes sense, but I've used wdired very little, so I don't
quite have a handle on whether this is a use case that people would
like.  (And if so, the default should probably be t, here.)

Opinions?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#6817: (Feature request w/ patch) wdired should create directories needed for destination files
  2016-02-26  6:44 ` Lars Ingebrigtsen
@ 2016-02-26 17:49   ` Ingo Lohmar
  2016-02-27  0:51     ` John Wiegley
  0 siblings, 1 reply; 5+ messages in thread
From: Ingo Lohmar @ 2016-02-26 17:49 UTC (permalink / raw)
  To: Lars Ingebrigtsen, Phil Sung; +Cc: 6817

On Fri, Feb 26 2016 17:14 (+1030), Lars Ingebrigtsen wrote:

> Phil Sung <philbert@gmail.com> writes:
>
>> It is sometimes useful in wdired to be able to move files into
>> directories that don't yet exist, e.g. when one is reorganizing files
>> and directories. The attached patch (against git HEAD), based on
>> previous work by Joakim Verona (source:
>> http://www.emacswiki.org/emacs/WDired), makes wdired create parent
>> directories needed as necessary for the destination files, conditional
>> on the variable `wdired-create-parent-directories'.
>>
>> What do others think of this feature?
>
> [...]
>
>> +(defcustom wdired-create-parent-directories nil
>> +  "If non-nil, create parent directories of destination files.
>> +
>> +If non-nil, when you rename a file to a destination path within a
>> +nonexistent directory, wdired will create any parent directories
>> +necessary. When nil, attempts to rename a file into a nonexistent
>> +directory will fail."
>> +  :type 'boolean
>> +  :group 'wdired)
>
> [...]
>
>> +(defun wdired-create-parentdirs (file-new)
>> +  "Create parent directories for FILE-NEW if they don't exist."
>> +  (and (not (file-exists-p (file-name-directory file-new)))
>> +       (message "Creating directory for file %s" file-new)
>> +       (make-directory (file-name-directory file-new) t)))
>
> I think this makes sense, but I've used wdired very little, so I don't
> quite have a handle on whether this is a use case that people would
> like.  (And if so, the default should probably be t, here.)
>
> Opinions?



I've been running with this patch for years (though not extensively
using it), and it has never failed me.  I think this is a very useful
addition, and would also like the "t"-default, though that is not
essential..





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#6817: (Feature request w/ patch) wdired should create directories needed for destination files
  2016-02-26 17:49   ` Ingo Lohmar
@ 2016-02-27  0:51     ` John Wiegley
  2016-02-28  4:30       ` Lars Ingebrigtsen
  0 siblings, 1 reply; 5+ messages in thread
From: John Wiegley @ 2016-02-27  0:51 UTC (permalink / raw)
  To: Ingo Lohmar; +Cc: Lars Ingebrigtsen, Phil Sung, 6817

>>>>> Ingo Lohmar <i.lohmar@gmail.com> writes:

> I've been running with this patch for years (though not extensively using
> it), and it has never failed me. I think this is a very useful addition, and
> would also like the "t"-default, though that is not essential..

I think that having wdired DRTR with regard to what the renamed version of a
file should "mean" (i.e., if it implies the existence of directories that
don't yet exist, and so create them), sounds useful to me.


-- 
John Wiegley                  GPG fingerprint = 4710 CF98 AF9B 327B B80F
http://newartisans.com                          60E1 46C4 BD1A 7AC1 4BA2





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#6817: (Feature request w/ patch) wdired should create directories needed for destination files
  2016-02-27  0:51     ` John Wiegley
@ 2016-02-28  4:30       ` Lars Ingebrigtsen
  0 siblings, 0 replies; 5+ messages in thread
From: Lars Ingebrigtsen @ 2016-02-28  4:30 UTC (permalink / raw)
  To: John Wiegley; +Cc: Ingo Lohmar, 6817, John Wiegley, Phil Sung

John Wiegley <jwiegley@gmail.com> writes:

>>>>>> Ingo Lohmar <i.lohmar@gmail.com> writes:
>
>> I've been running with this patch for years (though not extensively using
>> it), and it has never failed me. I think this is a very useful addition, and
>> would also like the "t"-default, though that is not essential..
>
> I think that having wdired DRTR with regard to what the renamed version of a
> file should "mean" (i.e., if it implies the existence of directories that
> don't yet exist, and so create them), sounds useful to me.

Ok; I'll apply the patch to the trunk.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-02-28  4:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-06 21:26 bug#6817: (Feature request w/ patch) wdired should create directories needed for destination files Phil Sung
2016-02-26  6:44 ` Lars Ingebrigtsen
2016-02-26 17:49   ` Ingo Lohmar
2016-02-27  0:51     ` John Wiegley
2016-02-28  4:30       ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).