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; 16+ 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] 16+ messages in thread
* Re: [PATCH] Add file-ring to dired-aux.el
@ 2024-10-21 15:05 Justin Fields
  2024-10-21 17:47 ` [External] : " Drew Adams
  0 siblings, 1 reply; 16+ 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] 16+ messages in thread

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

Thread overview: 16+ 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-21 17:47 ` [External] : " Drew Adams

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.