unofficial mirror of bug-guix@gnu.org 
 help / color / mirror / code / Atom feed
* bug#44272: guix edit doesn't work when $EDITOR is set to "kate"
@ 2020-10-28  6:13 Nathan Dehnel
  2020-10-28 13:05 ` Leo Prikler
  0 siblings, 1 reply; 7+ messages in thread
From: Nathan Dehnel @ 2020-10-28  6:13 UTC (permalink / raw)
  To: 44272

[-- Attachment #1: Type: text/plain, Size: 26 bytes --]

kate opens an empty file.

[-- Attachment #2: Type: text/html, Size: 51 bytes --]

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

* bug#44272: guix edit doesn't work when $EDITOR is set to "kate"
  2020-10-28  6:13 bug#44272: guix edit doesn't work when $EDITOR is set to "kate" Nathan Dehnel
@ 2020-10-28 13:05 ` Leo Prikler
  2020-10-28 14:52   ` zimoun
  0 siblings, 1 reply; 7+ messages in thread
From: Leo Prikler @ 2020-10-28 13:05 UTC (permalink / raw)
  To: ncdehnel; +Cc: 44272

Easy solution, set $EDITOR to "gedit" ;)

The reason why kate "doesn't work" when opening files as specified by
`guix edit`, is that kate apparently can't handle the "$EDITOR +$N
$FILE" syntax, where $N is the number of lines to skip.  It instead
opens two files, one of which will likely always be empty.  This should
probably be reported as bug to kate unless that works upstream and
somehow guix messes up this feature.





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

* bug#44272: guix edit doesn't work when $EDITOR is set to "kate"
  2020-10-28 13:05 ` Leo Prikler
@ 2020-10-28 14:52   ` zimoun
  2020-10-28 22:28     ` Nathan Dehnel
  2023-11-02  9:32     ` bug#44272: guix edit doesn't work when $EDITOR is set to VSCode Simon Tournier
  0 siblings, 2 replies; 7+ messages in thread
From: zimoun @ 2020-10-28 14:52 UTC (permalink / raw)
  To: Leo Prikler, ncdehnel; +Cc: 44272

Dear Nathan,

> Easy solution, set $EDITOR to "gedit" ;)

Or Emacs. ;-)


> The reason why kate "doesn't work" when opening files as specified by
> `guix edit`, is that kate apparently can't handle the "$EDITOR +$N
> $FILE" syntax, where $N is the number of lines to skip.  It instead
> opens two files, one of which will likely always be empty.  This should
> probably be reported as bug to kate unless that works upstream and
> somehow guix messes up this feature.

Instead ’kate’ use ’--line/-l’ and not ’+N’.  You could wrap, something
along these lines:

--8<---------------cut here---------------start------------->8---
#!/bin/sh

kate -l $(echo "$*" | tr "+" " ")
--8<---------------cut here---------------end--------------->8---

then:

  export EDITOR=/path/to/kate-wrapper.sh
  guix edit emacs

works (with ’/path/to/kate-wrapper.sh’ executable).  Well, the wrapper
could be better, obviously. :-)

As Leo said, it does not seem a bug on the Guix side.  Well, what could
be done on the Guix side?  What do you suggest?


All the best,
simon




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

* bug#44272: guix edit doesn't work when $EDITOR is set to "kate"
  2020-10-28 14:52   ` zimoun
@ 2020-10-28 22:28     ` Nathan Dehnel
  2020-10-28 22:55       ` zimoun
  2023-11-02  9:32     ` bug#44272: guix edit doesn't work when $EDITOR is set to VSCode Simon Tournier
  1 sibling, 1 reply; 7+ messages in thread
From: Nathan Dehnel @ 2020-10-28 22:28 UTC (permalink / raw)
  To: zimoun; +Cc: Leo Prikler, 44272

[-- Attachment #1: Type: text/plain, Size: 1653 bytes --]

>As Leo said, it does not seem a bug on the Guix side.  Well, what could
be done on the Guix side?  What do you suggest?

Well, guix could pass different flags if EDITOR is set to "kate". Somehow I
doubt kate would change their command line flags just because an extremely
obscure distro-specific tool treats it the same as other text editors.

But, whatever. The wrapper works well enough. Thanks.

On Wed, Oct 28, 2020 at 9:52 AM zimoun <zimon.toutoune@gmail.com> wrote:

> Dear Nathan,
>
> > Easy solution, set $EDITOR to "gedit" ;)
>
> Or Emacs. ;-)
>
>
> > The reason why kate "doesn't work" when opening files as specified by
> > `guix edit`, is that kate apparently can't handle the "$EDITOR +$N
> > $FILE" syntax, where $N is the number of lines to skip.  It instead
> > opens two files, one of which will likely always be empty.  This should
> > probably be reported as bug to kate unless that works upstream and
> > somehow guix messes up this feature.
>
> Instead ’kate’ use ’--line/-l’ and not ’+N’.  You could wrap, something
> along these lines:
>
> --8<---------------cut here---------------start------------->8---
> #!/bin/sh
>
> kate -l $(echo "$*" | tr "+" " ")
> --8<---------------cut here---------------end--------------->8---
>
> then:
>
>   export EDITOR=/path/to/kate-wrapper.sh
>   guix edit emacs
>
> works (with ’/path/to/kate-wrapper.sh’ executable).  Well, the wrapper
> could be better, obviously. :-)
>
> As Leo said, it does not seem a bug on the Guix side.  Well, what could
> be done on the Guix side?  What do you suggest?
>
>
> All the best,
> simon
>

[-- Attachment #2: Type: text/html, Size: 2225 bytes --]

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

* bug#44272: guix edit doesn't work when $EDITOR is set to "kate"
  2020-10-28 22:28     ` Nathan Dehnel
@ 2020-10-28 22:55       ` zimoun
  0 siblings, 0 replies; 7+ messages in thread
From: zimoun @ 2020-10-28 22:55 UTC (permalink / raw)
  To: Nathan Dehnel; +Cc: Leo Prikler, 44272-done

Dear,

On Wed, 28 Oct 2020 at 17:28, Nathan Dehnel <ncdehnel@gmail.com> wrote:
>>As Leo said, it does not seem a bug on the Guix side.  Well, what could
>> be done on the Guix side?  What do you suggest?

> Well, guix could pass different flags if EDITOR is set to "kate". Somehow I
> doubt kate would change their command line flags just because an extremely
> obscure distro-specific tool treats it the same as other text editors.

« Special cases aren't special enough to break the rules. »
Especially when all the other text editors use the same convention.

Well, thank you for the report.  If many “kate” users request, then
maybe « Although practicality beats purity. »

– from The Zen of Python, by Tim Peters – :-)

> But, whatever. The wrapper works well enough. Thanks.

So closing!

Thanks,
simon




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

* bug#44272: guix edit doesn't work when $EDITOR is set to VSCode
  2020-10-28 14:52   ` zimoun
  2020-10-28 22:28     ` Nathan Dehnel
@ 2023-11-02  9:32     ` Simon Tournier
  2023-11-06 17:41       ` Simon Tournier
  1 sibling, 1 reply; 7+ messages in thread
From: Simon Tournier @ 2023-11-02  9:32 UTC (permalink / raw)
  To: Leo Prikler; +Cc: ncdehnel, 44272

Hi,

PS: I write it here for later discovery.  The bug remains closed. :-)  I
will open another thread for discussing it.

On Wed, 28 Oct 2020 at 15:52, zimoun <zimon.toutoune@gmail.com> wrote:

> Instead ’kate’ use ’--line/-l’ and not ’+N’.  You could wrap, something
> along these lines:
>
> #!/bin/sh
>
> kate -l $(echo "$*" | tr "+" " ")
>
> then:
>
>   export EDITOR=/path/to/kate-wrapper.sh
>   guix edit emacs

VSCode does not respect the usual convention, too!  For instance,

    $ code +9 path/to/file

open files named “+9” and “path/to/file”.  Instead, VSCode expects:

    $ code --goto path/to/file:9

Therefore, it makes annoying to use VSCode with “guix edit”.  Here a
tiny wrapper to still be able to compose the both.  Well,

    $ EDITOR=vscode-wrapper guix edit hello

opens at the correct location.

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

(define %vscode--goto "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---




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

* bug#44272: guix edit doesn't work when $EDITOR is set to VSCode
  2023-11-02  9:32     ` bug#44272: guix edit doesn't work when $EDITOR is set to VSCode Simon Tournier
@ 2023-11-06 17:41       ` Simon Tournier
  0 siblings, 0 replies; 7+ messages in thread
From: Simon Tournier @ 2023-11-06 17:41 UTC (permalink / raw)
  To: Leo Prikler; +Cc: ncdehnel, 44272

Hi,

On Thu, 02 Nov 2023 at 10:32, Simon Tournier <zimon.toutoune@gmail.com> wrote:

> (define %vscode--goto "code --goto ")

In case, here an improvement when using Remote-SSH.

--8<---------------cut here---------------start------------->8---
(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
                           (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)))))))))
                     (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"))))
    (string-append code " --goto ")))
--8<---------------cut here---------------end--------------->8---


Cheers,
simon




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

end of thread, other threads:[~2023-11-06 17:42 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-28  6:13 bug#44272: guix edit doesn't work when $EDITOR is set to "kate" Nathan Dehnel
2020-10-28 13:05 ` Leo Prikler
2020-10-28 14:52   ` zimoun
2020-10-28 22:28     ` Nathan Dehnel
2020-10-28 22:55       ` zimoun
2023-11-02  9:32     ` bug#44272: guix edit doesn't work when $EDITOR is set to VSCode Simon Tournier
2023-11-06 17:41       ` Simon Tournier

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