Skip to content

Instantly share code, notes, and snippets.

@yongkangchen
Forked from Suor/INSTALL.markdown
Last active August 29, 2015 13:58
Show Gist options
  • Save yongkangchen/10224897 to your computer and use it in GitHub Desktop.
Save yongkangchen/10224897 to your computer and use it in GitHub Desktop.

Revisions

  1. yongkangchen revised this gist Apr 9, 2014. 2 changed files with 2 additions and 6 deletions.
    4 changes: 0 additions & 4 deletions INSTALL.markdown
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,3 @@
    ```bash
    cd ~/.config/sublime-text-2/Packages/User/
    curl -O https://raw.github.com/gist/1344471/open_file_at_cursor.py
    ```
    Open keyboard bindings file, and add a line to it

    ```js
    4 changes: 2 additions & 2 deletions open_file_at_cursor.py
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,7 @@ def run(self, edit):
    m = filename_re.search(whole_line, col)
    if m:
    filename = m.group()
    print "Opening file '%s'" % (filename)
    sublime.status_message("Opening file '%s'" % (filename))
    self.view.window().open_file(filename)
    else:
    print "No filename discovered"
    sublime.status_message("No filename discovered")
  2. yongkangchen revised this gist Apr 9, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion open_file_at_cursor.py
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@
    VALID_FILENAME_CHARS = "-_.() %s%s%s" % (string.ascii_letters, string.digits, "/\\")
    filename_re = re.compile(r'[\w/\.-]+')

    class OpenFilenameUnderCursor(sublime_plugin.TextCommand):
    class OpenFileAtCursor(sublime_plugin.TextCommand):
    def run(self, edit):
    for region in self.view.sel():
    # Find anything looking like file in whole line at cursor
  3. @Suor Suor revised this gist Nov 7, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion INSTALL.markdown
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ Open keyboard bindings file, and add a line to it
    ```js
    [
    ...
    { "keys": ["alt+o"], "command": "open_filename_under_cursor" } // this one
    { "keys": ["alt+o"], "command": "open_file_at_cursor" } // this one
    ]
    ```

  4. @Suor Suor revised this gist Nov 7, 2011. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions INSTALL.markdown
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,13 @@
    ```bash
    cd ~/.config/sublime-text-2/Packages/User/
    curl -O https://gist.github.com/raw/1344471/0960b96154988c78245fca365228499e212a80cb/open_file_at_cursor.py
    curl -O https://raw.github.com/gist/1344471/open_file_at_cursor.py
    ```
    Open keyboard bindings file, and add a line to it

    ```js
    [
    ...
    { "keys": ["alt+o"], "command": "open_filename_under_cursor" }
    { "keys": ["alt+o"], "command": "open_filename_under_cursor" } // this one
    ]
    ```

  5. @Suor Suor revised this gist Nov 7, 2011. 1 changed file with 12 additions and 2 deletions.
    14 changes: 12 additions & 2 deletions INSTALL.markdown
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,13 @@
    ```
    ```bash
    cd ~/.config/sublime-text-2/Packages/User/
    curl -O
    curl -O https://gist.github.com/raw/1344471/0960b96154988c78245fca365228499e212a80cb/open_file_at_cursor.py
    ```
    Open keyboard bindings file, and add a line to it

    ```js
    [
    ...
    { "keys": ["alt+o"], "command": "open_filename_under_cursor" }
    ]
    ```

  6. @Suor Suor created this gist Nov 7, 2011.
    3 changes: 3 additions & 0 deletions INSTALL.markdown
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    ```
    cd ~/.config/sublime-text-2/Packages/User/
    curl -O
    23 changes: 23 additions & 0 deletions open_file_at_cursor.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    import sublime, sublime_plugin
    import os.path, string
    import re

    VALID_FILENAME_CHARS = "-_.() %s%s%s" % (string.ascii_letters, string.digits, "/\\")
    filename_re = re.compile(r'[\w/\.-]+')

    class OpenFilenameUnderCursor(sublime_plugin.TextCommand):
    def run(self, edit):
    for region in self.view.sel():
    # Find anything looking like file in whole line at cursor
    whole_line = self.view.substr(self.view.line(region))
    row, col = self.view.rowcol(region.begin())
    while col >= len(whole_line) or whole_line[col] in VALID_FILENAME_CHARS:
    col -= 1

    m = filename_re.search(whole_line, col)
    if m:
    filename = m.group()
    print "Opening file '%s'" % (filename)
    self.view.window().open_file(filename)
    else:
    print "No filename discovered"