Home Download Buy Blog Forum Support

Getting current filename and line number on keypress?

Getting current filename and line number on keypress?

Postby Naatan on Fri Feb 24, 2012 4:53 pm

Hi, I'm just trying to create a very basic plugin that executes on a keypress and requires the current selected filename and line number, I checked the API and saw that I can get this from sublime.View, but I can't figure out how to access this class from a keypress (note - I have very little experience with Python, but am otherwise an experienced programmer).

Basically I created a python file, imported sublime_plugin and sublime and created a class which matched the command executed on a keypress. Now how do I access sublime.View ?

Thanks
Naatan
 
Posts: 20
Joined: Tue Feb 01, 2011 4:27 pm

Re: Getting current filename and line number on keypress?

Postby Naatan on Fri Feb 24, 2012 5:02 pm

Nevermind, figured it out:

Code: Select all
      view = sublime.Window.active_view(sublime.active_window())
      print view.file_name()
      (row,col) = view.rowcol(view.sel()[0].begin())
      print row + 1


Possibly not the best way, but it works.
Naatan
 
Posts: 20
Joined: Tue Feb 01, 2011 4:27 pm

Re: Getting current filename and line number on keypress?

Postby JMM on Fri Feb 24, 2012 5:10 pm

If your class extends sublime_plugin.TextCommand, then you can also access the active view as `self.view` (assuming the first argument to your `run` method is called `self`).
JMM
 
Posts: 9
Joined: Fri Feb 03, 2012 1:23 pm
Location: Portsmouth NH


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 7 guests