all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [bug#68412] [PATCH] scripts: edit: Accept generic formatting parameter.
@ 2024-01-12 23:35 Liliana Marie Prikler
  2024-01-12 23:35 ` [bug#68412] [PATCH v2] " Liliana Marie Prikler
  2024-01-27 14:07 ` [bug#68412] [PATCH] " Ludovic Courtès
  0 siblings, 2 replies; 13+ messages in thread
From: Liliana Marie Prikler @ 2024-01-12 23:35 UTC (permalink / raw)
  To: 68412; +Cc: Ludovic Courtès, Simon Tournier

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





^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2024-02-15  9:55 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-12 23:35 [bug#68412] [PATCH] scripts: edit: Accept generic formatting parameter Liliana Marie Prikler
2024-01-12 23:35 ` [bug#68412] [PATCH v2] " 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

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.