unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Justin Fields <justinlime1999@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: Juri Linkov <juri@linkov.net>, emacs-devel@gnu.org
Subject: Re: [PATCH] Add file-ring to dired-aux.el
Date: Wed, 23 Oct 2024 01:47:39 -0500	[thread overview]
Message-ID: <CAPafesEh3ROxnSrjyL2QDwe2+4fFLD0dSz-_XxyAxJwo5p-EBQ@mail.gmail.com> (raw)
In-Reply-To: <865xpkf075.fsf@gnu.org>


[-- 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


  reply	other threads:[~2024-10-23  6:47 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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-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 [this message]
2024-10-22 22:24   ` [External] : " Drew Adams
  -- strict thread matches above, loose matches on Subject: below --
2024-10-21 15:05 Justin Fields
2024-10-22 15:53 ` Michael Heerdegen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAPafesEh3ROxnSrjyL2QDwe2+4fFLD0dSz-_XxyAxJwo5p-EBQ@mail.gmail.com \
    --to=justinlime1999@gmail.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=juri@linkov.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).