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

标签 emacs dired emacs-ediff

我有以下函数,它对我在 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/

相关文章:

python - 在 emacs 中使用 pdb 时如何指定路径?

emacs - 在 dired 缓冲区中获取 ido

emacs - 一些 emacs 桌面保存问题 : how to change it to save in ~/. emacs.d/.emacs.desktop

EMACS 如何在缓冲区等于文件时重置缓冲区修改标志

emacs - emacs中grep-find的默认字符串

git - Ediff 作为 git difftool

emacs - 如何在emacs dired中为M命令(更改文件模式)提供递归选项(-R)?

Emacs:如何在同一窗口中打开 dired 书签

windows - 如何在 Windows + NTEmacs 下使用 ediff?