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: 59484 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 5011F27BBEC; Sat, 27 Jan 2024 20:28:28 +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 A278327BBE2 for ; Sat, 27 Jan 2024 20:28:23 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rTpHT-0006Og-QP; Sat, 27 Jan 2024 15:28:00 -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 1rTpHQ-0006O8-AL for guix-patches@gnu.org; Sat, 27 Jan 2024 15:27:56 -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 1rTpHQ-0000yb-2l for guix-patches@gnu.org; Sat, 27 Jan 2024 15:27:56 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rTpHX-0004FX-9o for guix-patches@gnu.org; Sat, 27 Jan 2024 15:28:03 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#68412] [PATCH v2] scripts: edit: Accept generic formatting parameter. References: <9a666abbf1cb4b7548c1a117eaa04b0de02145ae.1705103171.git.liliana.prikler@gmail.com> In-Reply-To: <9a666abbf1cb4b7548c1a117eaa04b0de02145ae.1705103171.git.liliana.prikler@gmail.com> Resent-From: Liliana Marie Prikler Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 27 Jan 2024 20:28:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 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 Received: via spool by 68412-submit@debbugs.gnu.org id=B68412.170638724216262 (code B ref 68412); Sat, 27 Jan 2024 20:28:03 +0000 Received: (at 68412) by debbugs.gnu.org; 27 Jan 2024 20:27:22 +0000 Received: from localhost ([127.0.0.1]:56002 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rTpGr-0004EC-U3 for submit@debbugs.gnu.org; Sat, 27 Jan 2024 15:27:22 -0500 Received: from mail-ej1-x644.google.com ([2a00:1450:4864:20::644]:49166) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rTpGo-0004Dk-Gs for 68412@debbugs.gnu.org; Sat, 27 Jan 2024 15:27:19 -0500 Received: by mail-ej1-x644.google.com with SMTP id a640c23a62f3a-a357cba4a32so7106666b.2 for <68412@debbugs.gnu.org>; Sat, 27 Jan 2024 12:27:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706387225; x=1706992025; darn=debbugs.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=EGaMVwb1gwOvWEf42/JMqeLDVmey4lHs9+h8XkxFy1k=; b=U/z0xl6DNTRHT/eoylA/IGPMJtb4nMjFchGUbPnLkUwLlyNP+mXLO+2foh1jLjJyMY ZLWW/0s6nsX/GB6HlSYR+FNjhdf8+uM7y2C3PKoKpgJBbEGAFbG65fCpU9HuaWKxQIYm TRop1Jix8DqAOrMKwRDjGDutf6sgNkWq3g6xkzEMJthvR/FWcGCnHyotKKWz1mkHUYB2 mXMpmxpL76ecYBt+p4mjxRiCY9ZnhUDDDZYx9Yck34SG83WekpzbejfMXg25vWevnF61 cTjMpKQzOHA0gRApm6/304/TCm1MW7gyYMrqRlw8IxbE6ku+KncSjaaustfWQfGof40f GMcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706387225; x=1706992025; 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=EGaMVwb1gwOvWEf42/JMqeLDVmey4lHs9+h8XkxFy1k=; b=bdP+c46+G+1m5OnU47BLjV+kpy7FEBXGjR+lf2J9ggqEJQ3pwtJf/odSzRD9rS//tL kMs3/dtT5AwalhUCAtR0XwU+TXffMIYb6rg5+LjJuexcWv/3omdYlt857JaYiQB61bzJ rIVs+PzKuCgJoWr/4Q6OF8pVXkPAztuwl7Dx18EfN9lRgkozGGFy44tDyRqZ3kOc0n4Z nveojUu6JWreF7ke9/Qu2sPtpLe5zHja4OROVUlPm6bGk0o80eWqe8XEOkxXgCQ9iolD jHW2rK/e+EpRxPzhXb5fASNB8uXRMWK8BsQ0vkcZW4UTkLk2Pn1YC0QPzG+H/vyaDLlA VsXA== X-Gm-Message-State: AOJu0YyNSeaS/BtnMzjMuChvtI3yQcbPQVlYucnh1O0e6l66ThMcmEx2 O8mMAwaQAqDULsw1AfpTcJ8zQ/KoJ9r6i0PAYO7ZTfG7BccKVkGydnwcrFn9PQE= X-Google-Smtp-Source: AGHT+IEAHLQwq9G/r7jfp0r2u5olLVqr0gADjiOwuuQ8UoSWaurgBfVcbfrKcjd1jozn7nzcHeSvFQ== X-Received: by 2002:a17:906:6953:b0:a34:af8a:ee3d with SMTP id c19-20020a170906695300b00a34af8aee3dmr1466685ejs.16.1706387225197; Sat, 27 Jan 2024 12:27:05 -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 rs10-20020a170907036a00b00a316a652c6csm2069718ejb.70.2024.01.27.12.27.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 27 Jan 2024 12:27:04 -0800 (PST) Message-ID: <86b13fd4916ffecb1947d0879805a6d0c32542bf.1706386650.git.liliana.prikler@gmail.com> From: Liliana Marie Prikler Date: Sat, 13 Jan 2024 00:35:29 +0100 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-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’ --- Am Samstag, dem 27.01.2024 um 15:07 +0100 schrieb Ludovic Courtès: > Hi Liliana, > > Liliana Marie Prikler skribis: > > > 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’ > > Rather: “Fixes .” I'm using a convention that I've proposed earlier in [1]. Since we're currently adding ChangeIds without any of the supported infra (AFAIK), I think following my own proposal here is fair game. As for why I took the message instead of the bug itself, the bug was marked as done without resolving it, so I think linking to the message is more correct. > [...] > I’d word it slightly differently, like: > [...] I changed the wording. Let me know WDYT. > Leftover debugging statement? Yup. > I’m still wondering about the relative merits of this approach vs. > the less generic but ready-to-use special-casing of Kate and VSCode > [...] With every decade bringing a new hot editor, we'd be special-casing a lot. Cheers [1] https://lists.gnu.org/archive/html/guix-devel/2023-09/msg00225.html doc/guix.texi | 29 +++++++++++++++++++++++++++++ guix/scripts/edit.scm | 20 ++++++++++++++------ 2 files changed, 43 insertions(+), 6 deletions(-) base-commit: dc8aa525174d25331d74576faf0643e45bc152c4 diff --git a/doc/guix.texi b/doc/guix.texi index c458befb76..2ae3871464 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -13989,6 +13989,35 @@ 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. +@vindex GUIX_EDITOR_LOCATION_FORMAT +The default convention used by @code{guix edit} when invoking +@code{$EDITOR} is to pass it @code{+@var{line} @var{file}} to open +@var{file} at the given @var{line}. +You can change this convention for editors that do not support it +by setting @env{GUIX_EDITOR_LOCATION_FORMAT}. +For instance, to set things up with kate, use: + +@example +export VISUAL=kate +export GUIX_EDITOR_LOCATION_FORMAT='--line=$@{LINE@} $@{FILE@}' +# Assume you want to hack on kate +guix edit kate +@end example + +Alternatively, for gnome-text-editor, which has no such flag, simply +skip it: + +@example +export VISUAL=gnome-text-editor +export GUIX_EDITOR_LOCATION_FORMAT='$@{FILE@}' +# Assume you want to hack on gnome +guix edit gnome +@end example + +Note, that Guix only matches the literal strings @code{$@{LINE@}} and +@code{$@{FILE@}} here. These may look like shell parameters, but their +short form is currently not supported. + @node Invoking guix download @section Invoking @command{guix download} diff --git a/guix/scripts/edit.scm b/guix/scripts/edit.scm index b7b4cd2514..130470dbc1 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 (%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))))))