Fork me on GitHub
#emacs
<
2021-09-06
>
andrea.crotti10:09:21

how do people deal with resolving conflicts with Emacs? for example I use smartparens-strict-mode and when I open a file with conflicts I always have to disable that

ribelo10:09:49

magit & ediff

☝️ 2
4
vemv10:09:21

I solve them by "force-deleting" lines for example for the conflict

>>>
a
===
b
<<<<<
I force-delete all lines but b Works pretty well for most conflicts I get. Sometimes I might have to do some surgical edits. At least under my setup paredit doesn't get in the way i.e. it can keep working even in face of slightly broken code

vemv10:09:02

my force-delete isn't particularly fancy

(defun vemv/delete-this-line ()
  (end-of-line)
  (cua-set-mark)
  (previous-line)
  (end-of-line)
  (call-interactively 'kill-region))

andrea.crotti10:09:58

actually I just found out that by default smerge-mode is already enabled

andrea.crotti10:09:33

when I open a file with conflicts, so I can probably just use that (have to try if smartparens is happy with that though)

andrea.crotti10:09:05

the only issue I guess is that the keybindings are a bit weird, I think it would be nicer if it just opened a read only buffer with simple keybindings to do the various actions

andrea.crotti10:09:16

but I guess I can do it myself with the right mapping

andrea.crotti10:09:12

there are some more rare cases in which I have to actually merge manually changes from the two versions, but I guess I can just first pick one and then apply the manual changes

djm10:09:08

You could just M-x turn-off-smartparens-mode until you’ve sorted the conflicts

djm10:09:30

Then M-x enable-paredit-mode afterwards 😉

andrea.crotti10:09:51

yeah I know, which is what I've done until now

andrea.crotti10:09:55

but it's quite annoying

andrea.crotti10:09:52

there is also a magit-diff-mode-hook I could probably use

andrea.crotti10:09:56

to turn it off automatically otherwise

andrea.crotti10:09:24

mm actually maybe that's something else though

djm10:09:50

That sounds like it should work.

andrea.crotti10:09:05

yeah no I don't think it opens the file in magit-diff-mode actually

andrea.crotti10:09:10

that's the mode to look at diffs

andrea.crotti10:09:37

but I can maybe add a hook to smerge-mode since that's enabled

pavlosmelissinos05:09:10

> [...] you could use Ediff, which uses separate buffers for the different versions of the file. To resolve conflicts in a file using Ediff press e while point is on such a file in the status buffer. > From the magit manual https://magit.vc/manual/magit/Resolving-Conflicts.html I've tried smerge but didn't like the ergonomics as much

andrea.crotti13:09:56

yeah I could try ediff again

Jason11:09:00

I’m just using smerge on mine and setting some shortcuts to use them

:leader
    "g n" #'smerge-next
    "g <up>" #'smerge-keep-upper
    "g <down>" #'smerge-keep-lower
    "g <left>" #'smerge-keep-all

Jason11:09:26

I do use doom emacs so configuration might be different for you

andrea.crotti11:09:38

ah cool @U028TA3H3PA,does it mean your buffer is also read only?

Jason11:09:26

Hmm not sure if it is read only or not :thinking_face:

Jason11:09:36

I think it’s likely to be read/write

Jason11:09:48

I’ll double check

Jason11:09:27

Are you relying on it being read only?

Jason11:09:03

It’s definitely read/write for me and that’s probably beneficial as it’s often I have to resolve the conflicts somewhat manually at times

andrea.crotti10:09:03

I guess it would be nice to just have a different mode to solve conflicts, or just automatically disable things that get in the way