gpt4 book ai didi

Emacs ediff 标记了不同目录缓冲区中的文件

转载 作者:行者123 更新时间:2023-12-04 23:54:58 24 4
gpt4 key购买 nike

我有以下函数,它对我在 dired 缓冲区中标记的文件运行 ediff:

(defun mkm/ediff-marked-pair ()
"Run ediff-files on a pair of files marked in dired buffer"
(interactive)
(let ((marked-files (dired-get-marked-files nil)))
(if (not (= (length marked-files) 2))
(message "mark exactly 2 files")
(ediff-files (nth 0 marked-files)
(nth 1 marked-files)))))

它仅适用于同一目录中的文件,如何使其适用于我在不同目录中标记的文件?

最佳答案

这是我的解决方案,它适用于标记在同一个 dired 缓冲区中的文件,也适用于不同缓冲区中的文件。

(defun mkm/ediff-marked-pair ()
"Run ediff-files on a pair of files marked in dired buffer"
(interactive)
(let* ((marked-files (dired-get-marked-files nil nil))
(other-win (get-window-with-predicate
(lambda (window)
(with-current-buffer (window-buffer window)
(and (not (eq window (selected-window)))
(eq major-mode 'dired-mode))))))
(other-marked-files (and other-win
(with-current-buffer (window-buffer other-win)
(dired-get-marked-files nil)))))
(cond ((= (length marked-files) 2)
(ediff-files (nth 0 marked-files)
(nth 1 marked-files)))
((and (= (length marked-files) 1)
(= (length other-marked-files) 1))
(ediff-files (nth 0 marked-files)
(nth 0 other-marked-files)))
(t (error "mark exactly 2 files, at least 1 locally")))))

关于Emacs ediff 标记了不同目录缓冲区中的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18121808/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com