Discussion:
[code] [textadept] run external app from editor
Thorsten Kampe
2015-12-27 16:16:46 UTC
Permalink
Hi,

I would like to be able to run two external commands from within the
editor:

1. `runscript` with the argument of the filename in the current
buffer. This should be possible for all file types - as runscript is
a wrapping extension to interpreter. Output of `runscript` should go
into a buffer of Textadept.

2. `showdocs` with the arguments "devdocs", "full_name_of_file" and
"selected text in editor". This will open a browser and so the output
should not be captured.

How can I achieve this? I had a look at the "Compile and Run Code"
section of Quick Reference but I didn't understand it.

Thorsten
--
You are subscribed to ***@foicica.com.
To change subscription settings, send an e-mail to code+***@foicica.com.
To unsubscribe, send an e-mail to code+***@foicica.com.
Mitchell
2015-12-27 19:58:25 UTC
Permalink
Hi Thorsten,
Post by Thorsten Kampe
Hi,
I would like to be able to run two external commands from within the
1. `runscript` with the argument of the filename in the current
buffer. This should be possible for all file types - as runscript is
a wrapping extension to interpreter. Output of `runscript` should go
into a buffer of Textadept.
You can put something like this in your ~/.textadept/init.lua:

keys.caa = function()
if not buffer.filename then return end
local dir, file = buffer.filename:match('^(.+)[/\\]([^/\\]+)$')
spawn('runscript "'..file..'"', dir, ui.print, ui.print)
end

(The function is bound to the Ctrl+Alt+A key, but you can make it whatever
you want.) All output will go into Textadept's message buffer.
Post by Thorsten Kampe
2. `showdocs` with the arguments "devdocs", "full_name_of_file" and
"selected text in editor". This will open a browser and so the output
should not be captured.
Something like this should work:

keys.caA = function()
if not buffer.filename then return end
local sel_text = buffer:get_sel_text()
if sel_text == '' then return end
spawn('showdocs devdocs "'..buffer.filename..'" "'..sel_text..'"')
end

That is bound to Ctrl+Alt+Shift+A, and can be changed, naturally.
Post by Thorsten Kampe
How can I achieve this? I had a look at the "Compile and Run Code"
section of Quick Reference but I didn't understand it.
Textadept's Compile and Run Code feature is useful for source files in
particular programming languages. Since your functionality is
language-agnostic, you would create a generic tool (function) to perform
it.

Cheers,
Mitchell
--
You are subscribed to ***@foicica.com.
To change subscription settings, send an e-mail to code+***@foicica.com.
To unsubscribe, send an e-mail to code+***@foicica.com.
Thorsten Kampe
2015-12-28 11:52:16 UTC
Permalink
* Mitchell (Sun, 27 Dec 2015 14:58:25 -0500 (EST))
Post by Thorsten Kampe
I would like to be able to run two external commands from within
1. `runscript` with the argument of the filename in the current
buffer. This should be possible for all file types - as runscript is
a wrapping extension to interpreter. Output of `runscript` should go
into a buffer of Textadept.
[...]
Thanks, that works beautifully.

Just a few related questions:

- is it possible to reload init.lua from within the editor without
closing and reopening Textadept?

- is there a function to return the word under the cursor? (so I
don't have to select text I search for)

- is it possible to force Textadept to open only a single instance
and to open all files in new tabs/buffers? (When I drag and drop
multiple files to the editor, they all open in tabs...)

Cheers, Thorsten
--
You are subscribed to ***@foicica.com.
To change subscription settings, send an e-mail to code+***@foicica.com.
To unsubscribe, send an e-mail to code+***@foicica.com.
Mitchell
2015-12-28 16:22:04 UTC
Permalink
Hi Thorsten,
Post by Thorsten Kampe
* Mitchell (Sun, 27 Dec 2015 14:58:25 -0500 (EST))
Post by Thorsten Kampe
I would like to be able to run two external commands from within
1. `runscript` with the argument of the filename in the current
buffer. This should be possible for all file types - as runscript is
a wrapping extension to interpreter. Output of `runscript` should go
into a buffer of Textadept.
[...]
Thanks, that works beautifully.
- is it possible to reload init.lua from within the editor without
closing and reopening Textadept?
Sure. Open the command entry, type "reset()"[1] (no quotes), and press
Enter.
Post by Thorsten Kampe
- is there a function to return the word under the cursor? (so I
don't have to select text I search for)
You have two options:

(1) textadept.editing.select_word()
local word = buffer:get_sel_text()

(2) local s = buffer:word_start_position(buffer.current_pos, true)
local e = buffer:word_end_position(buffer.current_pos, true)
local word = buffer:text_range(s, e)

The first modifies the selection and uses that to get the word, and the
second gets the word silently.
Post by Thorsten Kampe
- is it possible to force Textadept to open only a single instance
and to open all files in new tabs/buffers? (When I drag and drop
multiple files to the editor, they all open in tabs...)
It depends on what platform you're on. The manual should help you with
this[2].

Cheers,
Mitchell

[1]: http://foicica.com/textadept/api.html#reset
[2]: http://foicica.com/textadept/manual.html#Single.Instance
--
You are subscribed to ***@foicica.com.
To change subscription settings, send an e-mail to code+***@foicica.com.
To unsubscribe, send an e-mail to code+***@foicica.com.
Robert Gieseke
2015-12-28 16:30:53 UTC
Permalink
Post by Mitchell
Post by Thorsten Kampe
- is it possible to reload init.lua from within the editor without
closing and reopening Textadept?
Sure. Open the command entry, type "reset()"[1] (no quotes), and press
Enter.
You can also assign a short cut to do this, I have 'F9' bound to save
the current file and call reset:

-- Save file and reset Lua state: `F9`
keys['f9'] = function()
io.save_file()
reset()
end
Post by Mitchell
Post by Thorsten Kampe
- is it possible to force Textadept to open only a single instance
and to open all files in new tabs/buffers? (When I drag and drop
multiple files to the editor, they all open in tabs...)
It depends on what platform you're on. The manual should help you with
this[2].
On Windows you might be able to have a script wrapping the launch of
Textadept, though I have never tried this.

Cheers,
Robert
Post by Mitchell
[2]: http://foicica.com/textadept/manual.html#Single.Instance
--
You are subscribed to ***@foicica.com.
To change subscription settings, send an e-mail to code+***@foicica.com.
To unsubscribe, send an e-mail to code+***@foicica.com.
Carl Sturtivant
2015-12-28 19:14:45 UTC
Permalink
Post by Mitchell
Post by Thorsten Kampe
- is it possible to force Textadept to open only a single instance
and to open all files in new tabs/buffers? (When I drag and drop
multiple files to the editor, they all open in tabs...)
It depends on what platform you're on. The manual should help you with
this[2].
On Windows apparently not. It might be interesting to fix this. What is
the thinking behind the present state of affairs?

Carl.
--
You are subscribed to ***@foicica.com.
To change subscription settings, send an e-mail to code+***@foicica.com.
To unsubscribe, send an e-mail to code+***@foicica.com.
Mitchell
2015-12-29 04:18:21 UTC
Permalink
Hi Carl,
Post by Carl Sturtivant
Post by Mitchell
Post by Thorsten Kampe
- is it possible to force Textadept to open only a single instance
and to open all files in new tabs/buffers? (When I drag and drop
multiple files to the editor, they all open in tabs...)
It depends on what platform you're on. The manual should help you with
this[2].
On Windows apparently not. It might be interesting to fix this. What is
the thinking behind the present state of affairs?
GTK (Textadept's GUI toolkit) takes care of detecting whether or not an
application is open and communicating with it via a technology called DBus
that apparently does not work on Windows (at least for GTK 2.24). I'd have
to write my own method for detecting and communicating with an open
process, which would be difficult for me to do on Windows. I'm open to
patch though.

Cheers,
Mitchell
--
You are subscribed to ***@foicica.com.
To change subscription settings, send an e-mail to code+***@foicica.com.
To unsubscribe, send an e-mail to code+***@foicica.com.
Carl Sturtivant
2015-12-30 01:51:52 UTC
Permalink
Post by Mitchell
GTK (Textadept's GUI toolkit) takes care of detecting whether or not an
application is open and communicating with it via a technology called
DBus that apparently does not work on Windows (at least for GTK 2.24).
I'd have to write my own method for detecting and communicating with an
open process, which would be difficult for me to do on Windows. I'm open
to patch though.
Understood. I'll look into this a little.

Carl.
--
You are subscribed to ***@foicica.com.
To change subscription settings, send an e-mail to code+***@foicica.com.
To unsubscribe, send an e-mail to code+***@foicica.com.
Continue reading on narkive:
Loading...