CudaText
CudaText copied to clipboard
Plugin to work as R interpreter
Hi Alexey,
Good Morning, I hope all is well with you.
I've been following your work on the CudaText (multi-platform) source code for some time. In addition to following along, I have been using CudaText as a support editor for my programming activities. I really like what is being done!
Recently you gave me support to be able to compile the project, I have been looking at the source code.
The reason for my contact is that I am a university professor at a public state university [1] in Brazil and I have been developing simple and efficient GUIs for the R interpreter [2].
I participate in the development work of the NVim-R plugin [3] for Vim/NeoVim (multi-platform), I am the leader and main programmer of the Tinn-R [4] project (Windows only).
I'm thinking of making a plugin for CudaText so that it can be used as a GUI along with the R interpreter.
If possible, I need a little initial work from you or from the more advanced developers and users of the CudaText project so that I can understand how it's done and I can learn and evolve the work in the construction of the GUI. Is there interest in this project?
Always the best, J. C. Faria
[1] http://www.uesc.br/ [2] https://www.r-project.org/ [3] https://www.vim.org/scripts/script.php?script_id=2628 [4] https://tinn-r.org/en/
Well written article
It depends on how complex the initial code you need. if you need only simple plugin, I will help. what is needed from initial code?
Hi,
I'm happy with the welcome!
Initially I need the plugin prototype to do the following: a) Create a menu named R with two submenus: Send and Control. From there I can increase the options;
b) Create a rudimentary taskbar with two groups and two buttons in each group, located below the main taskbar, with associated simple code, for example: ShowMessage(Obj.Name);
c) Create in the "Side Panel" an icon and a hierarchical structure for objects, similar to a TListView. It will be used as an object browser for R. If the user drags an object to the editor, its source code will be shown as text. The functionality I will do. I just need the initial structure.
d) Create an instance of ATSynEdit in the "Botton Panel" so that the user can resize it vertically. It will be used to receive messages from the R interpreter and also to send instructions to the R interpreter interactively.
I believe the rest is up to me. Obviously, I hope to always count on the support of all developers.
Best, J. C. Faria
About 'taskbar'. Cud has 'stattusbar' (in the bottom of main window). do you need statusbar so? can you make FAKE screenshot to show this taskbar in the Cud, with its buttons?
About 'listview with objects'. do you need heirarchy of items, or plane 1-level list of items? hierarchy means you need 'treeview', not 'listview'.
Treeview - like in Project Manager. Listview - like in Addons Manager / Update dialog.
I'll make a picture and post it here. I think it will be easier for you to understand...
In the figure below it is possible to have an overview of the basic objects that are needed in the graphical interface of Cuda:
In the figure below it is possible to have an overview of the object browser:
In the figure below it is possible to have an overview of the R console:
The figures are from the Tinn-R project.
Is it clearer now what are the initial needs?
yes, it is clearer now. Good.
console: I suggest the console like in TerminalPlus plugin: a) top editor with log of commands, b) bottom single line input. okay?
@Alexey-T, I think TerminalPlus is not yet full-featured terminal in a sense that you cannot interact with an application through stdin
, only simple applications that output text can be launched with no problems. (at least on Windows).
You are right @veksha , patches welcome
TerminalPlus running with R without any changes on my part. As @veksha said above, TerminalPlus lacks the STDin channel.
Encoding problems are observed and I think it is a very restrictive solution. I think it's better to create an instance of AtSynEdit there at that location. Communication with R will be done through a pipe (IPC) that is already running in Object Pascal. It was adapted from the Tinn-R project. From the ATSynEdit instance I can write, copy and paste. It becomes more interactive.
There is also the option of working (on Windows) with R.dll. I have to study how this will be done. Tin-R works with Rterm.exe and Rgui.exe, which on Windows are wrappers (made for R core Team in C/C++) for R.dll.
R Under development (unstable) (2022-05-27 r82411 ucrt) -- "Unsuffered Consequences" Copyright (C) 2022 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 (64-bit)
All messages (In|Out) are in UTF-8.
If you want to test in the console, after installing R, type:
R --ess
Here is first iteration - i called it R Helper (you can rename - both folder and string in install.inf) https://github.com/CudaText-addons/cuda_r_helper
use Plugins/ AddonsManager/ Install from Git.
it shows console only. it saves last history of entered items to config. it has few options in config: font size, max history size.
My suggestion for the name is cuda_r_plugin. See if you like. Liking can now change.
Next iteration, side-panel 'R objects' added. I used control 'listbox_ex' - do you agree? not 'listview'. listbox_ex can also be painted with icons (see plugin Insert Emoji - it paints emoji icons).
https://github.com/CudaText-addons/cuda_r_plugin
Why not listview— it cannot be themed! In the dark Ui theme listview will be white
OK, no problem! Good work!
About toolbar. U have 2 choices , choose one
- global toolbar on the window top. Visible when any Cud file is opened
- toolbar inside R Objects side panel. Hides with the side panel . Not irritating when we edit other files
In fact you will need both:
- a larger global with options for sending instructions from the editor and controlling the interpreter
- one, smaller, associated with the Object Browser.
Sorry for the delay, I had a really bad headache and had to rest my eyes a little.
I have a (basic) question: is the plugins construction language only Python? Can't use Object Pascal?
Can you point me to the plugin build documentation?
Only Python. Pascal change needs to be added to Cud first and be exposed in API
now all done! please test.
https://github.com/CudaText-addons/cuda_r_plugin
- main toolbar is shown above Cud's toolbar. is it OK? i also can align it to left/right/bottom.
- sidepanel toolbar
Alexei, I really appreciate all your attention. I'll study the code you have this weekend. As soon as I have a clear vision, I'll report back here on the forum.