Hot answers tagged

22

The Emacs package for doing this is named Ediff and Magit supports Ediff. To get started press e on the change for which you want to see the side-by-side comparison. You might also have to use E occasionally to tell Ediff/Magit explicitly what you want to compare. Also see the Ediff manual and the node about Ediff in the Magit manual.


8

Invoke the magit-diff transient (d). Limit to the file you are interested in with the -- option. (Hit tab for completion.) Ignore white space changes with the -w option. Call the magit-diff-range action (r). Select the name of the branch you're interested in. (Hit tab for completion.) That will diff the branch with the working tree, but you can tweak the ...


5

Type TAB. Many sections in Magit can be expanded (and then again collapsed) by pressing TAB. Actually I was working on adding indicators to make that more obvious yesterday. Might try to finish that later today.


5

Magit can do this by limiting the revert action to the region. With the built-in diff-mode you can get the same kind of effect by splitting the hunk into portions using diff-split-hunk which is bound to C-c C-s by default.


4

(As previous mentioned in the comments by glucas), a heavyweight approach to comparing regions is provided by the excellent ediff library: ediff-regions-linewise ediff-regions-wordwise These commands "run Ediff on a pair of regions in specified buffers". They prompt you first to specify which buffer(s) the regions come from, and then to mark and/or ...


4

Interactively, I do this one of a few ways, depending on the scenario. First, if the regions are small -- e.g., lately I've been comparing some test output with the expected results, and both are just a single line -- I just edit so the lines are next to each other and compare visually. Another "low tech" solution is to use isearch. If both regions are ...


4

I think commands magit-log-buffer-file and its variant magit-log-buffer-file-popup are what you are looking for. These are bound to l and L in Magit buffers, respectively. Invoking the former command within a version-controlled-file-visiting buffer (i.e. by typing M-x magit-log-buffer-file) skips the popup and displays the log directly. Within the resulting ...


4

I've used a function like this for something similar: (defun current-buffer-matches-file-p () "Return t if the current buffer is identical to its associated file." (autoload 'diff-no-select "diff") (when buffer-file-name (diff-no-select buffer-file-name (current-buffer) nil 'noasync) (with-current-buffer "*Diff*" (and (search-forward-...


3

Why a binary search? compare-buffer-substrings returns the number of chars that were equal. So you can just do: (goto-char (+ (point-min) -1 (abs (compare-buffer-substrings BUF1 nil nil BUF2 nil nil)))) you may want to let-bind case-fold-search around the call to specify if you prefer to be case-sensitive or case-...


3

@tmalsburg, Following command calls diff on 2 buffers without the creation of temporary files. It uses named pipes as you suggested above: (require 'diff) (defun diff-buffers-without-temp-files (buffer1 buffer2 &optional switches) "Run diff program on BUFFER1 and BUFFER2. Make the comparison without the creation of temporary files. When called ...


3

You can always write a function to do all the repeated steps for you. This should get you started: (defun diff-generic(command) (interactive "sDiff command:") (let ((buffer (generate-new-buffer "*diff-generic*"))) (with-current-buffer buffer (diff-mode)) (call-process-shell-command command nil buffer 0) (switch-to-buffer buffer))) In ...


3

I don't think there is an existing Elisp solution for that. But if you look at how I implemented smerge-refine-subst (also used in diff-refine-hunk) it should give you some idea of how you can play with diff. IOW you should be able to run a single diff process to handle all your lines at once, by concatenating them and adding "synchronization lines" in ...


3

Since this solution uses only CLI Diff, it also answers your "ignore whitespace" question, tweak diff's option to do whatever you want. Please man diff. ;; Diff two regions ;; Step 1: Select a region and `M-x diff-region-tag-selected-as-a' ;; Step 2: Select another region and `M-x diff-region-compare-with-b' (defun diff-region-format-region-boundary (b e) ...


2

Try M-! <your diff command/> C-x b *Shell Command Output* (where the output of M-!==M-x shell-command goes by default) M-x diff-mode


2

Indeed, all those diff options work line-by-line, and insertion/removal of newlines creates completely different lines so they don't see those changes as "just whitespace". You need to use a word-based diff or something like that. Emacs comes with one such functionality which is the "refined" highlighting. It's available both in smerge-mode and in diff-...


2

vdiff processes the output of diff asynchronously which takes a nonzero amount of time. Instead of guessing when to run vdiff-refine-all-hunks just set vdiff-auto-refine to t to let vdiff run it at the right time. If you're having a performance issue, first check how long diff takes on the command line, then see if refining all hunks is slow, and finally ...


2

That's because you are not using custom-set-variables correctly. You are not supposed to write that by hand, but if you wrote it like this (custom-set-variables '(magit-diff-refine-hunk (quote all))) then it should work. But just use this instead (setq magit-diff-refine-hunk 'all) As mentioned by @Basil, you could also use custom-set-variable (singular), ...


2

I think that the command you're looking for is magit-diff-range. Being on some branch, hit M-x and magit-diff-range. Then, when prompted, enter the name of the other branch and you will get a buffer with diffs.


2

Git diff doesn't work for me as it can't find kdiff. I don't know why git diff would need kdiff (whatever that is), but if git diff does not work on the command line, the various magit-diff-* commands also won't work because they get the diff by running git diff too. It appears to me that you have misconfigured Git. You can probably fix that by running git ...


2

Step 1: Select text and M-x diff-region-tag-selected-as-a Step 2, Select or not select text, M-x diff-region-tag-selected-as-b You need install cli tool diff on windows (its bundled with Cygwin or MSYS2). To read clipboard, you need install Emacs plugin simpleclip. Here is the code: ;; {{ diff region SDK (defun diff-region-exit-from-certain-buffer (...


2

It seems that ediff displays line-based difference regions like diff. However, refinements are displayed using the moving commands like j, n and p. Ediff manual The functions ediff-files, ediff-buffers, ediff-files3, ediff-buffers3 first display the coarse, line-based difference regions, as reported by the diff program. [...] the differences are highlighted ...


2

Edit, I've since written made a version of this which parses the diff hunks, here. Posting own answer, it works but it has some limitations. This is a wrapper for vc-root-diff which opens a fillscreen buffer, and jumps to the current file then the line/column (using search). Ideally it would position the cursor using the diff line ranges, as long as you'...


2

Edit: this is now a package: diff-at-point This solution parses the diff hunks to lookup a buffer location in the diff. By default, if the current location isn't part of the diff, the closest line in the diff is used (unless the option argument strict isn't nil). (defun diff-at-point-file-line-to-point (current-filename-relative current-line current-...


2

Split the window. In each window, put point at the start of one of the two lines (or at the start of each "..." in your example). M-x compare-windows RET C-xzzzz... to repeatedly compare as many times as necessary. Or of course, bind compare-windows to a key (I use C-M-=), and you can just type that repeatedly. There's also M-x ediff-regions-wordwise (I ...


2

You apparently used dired-diff. Please just provide the recipe as part of your question. Don't throw a (very hard to read) screenshot at us. The behavior of the command depends on your OS diff command. Use M-x man diff to see what switch possibilities there are and whether any of them help you get the behavior you want. If so, then use C-u dired-diff. You'...


2

If you are content to use diff on the bash command line and are not looking for a pure emacs solution, you can use process substitution to pass into diff slightly modified files: diff <(sed -E 's/^\*+/*/' file1.org) <(sed -E 's/^\*+/*/' file2.org) Each sed command outputs its input file unchanged, except that a string of one or more asterisks at the ...


2

You can do an ediff-buffers-wordwise and type #h \*+ to ignore words consisting of stars. If you advance to the next diff by pressing SPC ediff will skip words only differing in the number of stars.


2

One can configure ediff-filtered-filters such that it replaces multiple leading stars with one leading star and call ediff-buffers. The following Elisp function my-org-ediff does that for you. Just copy the Elisp code to your init file, restart Emacs, and use my-org-ediff for diffing org files in the way you want it. (defvar ediff-filtered-filters) (defun ...


2

You don't need to do anything fancy with ediff or keyboard macros. Just concatenate the two files together, then remove any duplicates. You can do that at the command line: cat a b | sort | uniq > c Or you can do it in emacs: paste both lists into a single buffer, then select everything with C-x h. Run M-x sort-lines to sort them, then M-x delete-...


1

You can explicitly show the diff using C-d C-d in the COMMIT_EDITMSG buffer. Normally the diff is automatically shown by magit-commit-diff, which is a member of server-switch-hook. That hook isn't run when committing over Tramp because in that case we cannot use the emacsclient to connect to the server (server.el) running inside Emacs. Instead an ...


Only top voted, non community-wiki answers of a minimum length are eligible