mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2024-12-28 15:22:18 -05:00
edit: Extract 'spawn-editor' procedure.
* guix/scripts/edit.scm (spawn-editor): New procedure, with code from... (guix-edit): ... here. Use it.
This commit is contained in:
parent
104b4e25ab
commit
f9fb00ff08
1 changed files with 18 additions and 12 deletions
|
@ -1,5 +1,5 @@
|
|||
;;; GNU Guix --- Functional package management for GNU
|
||||
;;; Copyright © 2015, 2016, 2019, 2020, 2021 Ludovic Courtès <ludo@gnu.org>
|
||||
;;; Copyright © 2015-2016, 2019-2022 Ludovic Courtès <ludo@gnu.org>
|
||||
;;; Copyright © 2015 Mathieu Lirzin <mthl@gnu.org>
|
||||
;;; Copyright © 2020, 2021 Simon Tournier <zimon.toutoune@gmail.com>
|
||||
;;;
|
||||
|
@ -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 <location>
|
||||
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))))
|
||||
|
|
Loading…
Reference in a new issue