dired 似乎没有提供根据任意比较器函数对文件/文件夹进行排序的接口(interface)。 (默认情况下,它只允许按名称和日期排序)。
我一直在深入研究源代码以确定这种排序的机制,我发现它是对 dired-sort- 中的
(在(revert-buffer)
的调用切换dired.el
中)执行重新显示。这让我意识到 dired 只是运行带有某些开关的 ls 命令,然后将输出读入缓冲区。
有没有比将 dired 的 ls 函数指向自定义排序更好的方法来实现这种自定义排序?我觉得可能有一个变量保存 dired 缓冲区中的文件/目录的有序列表,我可以重新排列它。
我找到了变量dired-subdir-alist
,但这似乎只包含顶级目录(即使根据文档,这似乎正是我想要的列表)
dired-subdir-alist is a variable defined in `dired.el'. Documentation: Association list of subdirectories and their buffer positions. Each subdirectory has an element: (DIRNAME . STARTMARKER). The order of elements is the reverse of the order in the buffer. In simple cases, this list contains one element.
我怎样才能找到这样的变量?
最佳答案
你的理解是正确的。而且,正如 @Stefan 指出的,ls-lisp.el
提供了一些灵活性。
另请参阅库 Dired Sort Menu ,它至少提供了更多的 ls 可能性,并允许您组合排序顺序。 (但是,它不允许您提供任意排序顺序 - 为此,请参阅 ls-lisp.el。)
关于sorting - 根据自定义比较器对 emacs dired 缓冲区进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18784708/