Home Download Buy Blog Forum Support

Need API guidance for a first "CSV Jump2Def" plugin

Need API guidance for a first "CSV Jump2Def" plugin

Postby ronjouch on Wed Mar 06, 2013 9:41 pm

Hi.

I'm working on enterpriseware for which we define and package some customizations through CSV files, later on deployed by the customer. For example, to create a Menu containing two Commands, I would:
  1. Create two lines in CommandData.csv, containing (among other stuff) their names. Header and first lines of CommandData.csv would look like:
    Code: Select all
    CommandName,Property1,Property2,...
    AwesomeCommand1,other,stuff,...
    AwesomeCommand2,other,stuff,...
  2. Reference the Commands in MenuData.csv (siblings are pipe-separated). Header and first line of MenuData.csv would look like:
    Code: Select all
    MenuName,ChildrenCommands,Property1,...
    AwesomeMenu,AwesomeCommand1|AwesomeCommand2,other,stuff,...
I already created a tmlanguage to highlight stuff, and the API looks yummy so now I'd like to do My Very First Plugin® to scratch some additional itches. For a first version, requirements are short: when <Modifier>+clicking (e.g. ctrl-shift-clicking) a command in MenuData.csv I want to jump to its definition in CommandData.csv. Just like Find Results jumps to the containing file@line/column when clicking a line.

After a look at the API Reference, I'd go this way:
  1. Bindings should be easy with the definition of a button/press_command/press_args. If I stumble on problems with overriding the crowded <Modifier>+click space, I'll fallback to a keyboard shortcut, and will find the word at the current point with word(point). If the notion of "word" leads to problems with the pipe (|) character, I will just require the user to select the command before hitting the shortcut. So now I have my CommandName.
  2. I want now to find the ^CommandName regex in CommandData.csv. Problem: if I understand correctly, find(pattern, fromPosition, <flags>) only searches the current buffer, right? Is there a way to do something like find(buffer, pattern, fromPosition, <flags>)? Or I could first openFile(CommandData.xls, <row>, <col>), but that would be ugly: I don't want to switch to CommandData.xls without even knowing the search results will be not null! How can I work around that?
  3. If there is no match, fire a statusMessage(string) / errorMessage(string)
    If there is a matching Region, show(region, <showSurrounds>)
Questions:
  • What do you think?
  • In particular, any idea to solve point 2?
  • Other recommendations?
  • Does my needs look like something an existing plugins already does and where I could grab some clues?
Thanks for your help!

PS for those wondering (but given the audience here I'm sure I'll be understood): yes I'm editing CSV in a text editor with no "Column" notion, because Excel/LibreOffice messes with my data (commas, leading zeroes, etc.), CSVEd is unstable, and CSVEasy is neat but not very powerful. And SublimeText has lots to offer :)
ronjouch
 
Posts: 4
Joined: Sat Oct 13, 2012 12:25 am
Location: Montréal, Canada

Re: Need API guidance for a first "CSV Jump2Def" plugin

Postby sapphirehamster on Thu Mar 07, 2013 6:11 am

Some ideas for you:

Regarding point #2: find(...) is a method of the view object (what you are calling a buffer). If you want to do a search through another open view, you can access it from the window object. Perhaps something like iterating through self.view.window().views() and finding the view with the file_name() you want (CommandData.csv).

If you want to support the ability to examine the file without opening it, just use regular Python open() to open the file and search through it using python's re module or whatever is convenient. You can then call window.open_file() if you have a successful match, otherwise display your error.
sapphirehamster
 
Posts: 88
Joined: Sun Jul 01, 2012 11:19 pm

Re: Need API guidance for a first "CSV Jump2Def" plugin

Postby ronjouch on Thu Mar 07, 2013 2:39 pm

sapphirehamster wrote:Regarding point #2: find(...) is a method of the view object (what you are calling a buffer). If you want to do a search through another open view, you can access it from the window object. Perhaps something like iterating through self.view.window().views() and finding the view with the file_name() you want (CommandData.csv).

If you want to support the ability to examine the file without opening it, just use regular Python open() to open the file and search through it using python's re module or whatever is convenient. You can then call window.open_file() if you have a successful match, otherwise display your error.

Good points, will try! Thanks for the help :)
ronjouch
 
Posts: 4
Joined: Sat Oct 13, 2012 12:25 am
Location: Montréal, Canada


Return to Plugin Development

Who is online

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