Home Download Buy Blog Forum Support

Request: Start ext. application with special parameters

Request: Start ext. application with special parameters

Postby highend on Tue Sep 04, 2012 1:37 pm

Hi,

can anyone write a simple plugin that does the following:

Start an external application with two parameters depending on the current file type?

I've written a small .au3 (AutoIt) script, that uses an .ini file which contains different sections for each known help file entries for the resolution to what the .chm file will be resized, position, the general path for a topic inside the file (like: /idh_scripting_comref.htm\#idh_sc_<topic name>), etc.

It takes (currently) 2 parameters:
1.) Topic that should be displayed
2.) File extension
The rest is already inside the .ini file

So the plugin should execute a line like this:
"<path to my wrapper.exe file>" "<current keyword>" "<current file type>"

Everything else is handled inside the wrapper.

<current keyword>
It should take the word that is currently under the cursor or if no [a-zA-Z] is found at the current position it should find & take the first letter left from it and use that word instead.

An example ("|" = current cursor position):
Code: Select all
$file = getpathcomponent|

The cursor is not on a keyword (getpathcomponent) so search for the first letter on the left side of the cursor position ("t") and get the word under it (getpathcomponent again). Why this? I normally type the command and want to see the help file right after typing it.

<current file type>
Just use the extension of the current document without the leading dot.

It would be nice if I can define the keyboard shortcut for the plugin (to execute it) afterwards.

This would allow me / us to hit the same key for displaying a .chm help file with the correct topic, regardless if I'm currently working on a .au3, .ps1, .xys, etc. file.

If anyone is interested, I would post the .au3 file for the wrapper afterwards. If anybody else could make use of such a plugin.

Regards,
Highend
highend
 
Posts: 94
Joined: Fri Jan 20, 2012 2:47 pm

Re: Request: Start ext. application with special parameters

Postby quarnster on Wed Sep 26, 2012 10:13 am

Something like this perhaps?

Menu item Tools->New Plugin, and paste this code:
Code: Select all
import sublime, sublime_plugin
import os

class HighendCommand(sublime_plugin.TextCommand):
    def run(self, edit, command):
        word = self.view.substr(self.view.word(self.view.sel()[0].a))
        cmd = "\"%s\" \"%s\" \"%s\"" % (command, word, self.view.file_name()[self.view.file_name().rfind(".")+1:])
        print "Running command %s" % cmd
        os.system(cmd)


Then in your user keybindings:

Code: Select all
    { "keys": ["/"], "command": "highend", "args": {"command": "/path/to/wrapper.exe"}},
quarnster
 
Posts: 389
Joined: Tue Nov 29, 2011 11:34 am

Re: Request: Start ext. application with special parameters

Postby highend on Wed Sep 26, 2012 11:39 am

Thank you quarnster!

I've added this line to my user keymap:
{ "keys": ["alt+p"], "command": "highend", "args": {"command": "D:/NavigateCHM.exe"} },

The NavigateCHM.exe is the compiled AutoIt script file. The Navigate.chm contains a MsgBox line at the beginning to show me when it's executed.

The interesting thing is: The .exe is only executed (after pressing alt+p) under "weird circumstances":

This is the line I use (it's in a file named Test.xys)
foreach($task, $processTasks, "<crlf>") { sub "_" . $task; }

Three different cursor positions on this line lead to different results when using alt+p:
"|" is the current position

1.
foreach($|task, $processTasks, "<crlf>") { sub "_" . $task; }
Console: Running command "D:/NavigateCHM.exe" "task" "xys"
I don't get the message box from NavigateCHM.exe

2.
foreach|($task, $processTasks, "<crlf>") { sub "_" . $task; }
Console: Running command "D:/NavigateCHM.exe" "foreach" "xys"
I don't get the message box from NavigateCHM.exe

3.
foreach(|$task, $processTasks, "<crlf>") { sub "_" . $task; }
Console: Running command "D:/NavigateCHM.exe" "($" "xys"
NavigateCHM.exe is invoked...

This really doesn't make sense, does it?

P.s.: My last pm hasn't passed the outbox for over 1,5 hours, so I'll continue the discussion in this thread.

Regards,
Highend
highend
 
Posts: 94
Joined: Fri Jan 20, 2012 2:47 pm

Re: Request: Start ext. application with special parameters

Postby quarnster on Wed Sep 26, 2012 11:58 am

I don't know what's wrong, but try this code instead which will print out the program's stdout and stderr which should make it easier to debug if it doesn't work:

Code: Select all
import sublime, sublime_plugin
import subprocess

class HighendCommand(sublime_plugin.TextCommand):
    def run(self, edit, command):
        word = self.view.substr(self.view.word(self.view.sel()[0].a))
        args = (command, word, self.view.file_name()[self.view.file_name().rfind(".")+1:])
        cmd = "\"%s\" \"%s\" \"%s\"" % args
        print "Running command %s" % cmd
        p = subprocess.Popen(args, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
        stdout,stderr = p.communicate()
        print stdout
        print stderr
quarnster
 
Posts: 389
Joined: Tue Nov 29, 2011 11:34 am

Re: Request: Start ext. application with special parameters

Postby highend on Wed Sep 26, 2012 2:00 pm

print stdout / stderr only create blank lines so it seems there aren't any errors.

With the new code, NavigateCHM.exe is always started correctly and displays the correct keyword from the associated .chm file.

Thanks a lot for coding this for me, an invaluable help for looking up keywords :D

Regards,
Highend
highend
 
Posts: 94
Joined: Fri Jan 20, 2012 2:47 pm


Return to Plugin Development

Who is online

Users browsing this forum: Yahoo [Bot] and 7 guests