From: Simon Tournier <zimon.toutoune@gmail.com>
To: "Liliana Marie Prikler" <liliana.prikler@gmail.com>,
"Ludovic Courtès" <ludo@gnu.org>
Cc: Guix Devel <guix-devel@gnu.org>
Subject: Re: $EDITOR and “guix edit”
Date: Mon, 20 Nov 2023 10:40:39 +0100 [thread overview]
Message-ID: <86h6lg3gq0.fsf@gmail.com> (raw)
In-Reply-To: <246521d6a06ee6954372278b8507c346fcc068cb.camel@gmail.com>
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
next prev parent reply other threads:[~2023-11-20 10:23 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2023-11-20 19:33 ` Liliana Marie Prikler
2024-01-12 9:35 ` Simon Tournier
2024-01-12 17:39 ` Liliana Marie Prikler
2024-01-12 18:49 ` Simon Tournier
2024-01-12 19:46 ` Liliana Marie Prikler
2024-01-12 21:27 ` Simon Tournier
2023-11-22 18:21 ` Ludovic Courtès
2023-11-22 19:24 ` Liliana Marie Prikler
2023-12-09 9:24 ` Ludovic Courtès
2023-12-09 9:55 ` Liliana Marie Prikler
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86h6lg3gq0.fsf@gmail.com \
--to=zimon.toutoune@gmail.com \
--cc=guix-devel@gnu.org \
--cc=liliana.prikler@gmail.com \
--cc=ludo@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).