all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] Add file-ring to dired-aux.el
@ 2024-10-21  8:11 Justin Fields
  2024-10-21  9:48 ` Eli Zaretskii
  2024-10-22 18:15 ` Juri Linkov
  0 siblings, 2 replies; 17+ messages in thread
From: Justin Fields @ 2024-10-21  8:11 UTC (permalink / raw)
  To: emacs-devel


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



[-- Attachment #1.2: Type: text/html, Size: 26 bytes --]

[-- Attachment #2: dired-file-ring.patch --]
[-- Type: text/x-patch, Size: 2815 bytes --]

From ca8f28008aeb95e74a0b5de28445cc25602ab724 Mon Sep 17 00:00:00 2001
From: Justin Fields <justinlime1999@gmail.com>
Date: Sun, 20 Oct 2024 22:54:57 -0500
Subject: [PATCH] Dired-Aux: add file ring to dired

* lisp/dired-aux.el
(dired-file-ring): New var.
(dired-file-ring-capture, dired-file-ring-clear)
(dired-file-ring-move, dired-file-ring-execute)
(dired-file-ring-copy, dired-file-ring-symlink)
(dired-file-ring-symlink-relative): New Functions
---
 lisp/dired-aux.el | 50 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el
index 7fe67eed1e0..0274e175d1b 100644
--- a/lisp/dired-aux.el
+++ b/lisp/dired-aux.el
@@ -3255,6 +3255,56 @@ Type \\`SPC' or \\`y' to %s one file, \\`DEL' or \\`n' to skip to next,
   (dired-rename-non-directory #'downcase "Rename downcase" arg))
 
 \f
+
+;;; File ring
+(defvar dired-file-ring nil
+  "Captured dired files.")
+
+(defun dired-file-ring-execute (action action-name file-list)
+  "Execute a function to run for every item in the FILE-LIST.
+Argument ACTION argument to call with `dired-create-files' with as
+its' FILE-CREATOR.
+Argument ACTION-NAME The name of the action, used for logging.
+Argument FILE-LIST List of files to preform ACTION on."
+  (dired-create-files action action-name file-list
+    (lambda (file) (concat default-directory (file-name-nondirectory (directory-file-name file)))))
+  (revert-buffer))
+
+(defun dired-file-ring-capture ()
+  "Capture marked Dired files to the file ring."
+  (interactive)
+  (mapc (lambda (file) (add-to-list 'dired-file-ring file)) (dired-get-marked-files))
+  (message "Captured %s Files. %s files are present in the file ring" (length (dired-get-marked-files)) (length dired-file-ring)))
+
+(defun dired-file-ring-clear ()
+  "Reset/clear the file ring."
+  (interactive)
+  (setq dired-file-ring nil))
+
+(defun dired-file-ring-move ()
+  "Move the file/s from the file ring to current dir.
+This action clears the file ring."
+  (interactive)
+  (dired-file-ring-execute #'rename-file "MOVE" dired-file-ring)
+  (dired-file-ring-clear))
+
+(defun dired-file-ring-copy ()
+  "Copy the file/s from the file ring to current dir."
+  (interactive)
+  (dired-file-ring-execute #'dired-copy-file "COPY" dired-file-ring))
+
+(defun dired-file-ring-symlink ()
+  "Create a symlink for the the file/s from the file ring to current dir."
+  (interactive)
+  (dired-file-ring-execute #'make-symbolic-link "SYM-LINK" dired-file-ring))
+
+(defun dired-file-ring-symlink-relative ()
+  "Create a relative symlink for the the file/s from the file ring to current dir."
+  (interactive)
+  (dired-file-ring-execute #'dired-make-relative-symlink "RELATIVE SYM-LINK" dired-file-ring))
+
+\f
+
 ;;; Insert subdirectory
 
 ;;;###autoload
-- 
2.46.0


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

* Re: [PATCH] Add file-ring to dired-aux.el
  2024-10-21  8:11 [PATCH] Add file-ring to dired-aux.el Justin Fields
@ 2024-10-21  9:48 ` Eli Zaretskii
  2024-10-21 10:14   ` Justin Fields
  2024-10-21 12:35   ` Michael Heerdegen via Emacs development discussions.
  2024-10-22 18:15 ` Juri Linkov
  1 sibling, 2 replies; 17+ messages in thread
From: Eli Zaretskii @ 2024-10-21  9:48 UTC (permalink / raw)
  To: Justin Fields; +Cc: emacs-devel

> From: Justin Fields <justinlime1999@gmail.com>
> Date: Mon, 21 Oct 2024 03:11:23 -0500
> 
> From ca8f28008aeb95e74a0b5de28445cc25602ab724 Mon Sep 17 00:00:00 2001
> From: Justin Fields <justinlime1999@gmail.com>
> Date: Sun, 20 Oct 2024 22:54:57 -0500
> Subject: [PATCH] Dired-Aux: add file ring to dired

Thanks.  Some comments below.  If someone else has comments, please
post them.

> +;;; File ring
> +(defvar dired-file-ring nil
> +  "Captured dired files.")

Why do you call this a "ring"?  AFAICT, it is a simple list, created
and used as such.

> +(defun dired-file-ring-execute (action action-name file-list)
> +  "Execute a function to run for every item in the FILE-LIST.

The first line of a doc string should preferably mention all of the
mandatory arguments.

> +Argument ACTION argument to call with `dired-create-files' with as
> +its' FILE-CREATOR.

This reads awkwardly due to lack of punctuation.  Our usual style is
to say

  ACTION is passed to `dired-create-files' as its FILE-CREATOR
  argument.

Same comment for the other arguments.

> +Argument ACTION-NAME The name of the action, used for logging.

This should say "...for error logging by `dired-create-files'.", so
that readers could look up that logging.

> +  (dired-create-files action action-name file-list
> +    (lambda (file) (concat default-directory (file-name-nondirectory (directory-file-name file)))))

Why does this use 'concat' instead of 'expand-file-name'?

> +(defun dired-file-ring-capture ()
> +  "Capture marked Dired files to the file ring."
> +  (interactive)
> +  (mapc (lambda (file) (add-to-list 'dired-file-ring file)) (dired-get-marked-files))
> +  (message "Captured %s Files. %s files are present in the file ring" (length (dired-get-marked-files)) (length dired-file-ring)))

This will say "Captured 1 Files", which is incorrect English.  Please
use ngettext to do this better.

My suggestion is to rephrase this message to say something like

  %s files now in `file-ring', %s added

This makes the message much shorter and easier to understand, IMO.

> +(defun dired-file-ring-move ()
> +  "Move the file/s from the file ring to current dir.

By "current dir" do you mean default-directory?  We don't use the term
"current directory" in Emacs because Emacs pretends that each buffer
has its own "current directory".

> +This action clears the file ring."
> +  (interactive)
> +  (dired-file-ring-execute #'rename-file "MOVE" dired-file-ring)
> +  (dired-file-ring-clear))

What happens with files in subdirectories, e.g., if the user typed 'i'
before marking files?  Does this command create the corresponding
subdirectories in the default-directory when it moves the files?

> +(defun dired-file-ring-copy ()
> +  "Copy the file/s from the file ring to current dir."
> +  (interactive)
> +  (dired-file-ring-execute #'dired-copy-file "COPY" dired-file-ring))

Same question here.

> +(defun dired-file-ring-symlink ()
> +  "Create a symlink for the the file/s from the file ring to current dir."
> +  (interactive)
> +  (dired-file-ring-execute #'make-symbolic-link "SYM-LINK" dired-file-ring))
> +
> +(defun dired-file-ring-symlink-relative ()
> +  "Create a relative symlink for the the file/s from the file ring to current dir."
> +  (interactive)
> +  (dired-file-ring-execute #'dired-make-relative-symlink "RELATIVE SYM-LINK" dired-file-ring))

The doc strings of these two commands should be more explicit
regarding which file is the symlink and what will be its target.

This feature, when installed, will need a NEWS entry.

Finally, to accept a contribution of this size we need you to sign the
copyright assignment agreement.  Would you like to start this legal
paperwork rolling at this time?  If yes, I will send you the form to
fill and the instructions to go with it.



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

* Re: [PATCH] Add file-ring to dired-aux.el
  2024-10-21  9:48 ` Eli Zaretskii
@ 2024-10-21 10:14   ` Justin Fields
  2024-10-21 10:38     ` Eli Zaretskii
  2024-10-21 12:35   ` Michael Heerdegen via Emacs development discussions.
  1 sibling, 1 reply; 17+ messages in thread
From: Justin Fields @ 2024-10-21 10:14 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

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

Hi there, Thanks for taking a look.

Apologies for the sloppiness you pointed out, this was originally targeted
for the MELPA, but I was advised that this could be useful functionality in
mainline, so this is my first time attempting to contribute directly to
emacs :)

> Why do you call this a "ring"?  AFAICT, it is a simple list, created
> and used as such.

To be perfectly honest, it was just the first thing that came to mind to
help distinguish this feature. If anybody has any better suggestions I can
append accordingly.

> Why does this use 'concat' instead of 'expand-file-name'?
The (file-name-nondirectory (directory-file-name file)) in the snippet
returns a bare filename. I use concat here to set the destination as an
identical filename, in the default-directory.

> What happens with files in subdirectories, e.g., if the user typed 'i'
> before marking files?  Does this command create the corresponding
> subdirectories in the default-directory when it moves the files?
Yes, the files have their actions performed recursively, so all subdirs are
created as well.

I have noticed just now though, in your example, default-directory remains
unchanged, but it looks like if I swap to (dired-current-directory)
instead, it should be resolved properly when in a subdir. Thanks for
catching that.

I'll also work on amending all the documentation mistakes you pointed out
as well.

> This feature, when installed, will need a NEWS entry.
I might just not be looking hard enough, but do you have any resources
available that I could look into for this? :)

> Finally, to accept a contribution of this size we need you to sign the
> copyright assignment agreement.  Would you like to start this legal
> paperwork rolling at this time?  If yes, I will send you the form to
> fill and the instructions to go with it.

Of course! Very much appreciated.

On Mon, Oct 21, 2024 at 4:48 AM Eli Zaretskii <eliz@gnu.org> wrote:

> > From: Justin Fields <justinlime1999@gmail.com>
> > Date: Mon, 21 Oct 2024 03:11:23 -0500
> >
> > From ca8f28008aeb95e74a0b5de28445cc25602ab724 Mon Sep 17 00:00:00 2001
> > From: Justin Fields <justinlime1999@gmail.com>
> > Date: Sun, 20 Oct 2024 22:54:57 -0500
> > Subject: [PATCH] Dired-Aux: add file ring to dired
>
> Thanks.  Some comments below.  If someone else has comments, please
> post them.
>
> > +;;; File ring
> > +(defvar dired-file-ring nil
> > +  "Captured dired files.")
>
> Why do you call this a "ring"?  AFAICT, it is a simple list, created
> and used as such.
>
> > +(defun dired-file-ring-execute (action action-name file-list)
> > +  "Execute a function to run for every item in the FILE-LIST.
>
> The first line of a doc string should preferably mention all of the
> mandatory arguments.
>
> > +Argument ACTION argument to call with `dired-create-files' with as
> > +its' FILE-CREATOR.
>
> This reads awkwardly due to lack of punctuation.  Our usual style is
> to say
>
>   ACTION is passed to `dired-create-files' as its FILE-CREATOR
>   argument.
>
> Same comment for the other arguments.
>
> > +Argument ACTION-NAME The name of the action, used for logging.
>
> This should say "...for error logging by `dired-create-files'.", so
> that readers could look up that logging.
>
> > +  (dired-create-files action action-name file-list
> > +    (lambda (file) (concat default-directory (file-name-nondirectory
> (directory-file-name file)))))
>
> Why does this use 'concat' instead of 'expand-file-name'?
>
> > +(defun dired-file-ring-capture ()
> > +  "Capture marked Dired files to the file ring."
> > +  (interactive)
> > +  (mapc (lambda (file) (add-to-list 'dired-file-ring file))
> (dired-get-marked-files))
> > +  (message "Captured %s Files. %s files are present in the file ring"
> (length (dired-get-marked-files)) (length dired-file-ring)))
>
> This will say "Captured 1 Files", which is incorrect English.  Please
> use ngettext to do this better.
>
> My suggestion is to rephrase this message to say something like
>
>   %s files now in `file-ring', %s added
>
> This makes the message much shorter and easier to understand, IMO.
>
> > +(defun dired-file-ring-move ()
> > +  "Move the file/s from the file ring to current dir.
>
> By "current dir" do you mean default-directory?  We don't use the term
> "current directory" in Emacs because Emacs pretends that each buffer
> has its own "current directory".
>
> > +This action clears the file ring."
> > +  (interactive)
> > +  (dired-file-ring-execute #'rename-file "MOVE" dired-file-ring)
> > +  (dired-file-ring-clear))
>
> What happens with files in subdirectories, e.g., if the user typed 'i'
> before marking files?  Does this command create the corresponding
> subdirectories in the default-directory when it moves the files?
>
> > +(defun dired-file-ring-copy ()
> > +  "Copy the file/s from the file ring to current dir."
> > +  (interactive)
> > +  (dired-file-ring-execute #'dired-copy-file "COPY" dired-file-ring))
>
> Same question here.
>
> > +(defun dired-file-ring-symlink ()
> > +  "Create a symlink for the the file/s from the file ring to current
> dir."
> > +  (interactive)
> > +  (dired-file-ring-execute #'make-symbolic-link "SYM-LINK"
> dired-file-ring))
> > +
> > +(defun dired-file-ring-symlink-relative ()
> > +  "Create a relative symlink for the the file/s from the file ring to
> current dir."
> > +  (interactive)
> > +  (dired-file-ring-execute #'dired-make-relative-symlink "RELATIVE
> SYM-LINK" dired-file-ring))
>
> The doc strings of these two commands should be more explicit
> regarding which file is the symlink and what will be its target.
>
> This feature, when installed, will need a NEWS entry.
>
> Finally, to accept a contribution of this size we need you to sign the
> copyright assignment agreement.  Would you like to start this legal
> paperwork rolling at this time?  If yes, I will send you the form to
> fill and the instructions to go with it.
>

[-- Attachment #2: Type: text/html, Size: 7429 bytes --]

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

* Re: [PATCH] Add file-ring to dired-aux.el
  2024-10-21 10:14   ` Justin Fields
@ 2024-10-21 10:38     ` Eli Zaretskii
  2024-10-28 10:31       ` Björn Bidar
       [not found]       ` <87v7xctt6p.fsf@>
  0 siblings, 2 replies; 17+ messages in thread
From: Eli Zaretskii @ 2024-10-21 10:38 UTC (permalink / raw)
  To: Justin Fields; +Cc: emacs-devel

> From: Justin Fields <justinlime1999@gmail.com>
> Date: Mon, 21 Oct 2024 05:14:52 -0500
> Cc: emacs-devel@gnu.org
> 
> > Why do you call this a "ring"?  AFAICT, it is a simple list, created
> > and used as such.
> 
> To be perfectly honest, it was just the first thing that came to mind to help distinguish this feature. If anybody
> has any better suggestions I can append accordingly.

Something like dired-marked-files?

> > Why does this use 'concat' instead of 'expand-file-name'?
> The (file-name-nondirectory (directory-file-name file)) in the snippet returns a bare filename. I use concat here
> to set the destination as an identical filename, in the default-directory.

If you use expand-file-name, you will also get correct results.

> > This feature, when installed, will need a NEWS entry.
> I might just not be looking hard enough, but do you have any resources available that I could look into for
> this? :)

Just look at etc/NEWS and see how we announce new features and
commands there.

> > Finally, to accept a contribution of this size we need you to sign the
> > copyright assignment agreement.  Would you like to start this legal
> > paperwork rolling at this time?  If yes, I will send you the form to
> > fill and the instructions to go with it.
> 
> Of course! Very much appreciated. 

Form sent off-list.  Thank you for your interest in Emacs.



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

* Re: [PATCH] Add file-ring to dired-aux.el
  2024-10-21  9:48 ` Eli Zaretskii
  2024-10-21 10:14   ` Justin Fields
@ 2024-10-21 12:35   ` Michael Heerdegen via Emacs development discussions.
  1 sibling, 0 replies; 17+ messages in thread
From: Michael Heerdegen via Emacs development discussions. @ 2024-10-21 12:35 UTC (permalink / raw)
  To: emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

> > From: Justin Fields <justinlime1999@gmail.com>
> > Date: Sun, 20 Oct 2024 22:54:57 -0500
> > Subject: [PATCH] Dired-Aux: add file ring to dired
>
> Thanks.  Some comments below.  If someone else has comments, please
> post them.

I would like to know about typical use cases.  How is this better than
just invoking actions directly from another dired buffer?  Does it make
what one might want to do when multiple buffers are involved more
convenient?  How?

Privately I am using registers to save selections of files.  Registers
have the advantage that you can have more than one selection.  I am
using these selections totally differently, though: to restore marks or
to open a file listing in a separate dedicated buffer.

Michael.




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

* Re: [PATCH] Add file-ring to dired-aux.el
@ 2024-10-21 15:05 Justin Fields
  2024-10-22 15:53 ` Michael Heerdegen
  0 siblings, 1 reply; 17+ messages in thread
From: Justin Fields @ 2024-10-21 15:05 UTC (permalink / raw)
  To: michael_heerdegen@web.de, emacs-devel@gnu.org

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

> ​I would like to know about typical use cases.  How is this better than
> just invoking actions directly from another dired buffer?  Does it make
> what one might want to do when multiple buffers are involved more
> convenient?  How?

Hi there,

You can see some of our discussion on the use case on my MELPA PR:
https://github.com/melpa/melpa/pull/9207

But, to summarize, the general idea is that you capture files into the list, in which you can perform actions with them LATER. This also forgoes the need
of having multiple visible dired buffers present in the first place.

Furthermore, this allows for more explicit behavior of these actions in the event of having more than two dired buffers present on the frame
at once. This also means that you do not have to rely on the implicit behavior or dired-dwim-target (which requires cycling actions, if the
implied directory is not the intended one).

Lastly, this allows for the user to perform these actions, multiple times. (In the case of the symlink, symlink-relative, and copy functions)
As in, they can copy the captured files into one buffer, then move to another buffer and copy the same set again. So on, an so forth.


[-- Attachment #2: Type: text/html, Size: 5108 bytes --]

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

* Re: [PATCH] Add file-ring to dired-aux.el
  2024-10-21 15:05 Justin Fields
@ 2024-10-22 15:53 ` Michael Heerdegen
  0 siblings, 0 replies; 17+ messages in thread
From: Michael Heerdegen @ 2024-10-22 15:53 UTC (permalink / raw)
  To: Justin Fields; +Cc: emacs-devel@gnu.org

Justin Fields <justinlime1999@gmail.com> writes:

> But, to summarize, the general idea is that you capture files into the
> list, in which you can perform actions with them LATER. This also
> forgoes the need
> of having multiple visible dired buffers present in the first place.
> [...]

Thanks.  This is a bit similar to how selections work in file managers.

But - wouldn't a dedicated dired buffer listing exactly those files not
be more intuitive?  Instead of adding a bunch of new commands operating
on the remembered files you could just use the "normal" dired commands.


Michael.



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

* Re: [PATCH] Add file-ring to dired-aux.el
  2024-10-21  8:11 [PATCH] Add file-ring to dired-aux.el Justin Fields
  2024-10-21  9:48 ` Eli Zaretskii
@ 2024-10-22 18:15 ` Juri Linkov
  2024-10-22 18:43   ` Eli Zaretskii
  2024-10-22 22:24   ` [External] : " Drew Adams
  1 sibling, 2 replies; 17+ messages in thread
From: Juri Linkov @ 2024-10-22 18:15 UTC (permalink / raw)
  To: Justin Fields; +Cc: emacs-devel

> * lisp/dired-aux.el
> (dired-file-ring): New var.
> (dired-file-ring-capture, dired-file-ring-clear)
> (dired-file-ring-move, dired-file-ring-execute)
> (dired-file-ring-copy, dired-file-ring-symlink)
> (dired-file-ring-symlink-relative): New Functions

Thanks, this is a much welcome feature since it adds Dired
operations that are more in line with most file managers.
Let's try to implement the best UI in line with Emacs
conventions.  Currently copying/moving pops up a window
"*Marked Files*" where the user can inspect the list
of files and confirm before starting the process.
Doing the same could be like the following:

1. Copy the file names of marked files with 'w'.
2. In another dired buffer type 'C-y' (yank)
   like suggested by Drew.

Then it could pop up the standard window "*Marked Files*"
and ask for a choice from the list of characters
using 'map-y-or-n-p' or 'read-answer', e.g.:

(read-answer "Choose what to do with marked files "
  '(("copy" ?c "copy")
    ("move" ?r "move")
    ("symlink" ?s "make symlink")
    ("relsymlink" ?y "make relative symlink")))



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

* Re: [PATCH] Add file-ring to dired-aux.el
  2024-10-22 18:15 ` Juri Linkov
@ 2024-10-22 18:43   ` Eli Zaretskii
  2024-10-23  6:47     ` Justin Fields
  2024-10-22 22:24   ` [External] : " Drew Adams
  1 sibling, 1 reply; 17+ messages in thread
From: Eli Zaretskii @ 2024-10-22 18:43 UTC (permalink / raw)
  To: Juri Linkov; +Cc: justinlime1999, emacs-devel

> From: Juri Linkov <juri@linkov.net>
> Cc: emacs-devel@gnu.org
> Date: Tue, 22 Oct 2024 21:15:56 +0300
> 
> Doing the same could be like the following:
> 
> 1. Copy the file names of marked files with 'w'.

Please, either C-w or M-w.

> 2. In another dired buffer type 'C-y' (yank)
>    like suggested by Drew.
> 
> Then it could pop up the standard window "*Marked Files*"
> and ask for a choice from the list of characters
> using 'map-y-or-n-p' or 'read-answer', e.g.:
> 
> (read-answer "Choose what to do with marked files "
>   '(("copy" ?c "copy")
>     ("move" ?r "move")
>     ("symlink" ?s "make symlink")
>     ("relsymlink" ?y "make relative symlink")))

If we want to be "like most file managers", we need to show buttons on
the tool bar or pop up a menu, not just ask for a key with
read-answer.



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

* RE: [External] : Re: [PATCH] Add file-ring to dired-aux.el
  2024-10-22 18:15 ` Juri Linkov
  2024-10-22 18:43   ` Eli Zaretskii
@ 2024-10-22 22:24   ` Drew Adams
  2024-10-26  7:02     ` Eshel Yaron
  1 sibling, 1 reply; 17+ messages in thread
From: Drew Adams @ 2024-10-22 22:24 UTC (permalink / raw)
  To: Juri Linkov, Justin Fields; +Cc: emacs-devel@gnu.org

> Currently copying/moving pops up a window
> "*Marked Files*" where the user can inspect the list
> of files and confirm before starting the process.
> Doing the same could be like the following:
> 
> 1. Copy the file names of marked files with 'w'.
> 2. In another dired buffer type 'C-y' (yank)
>    like suggested by Drew.

`C-y' in Dired+ also lets you (with a prefix arg) copy
the files to any directory, whether or not it has a
Dired buffer.  There's no need limit the use of such
a file-name list to Dired.

And `C-w' in Dired+ moves, instead of copies, the files
whose names you copied with `w'.  Again, you can use a
prefix arg to move the files to any directory - the
command isn't limited to use in Dired.

> Then it could pop up the standard window "*Marked Files*"
> and ask for a choice from the list of characters
> using 'map-y-or-n-p' or 'read-answer', e.g.:
> 
> (read-answer "Choose what to do with marked files "
>   '(("copy" ?c "copy")
>     ("move" ?r "move")
>     ("symlink" ?s "make symlink")
>     ("relsymlink" ?y "make relative symlink")))

Dired+ doesn't have anything particular for symlinking
the copied file names.

If you do that, I suggest you do as I did for copy/move:
let users optionally specify a target directory with
completion, and perform the action even outside of Dired.
___

Overall:

1. Vanilla Dired already has `w' (Eli: not `C-w' or
`M-w' - `w' is as old Emacs 22) to copy the marked
file names.

In Dired+ the command respects option
`diredp-quote-copied-filenames-flag' instead of always
quoting file names that contain SPC, ' or ".  And it
uses a separator string defined in a variable, instead
of just a SPC char.  By default it's a string with just
a null char ("\0").

2. The string of file names is saved not only on the
kill ring, but also in a variable - you need not dig it
out of the kill ring to use it.

3. For yanking (`C-y'), the clipboard is checked first,
so MS Windows users can use file names copied to the
clipboard using Windows Explorer (or whatever).

4. To be useful for things such as Juri suggests above,
you want the copied names to be _absolute_ file names.

That's what command `diredp-copy-abs-filenames-as-kill'
does, and it's what a 0 numeric prefix arg (e.g. `M-0')
does for `w' (command `dired-copy-filename-as-kill') in
Dired+.
____


(Yes, there could also be register commands to do the
same things...)



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

* Re: [PATCH] Add file-ring to dired-aux.el
  2024-10-22 18:43   ` Eli Zaretskii
@ 2024-10-23  6:47     ` Justin Fields
  0 siblings, 0 replies; 17+ messages in thread
From: Justin Fields @ 2024-10-23  6:47 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Juri Linkov, emacs-devel


[-- Attachment #1.1: Type: text/plain, Size: 1684 bytes --]

Hi Friends,

I've made some changes, and I believe I've addressed all the docstring
issues and grammatical errors. I'll attach it here.

I've also renamed the concept as just "dired-captured" since as Eli pointed
out, it is just a list rather than a ring.

As Juri suggested, I've also added a buffer pop-up similar to
`dired-do-delete' to show the captured files staged for the given
operation, and prompt for confirmation, seeing as how there might not be
any visual feedback
if the original dired-buffer that the files were captured from is no longer
visible.

I've also changed the original destination target of `default-directory' to
instead be `dired-current-directory' to comply with subdirectories.

On Tue, Oct 22, 2024 at 1:43 PM Eli Zaretskii <eliz@gnu.org> wrote:

> > From: Juri Linkov <juri@linkov.net>
> > Cc: emacs-devel@gnu.org
> > Date: Tue, 22 Oct 2024 21:15:56 +0300
> >
> > Doing the same could be like the following:
> >
> > 1. Copy the file names of marked files with 'w'.
>
> Please, either C-w or M-w.
>
> > 2. In another dired buffer type 'C-y' (yank)
> >    like suggested by Drew.
> >
> > Then it could pop up the standard window "*Marked Files*"
> > and ask for a choice from the list of characters
> > using 'map-y-or-n-p' or 'read-answer', e.g.:
> >
> > (read-answer "Choose what to do with marked files "
> >   '(("copy" ?c "copy")
> >     ("move" ?r "move")
> >     ("symlink" ?s "make symlink")
> >     ("relsymlink" ?y "make relative symlink")))
>
> If we want to be "like most file managers", we need to show buttons on
> the tool bar or pop up a menu, not just ask for a key with
> read-answer.
>

[-- Attachment #1.2: Type: text/html, Size: 2508 bytes --]

[-- Attachment #2: dired-captured.patch --]
[-- Type: text/x-patch, Size: 3881 bytes --]

From 47ad7227113aed4ea6f99dc7f12c3519654f043a Mon Sep 17 00:00:00 2001
From: Justin Fields <justinlime1999@gmail.com>
Date: Sun, 20 Oct 2024 22:54:57 -0500
Subject: [PATCH] Dired-Aux: add captured file list and operations

* lisp/dired-aux.el
(dired-captured-files): New var.
(dired-capture-files, dired-captured-clear)
(dired-captured-move, dired-captured-execute)
(dired-captured-copy, dired-captured-symlink)
(dired-captured-symlink-relative): New Functions
---
 lisp/dired-aux.el | 67 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 67 insertions(+)

diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el
index 7fe67eed1e0..79d92594c3b 100644
--- a/lisp/dired-aux.el
+++ b/lisp/dired-aux.el
@@ -3255,6 +3255,73 @@ Type \\`SPC' or \\`y' to %s one file, \\`DEL' or \\`n' to skip to next,
   (dired-rename-non-directory #'downcase "Rename downcase" arg))
 
 \f
+
+;;; Captured Files
+
+(defvar dired-captured-files nil
+  "List of captured Dired files.")
+
+(defun dired-capture-files ()
+  "Capture marked Dired files into `dired-captured-files'."
+  (interactive)
+  (mapc (lambda (file) (add-to-list 'dired-captured-files file)) (dired-get-marked-files))
+  (let* ((added (length (dired-get-marked-files)))
+         (total (length dired-captured-files))
+         (msg (ngettext "file is" "files are" total)))
+    (message "%d %s now captured [%s added]." total msg added)))
+
+(defun dired-captured-clear ()
+  "Empty the `dired-captured-files' list."
+  (interactive)
+  (setq dired-captured-files nil)
+  (message "Emptied the capture file list."))
+
+(defun dired-captured-execute (file-creator operation marker-char)
+  "Apply provided FILE-CREATOR, OPERATION, and MARKER-CHAR to `dired-create-files' as their respective arguments.
+
+Applies the `FILE-CREATOR' to every filename present in `dired-captured-files', with the destination
+being resolved to `dired-current-directory'.
+"
+  (if (length= dired-captured-files 0)
+    (message "No captured files to operate on.")
+    (if (not (dired-mark-pop-up " *Captured Files*" nil dired-captured-files #'yes-or-no-p
+                                (format 
+                                  (ngettext "%s [%d file]" "%s [%d files]" (length dired-captured-files))
+                                    operation (length dired-captured-files))))
+      (message "%s aborted." operation)
+      ;; prevent dired-create-files from mutating the capture list.
+      (let ((fn-list (copy-sequence dired-captured-files)))
+        (dired-create-files file-creator operation fn-list
+          (lambda (file) (expand-file-name (file-name-nondirectory (directory-file-name file)) (dired-current-directory))) marker-char))
+      (revert-buffer))))
+
+(defun dired-captured-move ()
+  "Move the file/s from `dired-captured' to `dired-current-directory'."
+  (interactive)
+  (dired-captured-execute #'rename-file "MOVE" ?M)
+  ;; keep the files usable in the ring for other actions, by remapping the base filenames to `dired-current-directory' 
+  (setq dired-captured-files
+    (mapcar (lambda (file) (expand-file-name (file-name-nondirectory (directory-file-name file)) (dired-current-directory))) dired-captured-files)))
+
+(defun dired-captured-copy ()
+  "Copy the file/s from `dired-captured' to `dired-current-directory'."
+  (interactive)
+  (dired-captured-execute #'dired-copy-file "COPY" ?C))
+
+(defun dired-captured-symlink ()
+  "Create a symlink to the file/s from `dired-captured'
+to `dired-current-directory'."
+  (interactive)
+  (dired-captured-execute #'make-symbolic-link "SYM-LINK" ?S))
+
+(defun dired-captured-relative-symlink ()
+  "Create a relative symlink to the file/s from `dired-captured'
+to `dired-current-directory'."
+  (interactive)
+  (dired-captured-execute #'dired-make-relative-symlink "RELATIVE SYM-LINK" ?R))
+
+\f
+
 ;;; Insert subdirectory
 
 ;;;###autoload
-- 
2.46.0


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

* Re: [External] : Re: [PATCH] Add file-ring to dired-aux.el
  2024-10-22 22:24   ` [External] : " Drew Adams
@ 2024-10-26  7:02     ` Eshel Yaron
  2024-10-27  7:47       ` Juri Linkov
  0 siblings, 1 reply; 17+ messages in thread
From: Eshel Yaron @ 2024-10-26  7:02 UTC (permalink / raw)
  To: Drew Adams; +Cc: Juri Linkov, Justin Fields, emacs-devel@gnu.org

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

Hi,

Drew Adams <drew.adams@oracle.com> writes:

>> Currently copying/moving pops up a window
>> "*Marked Files*" where the user can inspect the list
>> of files and confirm before starting the process.
>> Doing the same could be like the following:
>> 
>> 1. Copy the file names of marked files with 'w'.
>> 2. In another dired buffer type 'C-y' (yank)
>>    like suggested by Drew.
>
> `C-y' in Dired+ also lets you (with a prefix arg) copy
> the files to any directory, whether or not it has a
> Dired buffer.  There's no need limit the use of such
> a file-name list to Dired.
>
> And `C-w' in Dired+ moves, instead of copies, the files
> whose names you copied with `w'.  Again, you can use a
> prefix arg to move the files to any directory - the
> command isn't limited to use in Dired.
>
>> Then it could pop up the standard window "*Marked Files*"
>> and ask for a choice from the list of characters
>> using 'map-y-or-n-p' or 'read-answer', e.g.:
>> 
>> (read-answer "Choose what to do with marked files "
>>   '(("copy" ?c "copy")
>>     ("move" ?r "move")
>>     ("symlink" ?s "make symlink")
>>     ("relsymlink" ?y "make relative symlink")))
>
> Dired+ doesn't have anything particular for symlinking
> the copied file names.
>
> If you do that, I suggest you do as I did for copy/move:
> let users optionally specify a target directory with
> completion, and perform the action even outside of Dired.

FWIW, I found these ideas and the discussion so far really interesting.
I'm experimenting with an implementation of this concept that uses a
transient menu to both let you choose an action (copy/move/...) and show
you which files you're about to act on.  As a bonus, this also lets you
choose other files to act on or a different target directory.

I'm attaching my current implementation for reference if anybody's
interested, as well as a screenshot of the menu that you get by copying
some file names in one directory and then invoking a command in another.


Best,

Eshel


[-- Attachment #2: filet.png --]
[-- Type: image/png, Size: 44875 bytes --]

[-- Attachment #3: filet.el --]
[-- Type: application/emacs-lisp, Size: 6557 bytes --]

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

* Re: [External] : Re: [PATCH] Add file-ring to dired-aux.el
  2024-10-26  7:02     ` Eshel Yaron
@ 2024-10-27  7:47       ` Juri Linkov
  2024-10-28  7:16         ` Eshel Yaron
  0 siblings, 1 reply; 17+ messages in thread
From: Juri Linkov @ 2024-10-27  7:47 UTC (permalink / raw)
  To: Eshel Yaron; +Cc: Drew Adams, Justin Fields, emacs-devel@gnu.org

> FWIW, I found these ideas and the discussion so far really interesting.
> I'm experimenting with an implementation of this concept that uses a
> transient menu to both let you choose an action (copy/move/...) and show
> you which files you're about to act on.

The standard window "*Marked Files*" better handles a long list of files,
but if it can't be used, then maybe displaying a truncated list of files
would be ok.

> As a bonus, this also lets you choose other files to act on or
> a different target directory.

Selecting files using the minibuffer is much less convenient.

> I'm attaching my current implementation for reference if anybody's
> interested, as well as a screenshot of the menu that you get by copying
> some file names in one directory and then invoking a command in another.

Thanks, I tried it out, and everything works nicely.

> ;; Simply mark some files and hit `0 w' to copy their absolute names.

There is more room for improvement to make it more simple.
Instead of requiring a prefix argument `0 w',
`w' could be modified to put text properties
with absolute file names on relative file name strings
to be available for functions that need absolute file names.

> ;; hit `C-y' to invoke `filet'.

Here is the missing keybinding: (keymap-set dired-mode-map "C-y" #'filet)
since the primary use is for Dired.

>   [ :description (lambda () (concat "In directory "
>                                     (abbreviate-file-name
>                                      (expand-file-name default-directory))))

Maybe displaying the current directory is helpful for such
rare cases when it will be used from buffers other than Dired.
But it's more important to show the source directory name, e.g.

  "From directory: ..."

>     ("-f" "Files" "--files"
>      :class transient-option :multi-value rest :reader filet-read-files
>      ;; Align value with the next line.
>      :format " %k %d     (%v)")

Displaying relative file names looks really bad with a lot of
"../../../../../..".  It would be much nicer to display file names
relative to the source directory, especially when its name will be
displayed above.



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

* Re: [External] : Re: [PATCH] Add file-ring to dired-aux.el
  2024-10-27  7:47       ` Juri Linkov
@ 2024-10-28  7:16         ` Eshel Yaron
  2024-10-28 18:53           ` Juri Linkov
  0 siblings, 1 reply; 17+ messages in thread
From: Eshel Yaron @ 2024-10-28  7:16 UTC (permalink / raw)
  To: Juri Linkov; +Cc: Drew Adams, Justin Fields, emacs-devel@gnu.org

Hi Juri,

Juri Linkov <juri@linkov.net> writes:

>> FWIW, I found these ideas and the discussion so far really interesting.
>> I'm experimenting with an implementation of this concept that uses a
>> transient menu to both let you choose an action (copy/move/...) and show
>> you which files you're about to act on.
>
> The standard window "*Marked Files*" better handles a long list of files,
> but if it can't be used, then maybe displaying a truncated list of files
> would be ok.

I think that's right, the transient-based interface works well with
short file name lists, but for longer lists it may not be ideal.

>> As a bonus, this also lets you choose other files to act on or
>> a different target directory.
>
> Selecting files using the minibuffer is much less convenient.

Agreed.  Still I think that it's a nice option to have.

>> I'm attaching my current implementation for reference if anybody's
>> interested, as well as a screenshot of the menu that you get by copying
>> some file names in one directory and then invoking a command in another.
>
> Thanks, I tried it out, and everything works nicely.
>
>> ;; Simply mark some files and hit `0 w' to copy their absolute names.
>
> There is more room for improvement to make it more simple.
> Instead of requiring a prefix argument `0 w',
> `w' could be modified to put text properties
> with absolute file names on relative file name strings
> to be available for functions that need absolute file names.

Good idea, that would definitely simplify things.

>> ;; hit `C-y' to invoke `filet'.
>
> Here is the missing keybinding: (keymap-set dired-mode-map "C-y" #'filet)
> since the primary use is for Dired.
>
>>   [ :description (lambda () (concat "In directory "
>>                                     (abbreviate-file-name
>>                                      (expand-file-name default-directory))))
>
> Maybe displaying the current directory is helpful for such
> rare cases when it will be used from buffers other than Dired.
> But it's more important to show the source directory name, e.g.
>
>   "From directory: ..."

I tend to agree, although as you see in my current implementation
there's no strong assumption that all files come from the same
directory.  You could grab just any list of file names, and go copy them
to some directory.  But I think you're right that in the common case of
copying from one directory (and perhaps some of its subdirectories),
showing the source directory name would be a nice addition.

>>     ("-f" "Files" "--files"
>>      :class transient-option :multi-value rest :reader filet-read-files
>>      ;; Align value with the next line.
>>      :format " %k %d     (%v)")
>
> Displaying relative file names looks really bad with a lot of
> "../../../../../..".  It would be much nicer to display file names
> relative to the source directory, especially when its name will be
> displayed above.

Right, note that filet-short-name only returns a relative name if it's
shorter than the absolute one, but still it may be better to limit the
number of "../../.." as it can get quite confusing.


Thank you for these suggestions.  I'll tweak things accordingly when I
have some time, and let you know how it goes.  Feel free to move forward
with Justin's or any other implementation in the meanwhile, of course.


Best,

Eshel



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

* Re: [PATCH] Add file-ring to dired-aux.el
  2024-10-21 10:38     ` Eli Zaretskii
@ 2024-10-28 10:31       ` Björn Bidar
       [not found]       ` <87v7xctt6p.fsf@>
  1 sibling, 0 replies; 17+ messages in thread
From: Björn Bidar @ 2024-10-28 10:31 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Justin Fields, emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Justin Fields <justinlime1999@gmail.com>
>> Date: Mon, 21 Oct 2024 05:14:52 -0500
>> Cc: emacs-devel@gnu.org
>> 
>> > Why do you call this a "ring"?  AFAICT, it is a simple list, created
>> > and used as such.
>> 
>> To be perfectly honest, it was just the first thing that came to mind to help distinguish this feature. If anybody
>> has any better suggestions I can append accordingly.
>
> Something like dired-marked-files?

It would be great to have consistent name on these. If it's a list of
files it should have the suffix -list similarly to e.g. recentf-list.



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

* Re: [PATCH] Add file-ring to dired-aux.el
       [not found]       ` <87v7xctt6p.fsf@>
@ 2024-10-28 12:42         ` Eli Zaretskii
  0 siblings, 0 replies; 17+ messages in thread
From: Eli Zaretskii @ 2024-10-28 12:42 UTC (permalink / raw)
  To: Björn Bidar; +Cc: justinlime1999, emacs-devel

> From: Björn Bidar <bjorn.bidar@thaodan.de>
> Cc: Justin Fields <justinlime1999@gmail.com>,  emacs-devel@gnu.org
> Date: Mon, 28 Oct 2024 12:31:26 +0200
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> >> From: Justin Fields <justinlime1999@gmail.com>
> >> Date: Mon, 21 Oct 2024 05:14:52 -0500
> >> Cc: emacs-devel@gnu.org
> >> 
> >> > Why do you call this a "ring"?  AFAICT, it is a simple list, created
> >> > and used as such.
> >> 
> >> To be perfectly honest, it was just the first thing that came to mind to help distinguish this feature. If anybody
> >> has any better suggestions I can append accordingly.
> >
> > Something like dired-marked-files?
> 
> It would be great to have consistent name on these. If it's a list of
> files it should have the suffix -list similarly to e.g. recentf-list.

OTOH, almost everything in Emacs is a list, so adding -list would be
waste of space.  When we say "files", "directories", etc., it should
IMO be quite clear we are talking about a list.



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

* Re: [External] : Re: [PATCH] Add file-ring to dired-aux.el
  2024-10-28  7:16         ` Eshel Yaron
@ 2024-10-28 18:53           ` Juri Linkov
  0 siblings, 0 replies; 17+ messages in thread
From: Juri Linkov @ 2024-10-28 18:53 UTC (permalink / raw)
  To: Eshel Yaron; +Cc: Drew Adams, Justin Fields, emacs-devel@gnu.org

>> Maybe displaying the current directory is helpful for such
>> rare cases when it will be used from buffers other than Dired.
>> But it's more important to show the source directory name, e.g.
>>
>>   "From directory: ..."
>
> I tend to agree, although as you see in my current implementation
> there's no strong assumption that all files come from the same
> directory.  You could grab just any list of file names, and go copy them
> to some directory.  But I think you're right that in the common case of
> copying from one directory (and perhaps some of its subdirectories),
> showing the source directory name would be a nice addition.

Probably the best way would be to find and show a common prefix
from all absolute names.  Then file names relative to this prefix
in the list of files will be shortest in the common case of
copying from one directory.



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

end of thread, other threads:[~2024-10-28 18:53 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-21  8:11 [PATCH] Add file-ring to dired-aux.el Justin Fields
2024-10-21  9:48 ` Eli Zaretskii
2024-10-21 10:14   ` Justin Fields
2024-10-21 10:38     ` Eli Zaretskii
2024-10-28 10:31       ` Björn Bidar
     [not found]       ` <87v7xctt6p.fsf@>
2024-10-28 12:42         ` Eli Zaretskii
2024-10-21 12:35   ` Michael Heerdegen via Emacs development discussions.
2024-10-22 18:15 ` Juri Linkov
2024-10-22 18:43   ` Eli Zaretskii
2024-10-23  6:47     ` Justin Fields
2024-10-22 22:24   ` [External] : " Drew Adams
2024-10-26  7:02     ` Eshel Yaron
2024-10-27  7:47       ` Juri Linkov
2024-10-28  7:16         ` Eshel Yaron
2024-10-28 18:53           ` Juri Linkov
  -- strict thread matches above, loose matches on Subject: below --
2024-10-21 15:05 Justin Fields
2024-10-22 15:53 ` Michael Heerdegen

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.