From 6e0703d191c13be0db4232f7d5a964602d78d849 Mon Sep 17 00:00:00 2001 From: fk128 Date: Fri, 24 Jul 2015 12:43:51 +0100 Subject: [PATCH 1/2] add open-url feature --- Default (Linux).sublime-mousemap | 6 +++++ Default (OSX).sublime-mousemap | 6 +++++ Default (Windows).sublime-mousemap | 6 +++++ notes.py | 38 ++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+) create mode 100644 Default (Linux).sublime-mousemap create mode 100644 Default (OSX).sublime-mousemap create mode 100644 Default (Windows).sublime-mousemap diff --git a/Default (Linux).sublime-mousemap b/Default (Linux).sublime-mousemap new file mode 100644 index 0000000..d1b226a --- /dev/null +++ b/Default (Linux).sublime-mousemap @@ -0,0 +1,6 @@ +[ + { + "button": "button1", "count": 1, "modifiers": ["alt"], + "press_command": "note_open_url" + } +] \ No newline at end of file diff --git a/Default (OSX).sublime-mousemap b/Default (OSX).sublime-mousemap new file mode 100644 index 0000000..d1b226a --- /dev/null +++ b/Default (OSX).sublime-mousemap @@ -0,0 +1,6 @@ +[ + { + "button": "button1", "count": 1, "modifiers": ["alt"], + "press_command": "note_open_url" + } +] \ No newline at end of file diff --git a/Default (Windows).sublime-mousemap b/Default (Windows).sublime-mousemap new file mode 100644 index 0000000..d1b226a --- /dev/null +++ b/Default (Windows).sublime-mousemap @@ -0,0 +1,6 @@ +[ + { + "button": "button1", "count": 1, "modifiers": ["alt"], + "press_command": "note_open_url" + } +] \ No newline at end of file diff --git a/notes.py b/notes.py index bac6e1b..56b7d95 100644 --- a/notes.py +++ b/notes.py @@ -5,6 +5,7 @@ import copy from gzip import GzipFile from pickle import load, dump +import webbrowser ST3 = int(sublime.version()) >= 3000 @@ -362,6 +363,43 @@ def is_enabled(self): else: return False + +class NoteOpenUrlCommand(sublime_plugin.TextCommand): + + def run(self, edit): + s = self.view.sel()[0] + + # Expand selection to possible URL + start = s.a + end = s.b + + view_size = self.view.size() + terminator = ['\t', ' ', '\"', '\'', '(', ')'] + + while (start > 0 + and not self.view.substr(start - 1) in terminator + and self.view.classify(start) & sublime.CLASS_LINE_START == 0): + start -= 1 + + while (end < view_size + and not self.view.substr(end) in terminator + and self.view.classify(end) & sublime.CLASS_LINE_END == 0): + end += 1 + + # Check if this is URL + url = self.view.substr(sublime.Region(start, end)) + + if url.startswith(('http://', 'https://')): + webbrowser.open_new_tab(url) + + def is_enabled(self): + is_note = sublime.active_window().active_view().settings().get("is_note") + if is_note: + return is_note + else: + return False + + def save_to_brain(): # print("SAVING TO DISK-----------------") # print(db) From 7b053e2392d126d4bdb3450902ad12167c09ed08 Mon Sep 17 00:00:00 2001 From: fk128 Date: Sat, 25 Jul 2015 10:00:14 +0100 Subject: [PATCH 2/2] update README --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index fccf4df..6c9ee79 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,9 @@ To add more yaml items you can add them to the settings by modifying `note_yaml: { "note_yaml" : ["categories"] } ``` +#### Other features +- open urls: place cursor on the link then `alt + click` to open a url in the browser. + ## Per-project notes To have a different notes directory for a project, add the following in your `.sublime-project` file: