Ivan Krylov
2021-Dec-17 21:07 UTC
[R-sig-Debian] Open a text file with vi/vim in another Terminal
On Fri, 17 Dec 2021 21:13:12 +0100 Patrice Kiener <patrice.kiener at inmodelia.com> wrote:> The instruction for the text editor > > system2(getOption("editor"), fileREP, wait = FALSE) > > works fine on Windows (it opens Notepad.exe, or Notepad++.exe in my > Rprofile.site) but not on Unix."A file.edit() but with the editor running in parallel with the R session" is a hard problem. Suppose that the user is running an R session on a server without a graphical display over remote command line. The user is probably running a graphical session with different windows, but R is unaware of it; it's only got one text terminal. What should our hypothetical file.edit.in.background() do in this case? It's fair to stopifnot(interactive()), but this counts as an interactive session. In theory, R could bundle a terminal multiplexer like tmux, split the terminal window in half and emulate a smaller terminal for the editor to run in, but there's no such functionality (or plans to implement it). On Debian, there's the /usr/bin/x-terminal-emulator symlink (typically present, but not 100% guaranteed to exist) pointing to _a_ graphical terminal emulator (if you can assume a running graphical session), but different terminal emulators take subtly different options to run command lines inside them. For example, xterm runs the rest of the command line after -e, while xfce4-terminal takes only one argument to -e but the rest of the command line after -x. The result is that you can't reliably pass arguments to the command you intend to launch. This *could* be worked around by writing a temporary shell script in /tmp, but the resulting solution accumulates too many moving parts to inspire any confidence and doesn't work on other distros or macOS. Besides, the user could plausibly prefer a text editor with a GUI when running a graphical session. Can you ask your users to specify an editor to run in the background? They could say it's 'emacs', c('xterm', '-e', 'joe'), c('xfce4-terminal', '-x', 'ed') or anything else. What do you intend to do with the file being edited by the user? Perhaps there's some other way to achieve the goal. (Not sure whether it's a better question for R-help or R-pkg-devel.) -- Best regards, Ivan
Dirk Eddelbuettel
2021-Dec-18 13:29 UTC
[R-sig-Debian] Open a text file with vi/vim in another Terminal
On 18 December 2021 at 00:07, Ivan Krylov wrote: | (Not sure whether it's a better question for R-help or R-pkg-devel.) Agreed. There is nothing Debian-specific here, these are UI-musings which, as discussed, are actually _hard_ if not impossible to solve in general. (20 years I played with R's tcltk package as it was (and still is) the only crossplatform tool allowing you to spawn a UI component on all OSs. And even then it isn't installed everywhere [as it is optional on Windows with the base R install] and will not work in pure "tty" text sessions.) Dirk -- https://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org