Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I combine the two variants of a conflict in emacs' emerge?

Tags:

emacs

Using emerge in Emacs, I have a session like this:

<<<<<<< variant A
            522ADC9C14B2FD9D00F56BAD /* close_test_button.png in Resources */,
            522ADC9D14B2FD9D00F56BAD /* [email protected] in Resources */,
            522ADCA014B2FDB100F56BAD /* test_failed.png in Resources */,
            522ADCA114B2FDB100F56BAD /* [email protected] in Resources */,
>>>>>>> variant B
            EC1633C014B2F3E3004B52E7 /* arrow.png in Resources */,
            EC1633C114B2F3E3004B52E7 /* [email protected] in Resources */,
            EC1633C214B2F3E3004B52E7 /* groups.png in Resources */,
            EC1633C314B2F3E3004B52E7 /* [email protected] in Resources */,
####### Ancestor
======= end

I can select variant A or B by hitting a or b on my keyboard, but how do I combine both variants, one after the other?

like image 609
Hans Sjunnesson Avatar asked Jan 03 '12 09:01

Hans Sjunnesson


2 Answers

Just use C-hm within the emerge buffer to see the help for the current modes. As is typical for most modes, the Emerge minor mode displays its key bindings in this help text.

That help shows that you can insert the content of variant A or B with: ia and ib, so you can use that feature to insert whichever variant isn't currently selected.

You can also switch from the default 'fast' mode to emerge 'edit' mode to directly edit the merged text. Use C-cC-cf in edit mode to get back to fast mode (because in edit mode, all emerge commands need to be prefixed by C-cC-c).

The Emerge manual has more details:
M-: (info "(emacs) Emerge") RET

In particular, it explains the behaviour of the xc binding, which combines the two variants in a single step using a pre-defined template string:
M-: (info "(emacs) Combining in Emerge") RET

The default template uses C preprocessor conditional syntax, however, so you would almost certainly want to override that. You can set the template via the Emerge Options menu or with emerge-set-combine-template. For the template syntax see:
C-hv emerge-combine-versions-template RET

like image 133
phils Avatar answered Nov 15 '22 05:11

phils


Use the shortcut:

x-c   (combine the two versions of the difference)

This will insert the two conflicting regions sequentially, yielding an output something like:

vvvvvvvvvvvvvvvvvvvv
#ifdef NEW
522ADC9C14B2FD9D00F56BAD /* close_test_button.png in Resources */,
522ADC9D14B2FD9D00F56BAD /* [email protected] in Resources */,
522ADCA014B2FDB100F56BAD /* test_failed.png in Resources */,
522ADCA114B2FDB100F56BAD /* [email protected] in Resources */,
#else /* not NEW */
EC1633C014B2F3E3004B52E7 /* arrow.png in Resources */,
EC1633C114B2F3E3004B52E7 /* [email protected] in Resources */,
EC1633C214B2F3E3004B52E7 /* groups.png in Resources */,
EC1633C314B2F3E3004B52E7 /* [email protected] in Resources */,
#endif /* not NEW */
^^^^^^^^^^^^^^^^^^^^

From there, you can go into edit mode (shortcut: 'e') remove the #ifdef macros as necessary to create the final merge that you desire.

like image 20
Mike Curtiss Avatar answered Nov 15 '22 03:11

Mike Curtiss