reddit / emacs
Is there a mechanism to manually sort a list of filenames?
lawlist · 2022-09-06 03:23
**EDIT / CLARIFICATION**: This question is *not* intended to be about *programmatically* sorting a list of filenames, but is rather a quest to find an Emacs library / package that facilitates a user to *manually* rearrange a list of filenames in an arbitrary order and then return the modified list as a result.
I'm using `pdftk` to combine various PDF files, and am looking for a mechanism to assist in manually choosing the sort order. The command line for combining PDF files looks like this:
pdftk file1.pdf file2.pdf file3.pdf cat output single_document.pdf
Starting from a `dired-mode` buffer, I can select various files and obtain a list with `dired-get-marked-files`. From there, is there a mechanism / library that can let me manually choose the order and return a new list sorted accordingly?
lebensterben · 2022-09-06 03:30
https://www.gnu.org/software/emacs/manual/html_node/cl/Sorting-Sequences.html
lawlist · 2022-09-06 04:33
Thank you for the link. In this particular use-case, I want to *manually* sort the order of files and have the revised list returned as a result. E.g., a buffer of filenames that I can reorder by moving files up or down, either one at a time, or several at a time. This could be similar to the GUI interface of Adobe Acrobat Professional when selecting the files to be combined and manually adjusting the order before assembling the binder.
lebensterben · 2022-09-06 04:48
you said you can obtain a list. I showed you how to sort it. What's the problem here?
lawlist · 2022-09-06 04:55
The documentation relates to a programmatic sort, rather than a user interface to manually reorder the files ... I'm looking for an Emacs library that provides an interface where the user may manually move files up or down (or left or right) to select a particular sorted order and then return the revised list.
lebensterben · 2022-09-06 04:59
dired-quick-sort
Hammar_Morty · 2022-09-06 05:21
https://github.com/Wilfred/refine
7890yuiop · 2022-09-06 08:53
From what I can tell you're not looking to *sort* the files at all, but rather you want to manually order them in any arbitrary sequence. That's not sorting (which implies some kind of deterministic rules).
Your question is consequently confusing people -- you might edit it to clarify.
HM0880 · 2022-09-06 16:23
You can highlight the DirEd buffer with `C-x h` and then copy/paste the contents to another buffer (say, `*scratch*`) where you can edit and move lines to your heart's content.
lawlist · 2022-09-06 16:41
The functions `refine-move-forwards` and `refine-move-backwards` look very promising. Thank you!
lawlist · 2022-09-06 16:41
Yes, I agree -- thank you.
arthurno1 · 2022-09-06 18:13
> The documentation relates to a programmatic sort
That is what "sorting" normally means.
> user interface to manually reorder the files
That is quite different from "sorting". If you said "manually order files" instead of "manually sort files" you might have got an answer that more suites your intention. In case where you have got a perfectly good answer from someone, but your question was unclear, I think it is quite impolite by you (or whomever) to downvote the answer. The other person has taken the time to read your question, answered it in good faith, and got punished by your downvote because you were clumsy and didn't express yourself clear. In my opinion, that is bad manner and impolite from you.
To answer your question, no there is not a way to mark files in a particular order in Dired. The use-case is very niche. I have yet to heard someone ask for preserving the marking order. However it wouldn't be very hard to develop a simple function to do what you want. [I just did it for the fun of it](https://github.com/amno1/dired-queue) :).
arthurno1 · 2022-09-06 18:17
As I answered in the other comment, this is a very niche use-case. However, for the fun of it, see if the [dired-queue](https://github.com/amno1/dired-queue) fits the bill. You can mark/unmark/unmark all as usually with dired shortcuts, and you can open the queue in another dired buffer with '#'. Or programmatically act on the 'dired-queue' which is just a list of strings.
Edit: I have just added two functions to move line up and down in a Dired buffer; so one can re-arrange the order of files and then mark them to act on them, or roughly mark files in a desired order, than open them in a "queue" buffer and re-arrange them further there.
lawlist · 2022-09-06 20:12
Thank you for the referral to the `dired-queue` library and for giving it a whirl yourself. I anticipate having an opportunity later in the evening after work to give it a try. In general, I do not downvote on reddit or on the stack exchange / overflow forums. Off hand, the only downotes I can remember issuing in the last 10+ years have been in response to particularly mean-spirited comments that unfortunately happens from time to time. I agree that my using the word "sort", rather than "order" / "rearrange" / "arbitrary order", caused quite a bit of confusion and I'll try to be more precise when explaining myself in the future.
arthurno1 · 2022-09-06 20:25
Ah, now it is in plus; but when I originally wrote the comment, and started to code it the answer from the other poster was in 0 :). I understand it was maybe not you, sorry for using "you" in entire text. When I write fast I don't express myself always the best way.
Check it now, see the Readme. You can either re-arrange filenames in a Dired buffer with M-<up> & M-<down> to move them up/down, and then mark, or just mark roughly in the order you want, open "the queue" buffer and re-arrange there where there is possibly fewer files to move up/down through.
You can also check [drag-stuff.el](https://github.com/rejeep/drag-stuff.el) if you are interesting in doing it with the mouse. Or try to just M-: (setq mouse-drag-and-drop-region t), but be sure to change to wdired-mode before, since Dired buffers are not writable (or wrte dired wrappers).
lawlist · 2022-09-07 03:20
Yes, `dired-queue-mode` is exactly the feature that I was looking for! Thank you so very much for creating that library!!! I've lightly tested it this evening, but am already certain that this will do the job nicely. I look forward to using this new feature / mechanism whenever there is a need to manually arrange files.
arthurno1 · 2022-09-07 06:51
Cool. Enjoy.