guix edit doesn't work when $EDITOR is set to "kate"

  • Done
  • quality assurance status badge
Details
3 participants
  • Leo Prikler
  • Nathan Dehnel
  • zimoun
Owner
unassigned
Submitted by
Nathan Dehnel
Severity
normal
N
N
Nathan Dehnel wrote on 28 Oct 2020 07:13
(name . Tobias Geerinckx-Rice via Bug reports for GNU Guix)(address . bug-guix@gnu.org)
CAEEhgEtmna9w9q4rKGNnVCb=qP5m-A2gBnHrWh5Lz4eiuP3PZQ@mail.gmail.com
kate opens an empty file.
Attachment: file
L
L
Leo Prikler wrote on 28 Oct 2020 14:05
(address . ncdehnel@gmail.com)(address . 44272@debbugs.gnu.org)
1a275264117e14a20f28757d8f6511acfd9ea5c9.camel@student.tugraz.at
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.
Z
Z
zimoun wrote on 28 Oct 2020 15:52
(address . 44272@debbugs.gnu.org)
868sbq2yjh.fsf@gmail.com
Dear Nathan,

Toggle quote (2 lines)
> Easy solution, set $EDITOR to "gedit" ;)

Or Emacs. ;-)


Toggle quote (7 lines)
> 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:

Toggle snippet (5 lines)
#!/bin/sh

kate -l $(echo "$*" | tr "+" " ")

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
N
N
Nathan Dehnel wrote on 28 Oct 2020 23:28
(name . zimoun)(address . zimon.toutoune@gmail.com)
CAEEhgEtuNy85rVxyG6VDBFjAikXoqyS5NkOaUMHEqsPV6Zc0Jg@mail.gmail.com
Toggle quote (1 lines)
>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:

Toggle quote (38 lines)
> 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: file
Z
Z
zimoun wrote on 28 Oct 2020 23:55
(name . Nathan Dehnel)(address . ncdehnel@gmail.com)
86361yyn8c.fsf@gmail.com
Dear,

On Wed, 28 Oct 2020 at 17:28, Nathan Dehnel <ncdehnel@gmail.com> wrote:
Toggle quote (7 lines)
>>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 – :-)

Toggle quote (2 lines)
> But, whatever. The wrapper works well enough. Thanks.

So closing!

Thanks,
simon
Closed
S
S
Simon Tournier wrote on 2 Nov 2023 10:23
control message for bug #44272
(address . control@debbugs.gnu.org)
868r7gpkzv.fsf@gmail.com
unarchive 44272
quit
S
S
Simon Tournier wrote on 2 Nov 2023 10:32
Re: bug#44272: guix edit doesn't work when $EDITOR is set to VSCode
(name . Leo Prikler)(address . leo.prikler@student.tugraz.at)
865y2kpkk4.fsf_-_@gmail.com
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:

Toggle quote (12 lines)
> 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

Toggle snippet (60 lines)
#!/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!")))
S
S
Simon Tournier wrote on 6 Nov 2023 18:41
(name . Leo Prikler)(address . leo.prikler@student.tugraz.at)
87a5rqg4ov.fsf@gmail.com
Hi,

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

Toggle quote (2 lines)
> (define %vscode--goto "code --goto ")

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

Toggle snippet (38 lines)
(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 ")))


Cheers,
simon
?