Hi,

As every sane person I use Emacs for my editing.  In order to have the
features of ‘emacsclient’ (fast startup + buffer sharing) and the
simplicity of ‘emacs’ (no daemon management), I have in my environment:

  export VISUAL="emacsclient --alternate-editor=''"

this automatically starts the daemon if it is not already running and
then launches ‘emacsclient’.  However, this does not work with ‘guix
edit’ because a single word command is assumed for $VISUAL and $EDITOR.

so here is a fix:

>From 9252f698348db42431264441a5e97fd5a414c001 Mon Sep 17 00:00:00 2001
From: Mathieu Lirzin <[email protected]>
Date: Sat, 21 Nov 2015 14:37:54 +0100
Subject: [PATCH 1/2] edit: Allow command line arguments in $VISUAL and
 $EDITOR.

* guix/scripts/edit.scm (guix-edit): Fix the assumption that %editor is
  a one word command.
---
 guix/scripts/edit.scm | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/guix/scripts/edit.scm b/guix/scripts/edit.scm
index 73a5bb7..f894953 100644
--- a/guix/scripts/edit.scm
+++ b/guix/scripts/edit.scm
@@ -1,5 +1,6 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2015 Ludovic Courtès <[email protected]>
+;;; Copyright © 2015 Mathieu Lirzin <[email protected]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -22,6 +23,7 @@
   #:use-module (guix utils)
   #:use-module (guix packages)
   #:use-module (gnu packages)
+  #:use-module (ice-9 match)
   #:use-module (srfi srfi-1)
   #:use-module (srfi srfi-37)
   #:export (%editor
@@ -83,8 +85,13 @@ line."
 
       (catch 'system-error
         (lambda ()
-          (apply execlp (%editor) (%editor)
-                 (append-map package->location-specification packages)))
+          (let ((editor-args (string-split (%editor) #\space))
+                (file-names  (append-map package->location-specification
+                                         packages)))
+            (match editor-args
+              ((editor . args)
+               (apply execlp editor (append editor-args file-names)))
+              (_ #f))))
         (lambda args
           (let ((errno (system-error-errno args)))
             (leave (_ "failed to launch '~a': ~a~%")
-- 
2.6.2

Moreover I think that assuming a running emacs daemon by default if
$VISUAL and $EDITOR are not set is not an obvious decision.  My first
intuition would be to use GNU Nano which is often installed on GNU
systems.  But after trying to edit a package with it... I have come to
the conclusion that it was more reasonable to use 'emacs' instead.

I have no strong opinion on this (other than being against defaulting to
VI of course).  ;)

>From 7988fd52a23811720c82f20b5b65eb527564a7f6 Mon Sep 17 00:00:00 2001
From: Mathieu Lirzin <[email protected]>
Date: Sat, 21 Nov 2015 15:05:07 +0100
Subject: [PATCH 2/2] edit: Don't assume that an emacs daemon is running.

* guix/scripts/edit.scm (%editor): Use Emacs as a default value.
---
 guix/scripts/edit.scm | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/guix/scripts/edit.scm b/guix/scripts/edit.scm
index f894953..5dbb58d 100644
--- a/guix/scripts/edit.scm
+++ b/guix/scripts/edit.scm
@@ -50,8 +50,10 @@ Start $VISUAL or $EDITOR to edit the definitions of PACKAGE...\n"))
   (show-bug-report-information))
 
 (define %editor
-  (make-parameter (or (getenv "VISUAL") (getenv "EDITOR")
-                      "emacsclient")))
+  ;; XXX: It would be better to default to something more likely to be
+  ;; pre-installed on an average GNU system.  Since Nano is not suited for
+  ;; editing Scheme, Emacs is used instead.
+  (make-parameter (or (getenv "VISUAL") (getenv "EDITOR") "emacs")))
 
 (define (search-path* path file)
   "Like 'search-path' but exit if FILE is not found."
-- 
2.6.2

TIA,

--
Mathieu Lirzin

Reply via email to