unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] edit: Friendlier error message.
@ 2015-11-04 22:42 benno
  2015-11-05 11:08 ` Ludovic Courtès
  0 siblings, 1 reply; 7+ messages in thread
From: benno @ 2015-11-04 22:42 UTC (permalink / raw)
  To: guix-devel; +Cc: Benno Evers

From: Benno Evers <benno@bmevers.de>

* guix/scripts/edit.scm (guix-edit): Check if %editor exists.
---
These are my first lines of guile, so probably there is a much
better way to do this :D

The previous error message ("execlp: No such file or directory")
had me confused for a while, though.

 guix/scripts/edit.scm | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/guix/scripts/edit.scm b/guix/scripts/edit.scm
index 30146af..9225629 100644
--- a/guix/scripts/edit.scm
+++ b/guix/scripts/edit.scm
@@ -62,6 +62,9 @@ Start $EDITOR to edit the definitions of PACKAGE...\n"))
 \f
 (define (guix-edit . args)
   (with-error-handling
+    (unless (search-path (parse-path (getenv "PATH")) (%editor))
+      (leave (_ "Couldn't find editor '~a'. Please check $EDITOR and $PATH.")
+             (%editor)))
     (let* ((specs    (parse-command-line args %options '(())
                                          #:argument-handler cons))
            (packages (map specification->package specs)))
-- 
2.5.0

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

* Re: [PATCH] edit: Friendlier error message.
  2015-11-04 22:42 [PATCH] edit: Friendlier error message benno
@ 2015-11-05 11:08 ` Ludovic Courtès
  2015-11-07  3:25   ` Andreas Enge
  0 siblings, 1 reply; 7+ messages in thread
From: Ludovic Courtès @ 2015-11-05 11:08 UTC (permalink / raw)
  To: benno; +Cc: guix-devel

benno@bmevers.de skribis:

> From: Benno Evers <benno@bmevers.de>
>
> * guix/scripts/edit.scm (guix-edit): Check if %editor exists.
> ---
> These are my first lines of guile, so probably there is a much
> better way to do this :D
>
> The previous error message ("execlp: No such file or directory")
> had me confused for a while, though.

Indeed.

You’re doing OK Scheme-wise, no worries!  ;-)

> +    (unless (search-path (parse-path (getenv "PATH")) (%editor))
> +      (leave (_ "Couldn't find editor '~a'. Please check $EDITOR and $PATH.")
> +             (%editor)))

In commit 650f161, I did things slightly differently by catching the
actual ‘execl’ exception and reporting it.  This is more accurate than
using ‘search-path’ because there could be other errors (invalid
permissions, etc.) and possibly TOCTTOU races.

Thank you!

Ludo’.

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

* Re: [PATCH] edit: Friendlier error message.
  2015-11-05 11:08 ` Ludovic Courtès
@ 2015-11-07  3:25   ` Andreas Enge
  2015-11-07 11:06     ` Ludovic Courtès
  0 siblings, 1 reply; 7+ messages in thread
From: Andreas Enge @ 2015-11-07  3:25 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guix-devel, benno

On Thu, Nov 05, 2015 at 12:08:35PM +0100, Ludovic Courtès wrote:
> > +    (unless (search-path (parse-path (getenv "PATH")) (%editor))
> > +      (leave (_ "Couldn't find editor '~a'. Please check $EDITOR and $PATH.")
> > +             (%editor)))

An additional, heterodox suggestion: Maybe also test for $VISUAL.

Andreas

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

* Re: [PATCH] edit: Friendlier error message.
  2015-11-07  3:25   ` Andreas Enge
@ 2015-11-07 11:06     ` Ludovic Courtès
  2015-11-07 12:24       ` Mathieu Lirzin
  0 siblings, 1 reply; 7+ messages in thread
From: Ludovic Courtès @ 2015-11-07 11:06 UTC (permalink / raw)
  To: Andreas Enge; +Cc: guix-devel, benno

Andreas Enge <andreas@enge.fr> skribis:

> On Thu, Nov 05, 2015 at 12:08:35PM +0100, Ludovic Courtès wrote:
>> > +    (unless (search-path (parse-path (getenv "PATH")) (%editor))
>> > +      (leave (_ "Couldn't find editor '~a'. Please check $EDITOR and $PATH.")
>> > +             (%editor)))
>
> An additional, heterodox suggestion: Maybe also test for $VISUAL.

AIUI, $VISUAL is for visualizing files, not for editing, no?

Ludo’.

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

* Re: [PATCH] edit: Friendlier error message.
  2015-11-07 11:06     ` Ludovic Courtès
@ 2015-11-07 12:24       ` Mathieu Lirzin
  2015-11-11 22:01         ` Ludovic Courtès
  0 siblings, 1 reply; 7+ messages in thread
From: Mathieu Lirzin @ 2015-11-07 12:24 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guix-devel, benno

ludo@gnu.org (Ludovic Courtès) writes:

> Andreas Enge <andreas@enge.fr> skribis:
>
>> On Thu, Nov 05, 2015 at 12:08:35PM +0100, Ludovic Courtès wrote:
>>> > +    (unless (search-path (parse-path (getenv "PATH")) (%editor))
>>> > +      (leave (_ "Couldn't find editor '~a'. Please check $EDITOR and $PATH.")
>>> > +             (%editor)))
>>
>> An additional, heterodox suggestion: Maybe also test for $VISUAL.
>
> AIUI, $VISUAL is for visualizing files, not for editing, no?

I can't remember where I have read this, but I think this 2 variables
exist to distinguish between line editing à la Ed, and visual editing
à la VI.

--
Mathieu Lirzin

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

* Re: [PATCH] edit: Friendlier error message.
  2015-11-07 12:24       ` Mathieu Lirzin
@ 2015-11-11 22:01         ` Ludovic Courtès
  2015-11-15  4:26           ` Andreas Enge
  0 siblings, 1 reply; 7+ messages in thread
From: Ludovic Courtès @ 2015-11-11 22:01 UTC (permalink / raw)
  To: Mathieu Lirzin; +Cc: guix-devel, benno

Mathieu Lirzin <mthl@gnu.org> skribis:

> ludo@gnu.org (Ludovic Courtès) writes:
>
>> Andreas Enge <andreas@enge.fr> skribis:
>>
>>> On Thu, Nov 05, 2015 at 12:08:35PM +0100, Ludovic Courtès wrote:
>>>> > +    (unless (search-path (parse-path (getenv "PATH")) (%editor))
>>>> > +      (leave (_ "Couldn't find editor '~a'. Please check $EDITOR and $PATH.")
>>>> > +             (%editor)))
>>>
>>> An additional, heterodox suggestion: Maybe also test for $VISUAL.
>>
>> AIUI, $VISUAL is for visualizing files, not for editing, no?
>
> I can't remember where I have read this, but I think this 2 variables
> exist to distinguish between line editing à la Ed, and visual editing
> à la VI.

SUS mentions ‘VISUAL’ but without saying what it’s for:

  http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08

But
<http://unix.stackexchange.com/questions/4859/visual-vs-editor-whats-the-difference>
says something that seems to make sense, like what you wrote.

I’ve committed a change that honors $VISUAL first, $EDITOR second.

Thanks,
Ludo’.

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

* Re: [PATCH] edit: Friendlier error message.
  2015-11-11 22:01         ` Ludovic Courtès
@ 2015-11-15  4:26           ` Andreas Enge
  0 siblings, 0 replies; 7+ messages in thread
From: Andreas Enge @ 2015-11-15  4:26 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guix-devel, benno

On Wed, Nov 11, 2015 at 11:01:30PM +0100, Ludovic Courtès wrote:
> I’ve committed a change that honors $VISUAL first, $EDITOR second.

Great, it works in my setting where $EDITOR is empty and $VISUAL equals vim
(without me setting either of them, if I remember correctly; some debian
magic must have created the variables). Thanks!

Andreas

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

end of thread, other threads:[~2015-11-15  4:26 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-04 22:42 [PATCH] edit: Friendlier error message benno
2015-11-05 11:08 ` Ludovic Courtès
2015-11-07  3:25   ` Andreas Enge
2015-11-07 11:06     ` Ludovic Courtès
2015-11-07 12:24       ` Mathieu Lirzin
2015-11-11 22:01         ` Ludovic Courtès
2015-11-15  4:26           ` Andreas Enge

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).