]> git.bundesbrandschatzamt.de Git - emacsconfig.git/commitdiff
added ediff-marked-pair
authorAndreas Gerler <baronNOSPAMbundesbrandschatzamt.de>
Mon, 17 Oct 2016 10:18:54 +0000 (12:18 +0200)
committerAndreas Gerler <baronNOSPAMbundesbrandschatzamt.de>
Mon, 17 Oct 2016 10:18:54 +0000 (12:18 +0200)
- thanks to
  http://stackoverflow.com/questions/18121808/emacs-ediff-marked-files-in-different-dired-buffers
  we can diff files in 2 different dired buffers. Eg dired via tramp on
  2 different servers and compare the files.

Signed-off-by: Andreas Gerler <baronNOSPAMbundesbrandschatzamt.de>
bba.org

diff --git a/bba.org b/bba.org
index 2a4c40a60d64da431236d638410cae27c1a5347d..a485de3711bda14aaaffbddab9a5a8f9fdbb9b4f 100644 (file)
--- a/bba.org
+++ b/bba.org
@@ -2741,6 +2741,45 @@ Kill the current buffer without asking if there is no prefix.
 
   (global-set-key (kbd "C-x k") 'jcs-kill-a-buffer)
 #+END_SRC
+
+* [[http://stackoverflow.com/questions/18121808/emacs-ediff-marked-files-in-different-dired-buffers][ediff marked pair]]
+[2016-10-17 Mon 11:57]
+
+Had to diff files on 2 different servers. What's better then dired and TRAMP?
+
+#+BEGIN_SRC emacs-lisp
+  (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)))
+             ((= (length marked-files) 1)
+              (let ((single-file (nth 0 marked-files)))
+                (ediff-files single-file
+                             (read-file-name
+                              (format "Diff %s with: " single-file)
+                              nil (m (if (string= single-file (dired-get-filename))
+                                         nil
+                                       (dired-get-filename))) t))))
+             (t (error "mark no more than 2 files")))))
+
+  (define-key dired-mode-map "=" 'mkm/ediff-marked-pair)
+#+END_SRC
+
 * configure some default values
     [2014-10-02 Thu 00:27]