Using an external editor

New to Gambas? Post your questions here. No question is too silly or too simple.
Post Reply
User avatar
Median Joe
Posts: 15
Joined: Tuesday 8th November 2022 7:30pm
Location: Britain

Using an external editor

Post by Median Joe »

When writing GUI scripts it makes sense to use the IDE, but for command line programs is there a way to run them directly from the Linux console, having created the script in an external editor? Thanks in advance for any help!
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Using an external editor

Post by cogier »

Hi Median Joe and welcome to the forum.

You can use any text editor to create your code. You need to put #!/usr/bin/env gbs3 as the first line of the file and once you have saved it right-click and make the file 'Executable'.

There is a load of help here.
User avatar
Median Joe
Posts: 15
Joined: Tuesday 8th November 2022 7:30pm
Location: Britain

Re: Using an external editor

Post by Median Joe »

Hi cogier,

Many thanks! I've been using vim for some years and it makes conventional editing hard work by comparison. :)
I found a basic syntax file for Gambas here here.

Hugely impressed by Gambas, Benoit is obviously some kind of God. :shock: I write a lot of number crunching code and was concerned that being an interpreted language, Gambas might not be up to the job, but I needn't have have worried. Even without using JIT it's fast enough for my needs.

Thanks again.
User avatar
stevedee
Posts: 518
Joined: Monday 20th March 2017 6:06pm

Re: Using an external editor

Post by stevedee »

Median Joe wrote: Thursday 10th November 2022 11:34am ...I've been using vim for some years and it makes conventional editing hard work by comparison...
Why not try Geany: http://captainbodgit.blogspot.com/2019/ ... ambas.html
User avatar
BruceSteers
Posts: 1523
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Using an external editor

Post by BruceSteers »

I wrote a script editor in gambas that has a few handy features like...

Uses the gambas gb.form.editor so has the same highlighting as the Gambas IDE and will format some text as the IDE does. (turns then into Then and stuff)
supports bash and gambas scripts
Click a button to toggle executable flag.
External tools (like pluma external tools) create scripts like plugins to do functions to the document/selected text.
A Run button to test the scripts.
Experimental key macro recorder. record keystrokes and repeat them at the press of a button. (works better with gtk than qt)
Lists the functions in a list , clicking a function in the list moves the cursor to it.
If you drop a .desktop file on it that points to a script it asks if you want to edit the ,desktop file or the file it points to.
Written in gambas, and you know gambas so you can modify the source at will.

https://gitlab.com/bsteers4/scripted

It's a bit WIP but i don't have many problems with it and use it all the time, it's especially handy for writing scripts as that's what it was made for.

The only real bug I've not been able to fix yet is sometimes when closing a tab they all close? so i generally make sure i've saved edits before closing tabs.
Attachments
Screenshot at 2022-11-10 13-50-22.png
Screenshot at 2022-11-10 13-50-22.png (266.43 KiB) Viewed 3659 times
If at first you don't succeed , try doing something differently.
BruceS
User avatar
Median Joe
Posts: 15
Joined: Tuesday 8th November 2022 7:30pm
Location: Britain

Re: Using an external editor

Post by Median Joe »

stevedee wrote: Thursday 10th November 2022 12:24pm
Median Joe wrote: Thursday 10th November 2022 11:34am ...I've been using vim for some years and it makes conventional editing hard work by comparison...
Why not try Geany: http://captainbodgit.blogspot.com/2019/ ... ambas.html
Hi stevedee, Geany is a nice editor, in fact I used it before discovering vim. The thing which sets vim apart is the fact that you don't need to take your hands off the keyboard - ever! With a little practice you'll find it much easier than having to keep moving from mouse to keyboard and back again. It takes a little while to build up the muscle memory but when you have it you won't want to use any other editor (which admittedly can be a disadvantage). Type vimtutor in the console for a quick interactive tutorial - you may get hooked!
User avatar
Median Joe
Posts: 15
Joined: Tuesday 8th November 2022 7:30pm
Location: Britain

Re: Using an external editor

Post by Median Joe »

BruceSteers wrote: Thursday 10th November 2022 1:04pm I wrote a script editor in gambas that has a few handy features like...
Hi BruceSteers,

Very impressive! If you add vim bindings I would definitely use it. :lol: I continue to be amazed at Gambas and its capabilities. I tried FreePascal with Lazarus for a while but the Gambas IDE is easier to use and I prefer BASIC syntax to Pascal's.
User avatar
BruceSteers
Posts: 1523
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: Using an external editor

Post by BruceSteers »

Median Joe wrote: Thursday 10th November 2022 2:52pm
BruceSteers wrote: Thursday 10th November 2022 1:04pm I wrote a script editor in gambas that has a few handy features like...
Hi BruceSteers,

Very impressive! If you add vim bindings I would definitely use it. :lol: I continue to be amazed at Gambas and its capabilities. I tried FreePascal with Lazarus for a while but the Gambas IDE is easier to use and I prefer BASIC syntax to Pascal's.
ew, :lol: , i never got on with vim and use nano ;)
Like i say it's written in gambas and has the KeyPress event so you could probably add any vim bindings you like :)

And i agree about the other programming environments, i tried a few, all rather complicated, then i found gambas and was amazed at it's simplicity and nice syntax.

PS. to your original question.

There are 2 ways to launch a gambas script created from any editor.

Like Cogier said make the very first line, the "shebang" line, like this...
#!/usr/bin/env gbs3
then set the files executable flag
chmod +x /path/to/my/file.gbs
That file can now either be double clicked to launch or directly run from terminal. the shebang tells it to use gbs3 and it will run because it is executable (on most sytems).

Alternatively you can use gbs3 to run the file without a shebang or being executable.

gbs3 /path/to/my/file.gbs

You can also use various options with the gbs3 command.
gbs3 --help

Compile and execute a Gambas script.

Usage: gbs3 [options][--] [<script file> | <project directory> | - ]
gbs3 --convert-project <input project directory> [<output directory where script is created>]
gbs3 --convert-script <input script> [<output directory where project directory is created>]
gbs3 --plugin <input script> [<output plugin cache directory>]

Options:
-b --buildonly process and compile the script without executing it
-c --nocache force the script compilation (do not check cache)
-e execute the source code provided by the command line ( ':' separator )
-g --debug add debugging information to application
-f --fast use just-in-time compiler
-h --help display this help
-L --license display license
-p --plugin Compile the script, no main, define the class name as script base name entry point _Call(...)
-S --strict fail if 'Public' or 'Sub' are defined without a 'main' function
-t --trace turn on tracing option during execution
-T --terse-listing only print a very terse error report on compile errors
-u --use <components> force component loading ('comp1,comp2...')
-U --unsafe allows jit compiler to generate unsafe faster code
-v --verbose be verbose
-V --version display version
-w --warnings display warnings during compilation
--convert-project convert a simple project to a script
--convert-script convert a simple script to a project
-- stop any further option processing
- read the script from standard input
If at first you don't succeed , try doing something differently.
BruceS
Post Reply