From patchwork Fri Jan 12 23:35:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Liliana Marie Prikler X-Patchwork-Id: 58830 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 F18A227BBEA; Fri, 12 Jan 2024 23:47:19 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham 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 BD44427BBE2 for ; Fri, 12 Jan 2024 23:47:18 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rOREz-0007t3-3A; Fri, 12 Jan 2024 18:47:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rOREv-0007sb-TC for guix-patches@gnu.org; Fri, 12 Jan 2024 18:47:05 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rOREv-0002fb-Km for guix-patches@gnu.org; Fri, 12 Jan 2024 18:47:05 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rOREr-0006Xy-WC for guix-patches@gnu.org; Fri, 12 Jan 2024 18:47:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#68412] [PATCH] scripts: edit: Accept generic formatting parameter. Resent-From: Liliana Marie Prikler Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 12 Jan 2024 23:47:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 68412 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 68412@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= , Simon Tournier X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.170510320624807 (code B ref -1); Fri, 12 Jan 2024 23:47:01 +0000 Received: (at submit) by debbugs.gnu.org; 12 Jan 2024 23:46:46 +0000 Received: from localhost ([127.0.0.1]:37969 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rOREb-0006Rt-4K for submit@debbugs.gnu.org; Fri, 12 Jan 2024 18:46:45 -0500 Received: from lists.gnu.org ([2001:470:142::17]:39148) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rOREX-0006KZ-Io for submit@debbugs.gnu.org; Fri, 12 Jan 2024 18:46:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rORET-0007rq-3W for guix-patches@gnu.org; Fri, 12 Jan 2024 18:46:37 -0500 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rOREQ-0002Mt-7T; Fri, 12 Jan 2024 18:46:36 -0500 Received: by mail-wm1-x343.google.com with SMTP id 5b1f17b1804b1-40e68d836bcso7074315e9.2; Fri, 12 Jan 2024 15:46:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1705103188; x=1705707988; darn=gnu.org; h=cc:to:content-transfer-encoding:mime-version:subject:date:from :message-id:from:to:cc:subject:date:message-id:reply-to; bh=aQFypJtNcnrX8ub64gTq4EpPyf/AL36gfT1suiTftk8=; b=aDFmkLoGgj9ZPh/DkXhOBxFTUqY4P31gERT23BKbDgmcvfqlGtbrL3czLB49dS6FMR 3tr8BXn9TPdVyqlHL3J6zo03ptbLQ9vbyyOuXCI3/i3QkcdsWoUDJ6uRVBbDfs1ByXft DBMgyD/GwGTHiIFoCk2HGlzgL2KnSVVt5Yz8wErwMa2/vv1Xti9a7819kas7qZ9iQG8C VdPtC0LfGCaHo+6OyzhHun+MhwcOXB9G4UL3+MXW14CeNHA/G513ERcbDb0KSK4ANRCb VOlh/0aIFvcOPP+S6HtjdfbXlhFZkuSKaKxNCuoI5XDp1Q/ux0bDM7ZGHseLUjPv4SJH lJCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705103188; x=1705707988; h=cc:to:content-transfer-encoding:mime-version:subject:date:from :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=aQFypJtNcnrX8ub64gTq4EpPyf/AL36gfT1suiTftk8=; b=sKW09BeBlO79jhubv4Bp8zR5+3ss7dycw8g621EOFC9YD1fL6UJxWM3fkNOyVFrrhW /SSZGpvbdG6ROCMDXq2ZtCYiKXprF+pUu1FE/0Z3bHegoQdY6Psx4+K2eogVka61yQUi cN9mCZb0oVpaPC0s9tl02m/G+KnGc2zog4M1O2lREtMm04fK16KJCgH0D0+g6bVxQ3pB p2C7qLRvpnIuoamxRGTVXR9SaemUidn5Cjjz0f6u5vJ+HnlA6nBKcth1KH4cDFpPWvlP VakO8eGpFlF1gM+sZMO9jwAddjh5c+U6wYiCBHvENCBwxEjPgmeiI6xeaZCQSVrorrEf Sq7A== X-Gm-Message-State: AOJu0Yymk4+Klf1B7RbivzjF+8S1+o8PUWrylXBeiugHIjKYrsOT10bl sAYTDKK65Nm1Kmb46eAtUe3U7ucopzOffw== X-Google-Smtp-Source: AGHT+IHl3Ue5/hGkaP/brGiARSRz0irj35y8U8aSXM3KXw57vYE83OIpFb8+QQGIK+5K30fqgRynwA== X-Received: by 2002:a05:600c:474a:b0:40e:4afa:d398 with SMTP id w10-20020a05600c474a00b0040e4afad398mr1115600wmo.14.1705103188066; Fri, 12 Jan 2024 15:46:28 -0800 (PST) Received: from lumine.fritz.box (85-127-52-93.dsl.dynamic.surfer.at. [85.127.52.93]) by smtp.gmail.com with ESMTPSA id r16-20020a056000015000b003376af392e5sm5056942wrx.38.2024.01.12.15.46.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jan 2024 15:46:27 -0800 (PST) Message-ID: <9a666abbf1cb4b7548c1a117eaa04b0de02145ae.1705103171.git.liliana.prikler@gmail.com> From: Liliana Marie Prikler Date: Sat, 13 Jan 2024 00:35:29 +0100 MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::343; envelope-from=liliana.prikler@gmail.com; helo=mail-wm1-x343.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action 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-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches This will hopefully end the opening of unwanted files. * guix/scripts/edit.scm (%location-format): New parameter. (location->location-specification): Use %location-format. (spawn-editor): Adjust accordingly. Fixes: Pass special flags to ‘kate’ --- doc/guix.texi | 18 ++++++++++++++++++ guix/scripts/edit.scm | 20 ++++++++++++++------ 2 files changed, 32 insertions(+), 6 deletions(-) base-commit: 3619dd7d059d1141acf39872f57e55b458dc8257 diff --git a/doc/guix.texi b/doc/guix.texi index 811edd0bf7..8dca1272a2 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -13987,6 +13987,24 @@ Invoking guix edit @var{directory}}) allows you to add @var{directory} to the front of the package module search path and so make your own packages visible. +By default, Guix assumes that @env{EDITOR} uses the +``+@var{LINE} @var{FILE}'' convention to scroll to a particular line +within a file. However, not all editors use this convention. +For instance, @command{kate} instead wants you to use @code{--line}. +Some minimal editors may not even have an option to pass the line. +In both cases, an additional file named ``+@var{LINE}'' would be +opened instead. To prevent this from happening, you can customize +@env{GUIX_EDITOR_LOCATION_FORMAT}, using the literal strings +`${FILE}' to denote @var{FILE} and `${LINE}' to denote @var{LINE} +respectively. +For instance: + +@example +GUIX_EDITOR_LOCATION_FORMAT='${FILE}' guix edit gnome +# will open @var{directory}/gnu/packages/gnome.scm, but not scroll to +# the definition of gnome +@end example + @node Invoking guix download @section Invoking @command{guix download} diff --git a/guix/scripts/edit.scm b/guix/scripts/edit.scm index b7b4cd2514..13b8a4559c 100644 --- a/guix/scripts/edit.scm +++ b/guix/scripts/edit.scm @@ -25,6 +25,7 @@ (define-module (guix scripts edit) #:use-module ((guix diagnostics) #:select (location-file location-line)) #:use-module (gnu packages) + #:use-module (ice-9 string-fun) #:use-module (srfi srfi-1) #:use-module (srfi srfi-37) #:export (%editor @@ -62,6 +63,10 @@ (define %editor ;; For development, user can set custom value for $EDITOR. (make-parameter (or (getenv "VISUAL") (getenv "EDITOR") "nano"))) +(define %location-format + (make-parameter (or (getenv "GUIX_EDITOR_LOCATION_FORMAT") + "+${LINE} ${FILE}"))) + (define (search-path* path file) "Like 'search-path' but exit if FILE is not found." (let ((absolute-file-name (or (search-path path file) @@ -78,18 +83,21 @@ (define (search-path* path file) (define (location->location-specification location) "Return the location specification for LOCATION for a typical editor command line." - (list (string-append "+" - (number->string - (location-line location))) - (search-path* %load-path (location-file location)))) + (let* ((spec (peek (%location-format))) + (spec (string-replace-substring + spec "${LINE}" + (number->string (location-line location)))) + (spec (string-replace-substring + spec "${FILE}" + (search-path* %load-path (location-file location))))) + spec)) (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))) + (let ((file-names (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))))))