all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#69220: [PATCH] smerge-mode: add a function to resolve all conflicts in a file
@ 2024-02-17 10:16 Konstantin Kharlamov
  2024-02-19 12:03 ` Eli Zaretskii
  0 siblings, 1 reply; 24+ messages in thread
From: Konstantin Kharlamov @ 2024-02-17 10:16 UTC (permalink / raw)
  To: 69220

[-- Attachment #1: Type: text/plain, Size: 710 bytes --]

This implements a feature request from here¹ about having a function to
resolve all conflicts simultaneously. Although question author didn't
reply, but either way I think it's a useful functional. I needed it so
many times, but before stumbling upon this question I just didn't know
there are functions `smerge-keep-upper/base/lower`, and so ofc I never
though of writing a new one that would apply them to all conflicts.

It might be useful to make a function to do the same within a git-repo,
but for now let's have at least a function that does that within a
file.

1:
https://emacs.stackexchange.com/questions/80361/when-merging-conflicts-in-smerge-mode-how-to-select-mine-for-all-conflicts

[-- Attachment #2: 1.patch --]
[-- Type: text/x-patch, Size: 2139 bytes --]

From 1702d7c0f782a8e18b2539194a5b276707181353 Mon Sep 17 00:00:00 2001
From: Konstantin Kharlamov <Hi-Angel@yandex.ru>
Date: Sat, 17 Feb 2024 12:43:02 +0300
Subject: [PATCH] smerge-mode: add a function to resolve all conflicts in a
 file

* lisp/vc/smerge-mode.el (smerge-resolve-all-in-file-to): a new
interactive function to resolve all conflicts in a file.
---
 etc/NEWS               |  6 ++++++
 lisp/vc/smerge-mode.el | 21 +++++++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/etc/NEWS b/etc/NEWS
index 9bdc3af5e71..b7a48412f4f 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1170,6 +1170,12 @@ Similarly to buffer restoration by Desktop, 'recentf-mode' checking
 of the accessibility of remote files can now time out if
 'remote-file-name-access-timeout' is set to a positive number.
 
+** Smerge mode
+
+*** New interactive function 'smerge-resolve-all-in-file-to'.
+Allows to resolve all conflicts inside a file in preference of 'upper'
+or 'base' or 'lower'.
+
 ** Notifications
 
 +++
diff --git a/lisp/vc/smerge-mode.el b/lisp/vc/smerge-mode.el
index a16c7871ff9..c32410bcb15 100644
--- a/lisp/vc/smerge-mode.el
+++ b/lisp/vc/smerge-mode.el
@@ -714,6 +714,27 @@ smerge-keep-upper
   (smerge-keep-n 1)
   (smerge-auto-leave))
 
+(defun smerge-resolve-all-in-file-to (to-keep)
+  "Resolves all conflicts inside a file in preference of TO-KEEP.
+
+TO-KEEP decides which part to keep and is one of `upper', `base',
+`lower'".
+  (interactive
+   (list (completing-read "Keeping: " [upper base lower])))
+  (let ((resolve-func
+         (pcase to-keep
+           ("upper" 'smerge-keep-upper)
+           ("base"  'smerge-keep-base)
+           ("lower" 'smerge-keep-lower)
+           (_ (error "Unknown resolution argument!"))))
+        (num-chars-before (point-max)))
+    (save-excursion
+      (goto-char (point-min))
+      (while (ignore-errors (not (smerge-next)))
+        (funcall resolve-func)))
+    (when (= num-chars-before (point-max))
+      (message "No conflicts were found"))))
+
 (define-obsolete-function-alias 'smerge-keep-mine 'smerge-keep-upper "26.1")
 
 (defun smerge-get-current ()
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2024-02-20 15:34 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-17 10:16 bug#69220: [PATCH] smerge-mode: add a function to resolve all conflicts in a file Konstantin Kharlamov
2024-02-19 12:03 ` Eli Zaretskii
2024-02-19 12:17   ` Konstantin Kharlamov
2024-02-19 12:25     ` Andreas Schwab
2024-02-19 12:28       ` Konstantin Kharlamov
2024-02-19 12:33         ` Andreas Schwab
2024-02-19 12:38           ` Konstantin Kharlamov
2024-02-19 12:44             ` Andreas Schwab
2024-02-19 12:53               ` Konstantin Kharlamov
2024-02-19 17:07     ` Konstantin Kharlamov
2024-02-20 15:34       ` Konstantin Kharlamov
2024-02-19 15:20   ` Dmitry Gutov
2024-02-19 15:35     ` Andreas Schwab
2024-02-19 15:31   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-02-19 17:25     ` Konstantin Kharlamov
2024-02-20  2:24       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-02-20  3:02         ` Konstantin Kharlamov
2024-02-20  3:15           ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-02-20  3:24             ` Konstantin Kharlamov
2024-02-20  3:40               ` Konstantin Kharlamov
2024-02-20 13:53                 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-02-20 13:59                   ` Konstantin Kharlamov
2024-02-20 14:03               ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-02-20 14:10                 ` Konstantin Kharlamov

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.