Home Download Buy Blog Forum Support

open file by a hot key

open file by a hot key

Postby yann.tersen on Thu Jun 28, 2012 9:48 am

How can I do this?

I put
Code: Select all
   { "keys": ["f1"], "command": "open_file", "args": {"filename": "index.php"} }


I struggle with sublime API and open_file but nothing works and I can't debug it. It always returns nothing.

For example, I thought it will work. I was wrong. =)
Code: Select all
import sublime, sublime_plugin
import os

class open_fileCommand(sublime_plugin.WindowCommand):
    def run(self):
        v = self.window.new_file()
        v.settings().set('default_dir',
            os.path.join(sublime.packages_path(), 'User'))
        v.set_syntax_file('Packages/JavaScript/JSON.tmLanguage')
        v.set_name('untitled.sublime-build')

        template = """{
   "cmd": ["${0:make}"]
}
"""
        v.run_command("insert_snippet", {"contents": template})


yann.tersen
 
Posts: 4
Joined: Sat Jun 23, 2012 12:15 pm

Re: open file by a hot key

Postby thekyz on Thu Jun 28, 2012 10:45 am

Should be something like this:

Code: Select all
  { "keys" : ["f1"], "command": "my_open_file", "args": {"file" : "index.php"}}


Code: Select all
import sublime, sublime_plugin
import os.path

class MyOpenFileCommand(sublime_plugin.WindowCommand):
    def run(self, file):
        dir_name = os.path.join(sublime.packages_path(), 'User')
        self.window.open_file(os.path.join(dir_name, file))
thekyz
 
Posts: 20
Joined: Fri Feb 04, 2011 9:27 am

Re: open file by a hot key

Postby yann.tersen on Thu Jun 28, 2012 11:26 am

Wow!
This is really cool. Thank you so much!
yann.tersen
 
Posts: 4
Joined: Sat Jun 23, 2012 12:15 pm


Return to Technical Support

Who is online

Users browsing this forum: Exabot [Bot], Google [Bot], Yahoo [Bot] and 22 guests