From patchwork Wed Jun 1 15:42:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 39706 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 9F6A327BBEA; Wed, 1 Jun 2022 16:44:13 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 464CB27BBE9 for ; Wed, 1 Jun 2022 16:44:13 +0100 (BST) Received: from localhost ([::1]:57780 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nwQW4-0004Dg-EX for patchwork@mira.cbaines.net; Wed, 01 Jun 2022 11:44:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48340) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nwQVu-0004CR-CP for guix-patches@gnu.org; Wed, 01 Jun 2022 11:44:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:57751) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nwQVu-00088r-3L for guix-patches@gnu.org; Wed, 01 Jun 2022 11:44:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nwQVu-0001WS-1X for guix-patches@gnu.org; Wed, 01 Jun 2022 11:44:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#55752] [PATCH 1/5] edit: Extract 'spawn-editor' procedure. References: <20220601154140.16178-1-ludo@gnu.org> In-Reply-To: <20220601154140.16178-1-ludo@gnu.org> Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 01 Jun 2022 15:44:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 55752 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 55752@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= Received: via spool by 55752-submit@debbugs.gnu.org id=B55752.16540982015752 (code B ref 55752); Wed, 01 Jun 2022 15:44:01 +0000 Received: (at 55752) by debbugs.gnu.org; 1 Jun 2022 15:43:21 +0000 Received: from localhost ([127.0.0.1]:51640 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nwQVF-0001Uh-9Y for submit@debbugs.gnu.org; Wed, 01 Jun 2022 11:43:21 -0400 Received: from eggs.gnu.org ([209.51.188.92]:54956) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nwQVD-0001U8-1r for 55752@debbugs.gnu.org; Wed, 01 Jun 2022 11:43:19 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:37370) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nwQV5-00083E-DL; Wed, 01 Jun 2022 11:43:11 -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=q4GMJVRvZUusTmNcjc3CT9qCqODFhQBFpXZ+NWSBu/Y=; b=KSaWhV8euNZhIe Kj1OgQWNWTyn1+3JEjD6icSEoeQKf2npTSi3OIH8tpbJ6lQfpUM903byAggm8wwiIEti75N+qTbJC DBoAqHPsulWAkve4L3K6ivtCwOwcto/erb1CTTbiyfmGXLDrsRMHYImh+M9+dMXMzTLSl1jSklGPR F9V7JlZY7XBeKpX0nXDS0SL6SQ8mdvch9lCqpvzE1bSy7CAVACkTaCm+0dm2kNW1w7gipVHQGMysx K8pBqDjeWiojFznn2QHEJG92s+WaQaKGUlCgTZtqNEsjx+gL01reLCTW158YqZ/WgBcvRnutpCPvI VLKFoGdjkjUCSjN7LWCQ==; Received: from 91-160-117-201.subs.proxad.net ([91.160.117.201]:55618 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nwQV5-0006Xy-0f; Wed, 01 Jun 2022 11:43:11 -0400 From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Wed, 1 Jun 2022 17:42:58 +0200 Message-Id: <20220601154302.16222-1-ludo@gnu.org> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * guix/scripts/edit.scm (spawn-editor): New procedure, with code from... (guix-edit): ... here. Use it. --- guix/scripts/edit.scm | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/guix/scripts/edit.scm b/guix/scripts/edit.scm index a2e1ffb434..8e777d1405 100644 --- a/guix/scripts/edit.scm +++ b/guix/scripts/edit.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2015, 2016, 2019, 2020, 2021 Ludovic Courtès +;;; Copyright © 2015-2016, 2019-2022 Ludovic Courtès ;;; Copyright © 2015 Mathieu Lirzin ;;; Copyright © 2020, 2021 Simon Tournier ;;; @@ -27,6 +27,7 @@ (define-module (guix scripts edit) #:use-module (srfi srfi-1) #:use-module (srfi srfi-37) #:export (%editor + spawn-editor guix-edit)) (define %options @@ -77,6 +78,21 @@ (define (location->location-specification location) (location-line location))) (search-path* %load-path (location-file location)))) +(define (spawn-editor locations) + "Spawn (%editor) to edit the code at LOCATIONS, a list of +records, and exit." + (catch 'system-error + (lambda () + (let ((file-names (append-map location->location-specification + locations))) + ;; Use `system' instead of `exec' in order to sanely handle + ;; possible command line arguments in %EDITOR. + (exit (system (string-join (cons (%editor) file-names)))))) + (lambda args + (let ((errno (system-error-errno args))) + (leave (G_ "failed to launch '~a': ~a~%") + (%editor) (strerror errno)))))) + (define-command (guix-edit . args) (category packaging) @@ -94,14 +110,4 @@ (define (parse-arguments) (when (null? specs) (leave (G_ "no packages specified, nothing to edit~%"))) - (catch 'system-error - (lambda () - (let ((file-names (append-map location->location-specification - locations))) - ;; Use `system' instead of `exec' in order to sanely handle - ;; possible command line arguments in %EDITOR. - (exit (system (string-join (cons (%editor) file-names)))))) - (lambda args - (let ((errno (system-error-errno args))) - (leave (G_ "failed to launch '~a': ~a~%") - (%editor) (strerror errno)))))))) + (spawn-editor locations))))