Frage

I simply want to supply two files to emacs from terminal and it should open them in two separate windows in diff mode.

War es hilfreich?

Lösung

You're looking for ediff. In emacs you can activate it via M-x ediff and the file names. To call it from commandline try something like this (taken from emacs wiki):

(defun command-line-diff (switch)
  (let ((file1 (pop command-line-args-left))
        (file2 (pop command-line-args-left)))
    (ediff file1 file2)))

(add-to-list 'command-switch-alist '("diff" . command-line-diff))

;; Usage: emacs -diff file1 file2

To get you started here are a few additional "saner" defaults"

;; saner ediff default
(setq ediff-diff-options "-w")
(setq ediff-split-window-function 'split-window-horizontally)
(setq ediff-window-setup-function 'ediff-setup-windows-plain)

These will always split to have ediff windows side-by-side.

If you want to always force a new frame (it is cleaner this way), try these additionally:

(add-hook 'ediff-before-setup-hook 'new-frame)
(add-hook 'ediff-quit-hook 'delete-frame)

I hope that helps for the beginning.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top