From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Tassilo Horn Newsgroups: gmane.emacs.help Subject: How to use emacs as a "diff3 -m" compatible merge tool? Date: Thu, 09 Jun 2022 12:52:20 +0200 Message-ID: <87ilpaay1j.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10519"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.7.26; emacs 29.0.50 To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Thu Jun 09 15:56:54 2022 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nzIeb-0002VP-Qn for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 09 Jun 2022 15:56:54 +0200 Original-Received: from localhost ([::1]:37742 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nzIea-0001Wu-Mn for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 09 Jun 2022 09:56:52 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46006) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzG7p-00075l-68 for help-gnu-emacs@gnu.org; Thu, 09 Jun 2022 07:14:54 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:52058) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nzG7o-0002c4-UK for help-gnu-emacs@gnu.org; Thu, 09 Jun 2022 07:14:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:Subject:To:From:in-reply-to: references; bh=VbKwlow3/46jCJ8h6CsdToKKixZsc2AXGFJIHXzuPCA=; b=rKk8CQUrcTRO1Y yNg+Us91tdl5qnUz3bMAi2/kBFSIXRbCcy/bd0ew0RXNitPbclYrEuhtSTIq4hplyI1u3/ddI8LMU TXm8Z6OYkdDHkViXalWJphCMhZGKln5tSSIhdXi3WohzckdGFjn4q6mpgsZBBhXEFSHk0cwule+Bg eTtk1obpB2Wf2FTfr+RnSRUP1e3H39d9pZyi4T/uWvXqTtE2RbiHC3GJ7g9GXTeKyDAcurpqocwnv XTtpSylz7dwo0Jotk2Bn7G5JuwBNEC5LUuy3QEH++G7MA+ZsrblOCpvcpNiwyPxyD5WRoS8mtWyVB HD70hdXLkP5R3IhYHIng==; Original-Received: from auth1-smtp.messagingengine.com ([66.111.4.227]:33361) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nzG7n-0004Zw-IW for help-gnu-emacs@gnu.org; Thu, 09 Jun 2022 07:14:52 -0400 Original-Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailauth.nyi.internal (Postfix) with ESMTP id 50FB927C0054 for ; Thu, 9 Jun 2022 07:14:51 -0400 (EDT) Original-Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Thu, 09 Jun 2022 07:14:51 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedruddtledgfeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpegfhffvufffkfggtgesthdtredttd ertdenucfhrhhomhepvfgrshhsihhlohcujfhorhhnuceothhsughhsehgnhhurdhorhhg qeenucggtffrrghtthgvrhhnpeduvdeuveejfeekueffieffhfethfdviedutddtgfeivd dvhfevffelgfdujeetveenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgr ihhlfhhrohhmpehthhhorhhnodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqd ekieejfeekjeekgedqieefhedvleekqdhtshguhheppehgnhhurdhorhhgsehfrghsthhm rghilhdrfhhm X-ME-Proxy: Feedback-ID: ib2b94485:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Thu, 9 Jun 2022 07:14:50 -0400 (EDT) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:137551 Archived-At: Hi all, there are certain tools/scripts such as Arch GNU/Linux' pacdiff which call a user-defined tool for doing a 3-way merge. For example, pacdiff wants to merge the current config file with the current package-provided config file and the package-provided config file of a previous version as a base/ancestor. pacdiff calls the user-defined mergeprog like so: --8<---------------cut here---------------start------------->8--- if $mergeprog "$file" "$base" "$pacfile" >"$merged"; then msg2 "Merged without conflicts." fi --8<---------------cut here---------------end--------------->8--- I'd like to use emacs as mergetool so need to support these calling convention (which are the ones of "diff3 -m"), i.e., 1. args are MY-VERSION BASE THEIR-VERSION 2. a successful merge exits zero, an aborted merge exits non-zero 3. the merge result is printed to stdout I've come up with two versions (ediff-merge & emerge): --8<---------------cut here---------------start------------->8--- (defun th/command-line-ediff-merge3 (_switch) "Do a 3-way merge using `ediff-merge-files-with-ancestor'." (let ((make-backup-files nil) (my-version (pop command-line-args-left)) (base-version (pop command-line-args-left)) (their-version (pop command-line-args-left))) (ediff-merge-files-with-ancestor my-version their-version base-version))) (add-to-list 'command-switch-alist '("--ediff-merge3" . th/command-line-ediff-merge3)) (defun th/command-line-emerge3 (_switch) "Do a 3-way merge using `emerge-files-with-ancestor'." (let* ((make-backup-files nil) (my-version (pop command-line-args-left)) (base-version (pop command-line-args-left)) (their-version (pop command-line-args-left)) (merged (make-temp-file (concat (file-name-nondirectory my-version) ".merged")))) (emerge-files-with-ancestor nil my-version their-version base-version merged))) (add-to-list 'command-switch-alist '("--emerge3" . th/command-line-emerge3)) --8<---------------cut here---------------end--------------->8--- So now I can call "emacs --ediff-merge3 my base theirs" or "emacs --emerge3 my base theirs" and do the merge. However, points 2 and 3 are not yet addressed. So how to address those? I guess I need to stick a function in ediff-quit-merge-hook and emerge-quit-hook. But then? How do I print the merge buffer's contents to stdout? And how can I influence the exit code? (I could do (kill-emacs my-exit-code) but would be more happy if I could also use the merge command with emacsclient where I obviously don't want to kill emacs.) Bye, Tassilo