unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
* $EDITOR and “guix edit”
@ 2023-11-02  9:43 Simon Tournier
  2023-11-02 10:24 ` Liliana Marie Prikler
  0 siblings, 1 reply; 8+ messages in thread
From: Simon Tournier @ 2023-11-02  9:43 UTC (permalink / raw)
  To: Guix Devel

Hi,

The command “guix edit” returns “+N path/to/file” that is then passed to
$EDITOR.  Therefore $EDITOR needs the command line:

    $ $EDITOR +N /path/to/file

Well, that is accepted by many $EDITOR, to my knowledge.  At least,
Emacs, Vi or less are fine with it.

However, some other $EDITOR does not.  I have in mind “kate” or
“VSCode“,

    $ kate -l N path/to/file
    $ code --goto path/to/file:N

This had been raised in #44272 [1].  The current fix is to wrap $EDITOR
and then make the current correct call.

The question is:

  do we tweak “guix edit” for behaving differently depending on $EDITOR?

or

  do we provide some wrappers for the issues that already popped up?

WDYT?

Cheers,
simon

1: https://issues.guix.gnu.org/44272


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

* Re: $EDITOR and “guix edit”
  2023-11-02  9:43 $EDITOR and “guix edit” Simon Tournier
@ 2023-11-02 10:24 ` Liliana Marie Prikler
  2023-11-16 15:25   ` Ludovic Courtès
  0 siblings, 1 reply; 8+ messages in thread
From: Liliana Marie Prikler @ 2023-11-02 10:24 UTC (permalink / raw)
  To: Simon Tournier, Guix Devel

Am Donnerstag, dem 02.11.2023 um 10:43 +0100 schrieb Simon Tournier:
> Hi,
> 
> The command “guix edit” returns “+N path/to/file” that is then passed
> to $EDITOR.  Therefore $EDITOR needs the command line:
> 
>     $ $EDITOR +N /path/to/file
> 
> Well, that is accepted by many $EDITOR, to my knowledge.  At least,
> Emacs, Vi or less are fine with it.
This appears to be a somewhat archaic convention.  Since less used +N,
many other tools inherited it from it; POSIX requires -p for more since
2008 instead (ironically, it laments the incompatibility with vi and
ex, which use -c).

> However, some other $EDITOR does not.  I have in mind “kate” or
> “VSCode“,
> 
>     $ kate -l N path/to/file
>     $ code --goto path/to/file:N
> 
> This had been raised in #44272 [1].  The current fix is to wrap
> $EDITOR and then make the current correct call.
> 
> The question is:
> 
>   do we tweak “guix edit” for behaving differently depending on
> $EDITOR?
> 
> or
> 
>   do we provide some wrappers for the issues that already popped up?
I think we should at least document our behaviour, so that there's
"less surprise" (at the very least, we can point surprised folk towards
the manual/cookbook then).  Going forward, we might want to call upon
some standards committee to finally have +LINE:COL or similar
standardized behaviour for $EDITOR and $VISUAL and then use that.

Cheers


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

* Re: $EDITOR and “guix edit”
  2023-11-02 10:24 ` Liliana Marie Prikler
@ 2023-11-16 15:25   ` Ludovic Courtès
  2023-11-16 16:04     ` Liliana Marie Prikler
  0 siblings, 1 reply; 8+ messages in thread
From: Ludovic Courtès @ 2023-11-16 15:25 UTC (permalink / raw)
  To: Liliana Marie Prikler; +Cc: Simon Tournier, Guix Devel

Liliana Marie Prikler <liliana.prikler@gmail.com> skribis:

> Am Donnerstag, dem 02.11.2023 um 10:43 +0100 schrieb Simon Tournier:
>> Hi,
>> 
>> The command “guix edit” returns “+N path/to/file” that is then passed
>> to $EDITOR.  Therefore $EDITOR needs the command line:
>> 
>>     $ $EDITOR +N /path/to/file
>> 
>> Well, that is accepted by many $EDITOR, to my knowledge.  At least,
>> Emacs, Vi or less are fine with it.
> This appears to be a somewhat archaic convention.

“Archaic” is one way to describe it; I’d have said “standard”.  :-)
(Implemented by Vi(m), Emacs, Nano, less, more, etc.)

>> However, some other $EDITOR does not.  I have in mind “kate” or
>> “VSCode“,
>> 
>>     $ kate -l N path/to/file
>>     $ code --goto path/to/file:N

It’d be nice to support these as well.  However, how do we know we’re
dealing with kate or VSCode?  By checking the basename of $EDITOR?
Kinda ugly and brittle, but probably better than nothing.

Thanks,
Ludo’.


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

* Re: $EDITOR and “guix edit”
  2023-11-16 15:25   ` Ludovic Courtès
@ 2023-11-16 16:04     ` Liliana Marie Prikler
  2023-11-20  9:40       ` Simon Tournier
  2023-11-22 18:21       ` Ludovic Courtès
  0 siblings, 2 replies; 8+ messages in thread
From: Liliana Marie Prikler @ 2023-11-16 16:04 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: Simon Tournier, Guix Devel

Am Donnerstag, dem 16.11.2023 um 16:25 +0100 schrieb Ludovic Courtès:
> Liliana Marie Prikler <liliana.prikler@gmail.com> skribis:
> 
> > Am Donnerstag, dem 02.11.2023 um 10:43 +0100 schrieb Simon
> > Tournier:
> > > Hi,
> > > 
> > > The command “guix edit” returns “+N path/to/file” that is then
> > > passed to $EDITOR.  Therefore $EDITOR needs the command line:
> > > 
> > >     $ $EDITOR +N /path/to/file
> > > 
> > > Well, that is accepted by many $EDITOR, to my knowledge.  At
> > > least, Emacs, Vi or less are fine with it.
> > This appears to be a somewhat archaic convention.
> 
> “Archaic” is one way to describe it; I’d have said “standard”.  :-)
> (Implemented by Vi(m), Emacs, Nano, less, more, etc.)
I said “archaic”, because POSIX specifically says “all options should
be preceded by the '-' character”, with special exceptions for more,
etc. for backwards compatibility.  It's a bit of a pain, because the
argument that used to be standard among all those tools has (in POSIX
at least) been replaced by several dashed ones.

> > > However, some other $EDITOR does not.  I have in mind “kate” or
> > > “VSCode“,
> > > 
> > >     $ kate -l N path/to/file
> > >     $ code --goto path/to/file:N
> 
> It’d be nice to support these as well.  However, how do we know we’re
> dealing with kate or VSCode?  By checking the basename of $EDITOR?
> Kinda ugly and brittle, but probably better than nothing.
Maybe we can check for a guix_editor shell function and invoke that
rather than EDITOR if defined?

Cheers 


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

* Re: $EDITOR and “guix edit”
  2023-11-16 16:04     ` Liliana Marie Prikler
@ 2023-11-20  9:40       ` Simon Tournier
  2023-11-20 19:33         ` Liliana Marie Prikler
  2023-11-22 18:21       ` Ludovic Courtès
  1 sibling, 1 reply; 8+ messages in thread
From: Simon Tournier @ 2023-11-20  9:40 UTC (permalink / raw)
  To: Liliana Marie Prikler, Ludovic Courtès; +Cc: Guix Devel

Hi,

On Thu, 16 Nov 2023 at 17:04, Liliana Marie Prikler <liliana.prikler@gmail.com> wrote:

>> It’d be nice to support these as well.  However, how do we know we’re
>> dealing with kate or VSCode?  By checking the basename of $EDITOR?
>> Kinda ugly and brittle, but probably better than nothing.
>
> Maybe we can check for a guix_editor shell function and invoke that
> rather than EDITOR if defined?

Yeah, from my point of view, the two alternatives [1] are:

  1. do we tweak “guix edit” for behaving differently depending on $EDITOR?

or

  2. do we provide some wrappers for the issues that already popped up?

Where #1 is what Ludo suggests and #2 is what Liliana suggests. :-)

Well, see below the code [2] that we concretely need for VSCode.  The
question is:

 1. Do we put this code in guix/scripts/edit.scm?  And trigger on the
 basename of EDITOR?

or

 2. Do we put this code in some etc/vscode-wrapper that user can
 install?  (or that we could automatically installl) Or maybe revamp it
 for calling this code via some shell function?


WDYT?

Cheers,
simon

--8<---------------cut here---------------start------------->8---
#!/usr/bin/env -S guix repl -q --
;; -*- mode: scheme -*-
!#
;;; Copyright © 2023 Simon Tournier <zimon.toutoune@gmail.com>
;;;
;;;
;;; VSCode does not respect the convention:
;;;
;;;     $EDITOR +line file
;;;
;;; and instead relies on:
;;;
;;;     code --goto file:line
;;;
;;;
;;; This wrapper is a workaround.  It is Scheme but it could be whatever else
;;; as Bash, Python, etc.  It uses "guix repl" although no Guix library is
;;; required.  Because we assume the invokation,
;;;
;;;     EDITOR=./vscode-wrapper guix edit foo bar
;;;
;;; relying on "guix repl" allows to easily get Guile.
;;;

(use-modules (ice-9 match)
             ((ice-9 string-fun) #:select (string-replace-substring))
             ((ice-9 ftw) #:select (scandir))
             )

(define %vscode--goto
  (let* ((vscode-server (string-append (getenv "HOME") "/.vscode-server"))
         (code (if (file-exists? vscode-server)
                   ;; Maybe Remote-SSH
                   (let* ((vscode-server/bin (string-append vscode-server "/bin"))
                          (hash         ;Guess the correct identifier
                           (car
                            (scandir vscode-server/bin
                                     (lambda (file)
                                       (not (member file (list "." ".."))))
                                     (lambda (x y)
                                       (> (stat:mtime
                                           (lstat (string-append vscode-server/bin "/" x)))
                                          (stat:mtime
                                           (lstat (string-append vscode-server/bin "/" y))))))))
                          (vscode (string-append
                                   vscode-server/bin "/" hash "/bin/remote-cli/code"))
                          (run/user/uid (string-append "/run/user/"
                                                       (number->string (getuid))))
                          (socket       ;Guess the correct socket, if required
                           (car
                            (scandir run/user/uid
                                     (lambda (file)
                                       (string-prefix? "vscode-ipc" file))
                                     (lambda (x y)
                                       (< (stat:mtime
                                           (lstat (string-append run/user/uid "/" x)))
                                          (stat:mtime
                                           (lstat (string-append run/user/uid "/" y)))))))))
                     ;; XXXX: Check VSCode API for something more robust
                     (if (getenv "VSCODE_IPC_HOOK_CLI")
                         vscode
                         (string-append
                          "VSCODE_IPC_HOOK_CLI=" socket " " vscode)))
                   ;; No Remote-SSH, try to find the local one in PATH
                   (search-path (string-split (getenv "PATH") #\:)
                                "code"))))
                                        ;(format #t "~a~%" code)
    (string-append code " --goto ")))

(define +line-files
  (match (command-line)
    ((wrapper rest ...)
     (if (eqv? 0 (modulo (length rest) 2))
         rest
         (begin
           (write "Error with 'guix edit'")
           (exit 1))))))

(define files
  (let loop ((files:lines '())
             (lst +line-files))
    (if (null? lst)
        (reverse files:lines)
        (match lst
          ((n file rest ...)
           (loop
            (cons (string-append
                   file ":" (string-replace-substring n "+" ""))
                  files:lines)
            rest))))))

(catch 'system-error
  (lambda ()
    (for-each (lambda (file)
                (system (string-append
                         %vscode--goto file)))
              files))
  (lambda _
    (write "failed to launch!")))
--8<---------------cut here---------------end--------------->8---



1: $EDITOR and “guix edit”
Simon Tournier <zimon.toutoune@gmail.com>
Thu, 02 Nov 2023 10:43:57 +0100
id:86wmv0o5gi.fsf@gmail.com
https://lists.gnu.org/archive/html/guix-devel/2023-11
https://yhetil.org/guix/86wmv0o5gi.fsf@gmail.com

2: https://gitlab.com/zimoun/advanced-packages-2023/-/blob/670b81e9321ee4af2407babd985222cc37f33e31/vscode-wrapper


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

* Re: $EDITOR and “guix edit”
  2023-11-20  9:40       ` Simon Tournier
@ 2023-11-20 19:33         ` Liliana Marie Prikler
  0 siblings, 0 replies; 8+ messages in thread
From: Liliana Marie Prikler @ 2023-11-20 19:33 UTC (permalink / raw)
  To: Simon Tournier, Ludovic Courtès; +Cc: Guix Devel

Am Montag, dem 20.11.2023 um 10:40 +0100 schrieb Simon Tournier:
> Hi,
> 
> On Thu, 16 Nov 2023 at 17:04, Liliana Marie Prikler
> <liliana.prikler@gmail.com> wrote:
> 
> > > It’d be nice to support these as well.  However, how do we know
> > > we’re dealing with kate or VSCode?  By checking the basename of
> > > $EDITOR?  Kinda ugly and brittle, but probably better than
> > > nothing.
> > 
> > Maybe we can check for a guix_editor shell function and invoke that
> > rather than EDITOR if defined?
> 
> Yeah, from my point of view, the two alternatives [1] are:
> 
>   1. do we tweak “guix edit” for behaving differently depending on
> $EDITOR?
> 
> or
> 
>   2. do we provide some wrappers for the issues that already popped
> up?
> 
> Where #1 is what Ludo suggests and #2 is what Liliana suggests. :-)
> 
> Well, see below the code [2] that we concretely need for VSCode.  The
> question is:
> 
>  1. Do we put this code in guix/scripts/edit.scm?  And trigger on the
>  basename of EDITOR?
> 
> or
> 
>  2. Do we put this code in some etc/vscode-wrapper that user can
>  install?  (or that we could automatically installl) Or maybe revamp
> it
>  for calling this code via some shell function?
With VSCode et al. not being Guix packages, I see little point in
providing these wrappers through Guix itself.  With kate we could at
least install a "kate-for-guix-edit" wrapper through the package or
something.

Cheers


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

* Re: $EDITOR and “guix edit”
  2023-11-16 16:04     ` Liliana Marie Prikler
  2023-11-20  9:40       ` Simon Tournier
@ 2023-11-22 18:21       ` Ludovic Courtès
  2023-11-22 19:24         ` Liliana Marie Prikler
  1 sibling, 1 reply; 8+ messages in thread
From: Ludovic Courtès @ 2023-11-22 18:21 UTC (permalink / raw)
  To: Liliana Marie Prikler; +Cc: Simon Tournier, Guix Devel

Hello,

Liliana Marie Prikler <liliana.prikler@gmail.com> skribis:

> Am Donnerstag, dem 16.11.2023 um 16:25 +0100 schrieb Ludovic Courtès:

[...]

>> It’d be nice to support these as well.  However, how do we know we’re
>> dealing with kate or VSCode?  By checking the basename of $EDITOR?
>> Kinda ugly and brittle, but probably better than nothing.
> Maybe we can check for a guix_editor shell function and invoke that
> rather than EDITOR if defined?

‘guix edit’ cannot “invoke” a shell function though.

I was thinking of something more gross, like checking whether the
basename of $EDITOR is ‘kate’ or ‘vscode’ and in that case do whatever
is relevant for those editors.

WDYT?

Ludo’.


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

* Re: $EDITOR and “guix edit”
  2023-11-22 18:21       ` Ludovic Courtès
@ 2023-11-22 19:24         ` Liliana Marie Prikler
  0 siblings, 0 replies; 8+ messages in thread
From: Liliana Marie Prikler @ 2023-11-22 19:24 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: Simon Tournier, Guix Devel

Am Mittwoch, dem 22.11.2023 um 19:21 +0100 schrieb Ludovic Courtès:
> Hello,
> 
> Liliana Marie Prikler <liliana.prikler@gmail.com> skribis:
> 
> > Am Donnerstag, dem 16.11.2023 um 16:25 +0100 schrieb Ludovic
> > Courtès:
> 
> [...]
> 
> > > It’d be nice to support these as well.  However, how do we know
> > > we’re
> > > dealing with kate or VSCode?  By checking the basename of
> > > $EDITOR?
> > > Kinda ugly and brittle, but probably better than nothing.
> > Maybe we can check for a guix_editor shell function and invoke that
> > rather than EDITOR if defined?
> 
> ‘guix edit’ cannot “invoke” a shell function though.
> 
> I was thinking of something more gross, like checking whether the
> basename of $EDITOR is ‘kate’ or ‘vscode’ and in that case do
> whatever is relevant for those editors.
> 
> WDYT?
I see your gross "checking whether the basename of $EDITOR is ‘kate’…"
and I raise my "use $GUIX_EDITOR which uses substring replacements for
${LINE} and ${FILE} implemented in pure Guile code"

Cheers


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

end of thread, other threads:[~2023-11-22 19:25 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-02  9:43 $EDITOR and “guix edit” Simon Tournier
2023-11-02 10:24 ` Liliana Marie Prikler
2023-11-16 15:25   ` Ludovic Courtès
2023-11-16 16:04     ` Liliana Marie Prikler
2023-11-20  9:40       ` Simon Tournier
2023-11-20 19:33         ` Liliana Marie Prikler
2023-11-22 18:21       ` Ludovic Courtès
2023-11-22 19:24         ` Liliana Marie Prikler

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