all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Liliana Marie Prikler <liliana.prikler@gmail.com>
To: 68412@debbugs.gnu.org
Cc: "Ludovic Courtès" <ludo@gnu.org>,
	"Simon Tournier" <zimon.toutoune@gmail.com>
Subject: [bug#68412] [PATCH] scripts: edit: Accept generic formatting parameter.
Date: Sat, 13 Jan 2024 00:35:29 +0100	[thread overview]
Message-ID: <9a666abbf1cb4b7548c1a117eaa04b0de02145ae.1705103171.git.liliana.prikler@gmail.com> (raw)

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’ <https://bugs.gnu.org/44272#14>
---
 doc/guix.texi         | 18 ++++++++++++++++++
 guix/scripts/edit.scm | 20 ++++++++++++++------
 2 files changed, 32 insertions(+), 6 deletions(-)

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 <location>
 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))))))

base-commit: 3619dd7d059d1141acf39872f57e55b458dc8257
-- 
2.41.0





             reply	other threads:[~2024-01-12 23:47 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-12 23:35 Liliana Marie Prikler [this message]
2024-01-12 23:35 ` [bug#68412] [PATCH v2] scripts: edit: Accept generic formatting parameter Liliana Marie Prikler
2024-01-29 11:10   ` Simon Tournier
2024-01-29 17:58     ` Liliana Marie Prikler
2024-02-07 22:22       ` Ludovic Courtès
2024-02-08 18:09         ` Liliana Marie Prikler
2024-02-10  9:58           ` Ludovic Courtès
2024-02-10 11:01             ` Simon Tournier
2024-02-13 15:04               ` Liliana Marie Prikler
2024-02-14 11:19                 ` Simon Tournier
2024-01-29 13:24   ` Ludovic Courtès
2024-01-29 14:07     ` Simon Tournier
2024-01-27 14:07 ` [bug#68412] [PATCH] " Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9a666abbf1cb4b7548c1a117eaa04b0de02145ae.1705103171.git.liliana.prikler@gmail.com \
    --to=liliana.prikler@gmail.com \
    --cc=68412@debbugs.gnu.org \
    --cc=ludo@gnu.org \
    --cc=zimon.toutoune@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.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.