最近有用orderless筛选dired buffer的需求,所以才有了标题所说的
方案一:dired-goto-file
emacs自带,但是只能搜索当前dired-header下的目录,如果使用dired-insert-subdir插入了多个目录,不能同时搜索这些目录。
方案二:用consult-line,缺点因为是基于occor-mode,embark-export没法导出为dired buffer,如果想进一步做文件管理相关的操作不太好用。
方案三: consult-find
或者consult-fd
之类的补全命令,能避免之前两个方案的缺点,不过这样好像不算搜索dired buffer,而是直接搜索文件名了。
方案四: 让dired-goto-file
支持补全整个dired buffer,需要自己写一个:
(defun dired-list-files (&optional localp no-error-if-not-filep)
"List all files in current Dired buffer.
Adapted from `dired-toggle-marks'."
(if (derived-mode-p 'dired-mode)
(save-excursion
(let (files
(inhibit-read-only t)
(beg (dired-mark--region-beginning))
(end (dired-mark--region-end)))
(goto-char beg)
(while (< (point) end)
(or (dired-between-files)
(looking-at-p dired-re-dot)
(push (cons (dired-get-filename localp no-error-if-not-filep) (point)) files))
(forward-line 1))
files))
(user-error "Not A Dired Buffer!")))
(defun dired-swiper ()
"Jump to files in current Dired buffer with completion."
(interactive nil dired-mode)
(let* ((files (dired-list-files))
(completion-extra-properties '(:category file))
(file (completing-read "Find Files: " files nil t)))
(when file
(goto-char (cdr (assoc file files))))))
目前我自己用方案四,功能很简单不过够用了