Sublime Forum

Need API guidance for a first "CSV Jump2Def" plugin

#1

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:

CommandName,Property1,Property2,... AwesomeCommand1,other,stuff,... AwesomeCommand2,other,stuff,...

  1. Reference the Commands in MenuData.csv
    (siblings are pipe-separated). Header and first line of MenuData.csv would look like:

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 +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 +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, ) only searches the current buffer, right? Is there a way to do something like find(buffer, pattern, fromPosition, )? Or I could first openFile(CommandData.xls, , ), 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, )

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 :smile:

0 Likes

#2

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.

0 Likes

#3

[quote=“sapphirehamster”]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.[/quote]

Good points, will try! Thanks for the help :smile:

0 Likes