Anonymous avatar Anonymous committed abd7e6c

Added support for Python tracebacks.

Comments (0)

Files changed (3)

     - Checkbox summaries
     - External links
     - Inter document links. E.g. {1} {{Context sensitive actions}}
+    - Code blocks
+    - Python tracebacks
 
   * Context sensitive actions
     - Toggle checkbox on pressing enter
     - Jump between inter document links on pressing enter (e.g. {1})
     - Jump to linked headline on pressing enter (e.g. {{Installation}})
     - Show an outline of the document on using goto symbol
+    - Open Python file at specific line from Python tracebacks when pressing enter on a filepath
 
 * Installation
 
                 return resolver, result
         return None, None
 
+    def is_valid_scope(self, sel):
+        scope_name = self.view.scope_name(sel.end())
+        return 'orgmode.link' in scope_name
+
+    def extract_content(self, region):
+        content = self.view.substr(region)
+        if content.startswith('[[') and content.endswith(']]'):
+            content = content[2:-2]
+        return content
+
     def run(self, edit):
         view = self.view
         for sel in view.sel():
-            if 'orgmode.link' not in view.scope_name(sel.end()):
+            if not self.is_valid_scope(sel):
                 continue
             region = view.extract_scope(sel.end())
-            content = view.substr(region)
-            if content.startswith('[[') and content.endswith(']]'):
-                content = content[2:-2]
+            content = self.extract_content(region)
             resolver, content = self.resolve(content)
             if content is None:
                 sublime.error_message('Could not resolve link:\n%s' % content)
             resolver.execute(content)
 
 
+class OrgmodeOpenPythonRefCommand(OrgmodeOpenLinkCommand):
+
+    def __init__(self, *args, **kwargs):
+        super(OrgmodeOpenPythonRefCommand, self).__init__(*args, **kwargs)
+        pattern = r'.+", line (?P<line>\d+), in (?P<symbol>.+)$'
+        self.regex = re.compile(pattern)
+
+    def is_valid_scope(self, sel):
+        scope_name = self.view.scope_name(sel.end())
+        return 'filepath reference orgmode.python.traceback' in scope_name
+
+    def extract_content(self, region):
+        content = self.view.substr(region)
+        outer_region = self.view.extract_scope(region.end() + 1)
+        scope_name = self.view.scope_name(region.end() + 1)
+        # print scope_name
+        if 'reference orgmode.python.traceback' in scope_name:
+            outer_content = self.view.substr(outer_region)
+            # print outer_content
+            match = self.regex.match(outer_content)
+            if match:
+                # print match.groupdict()
+                content += ':%s' % match.group('line')
+        return content
+
+
 class OrgmodeCycleInternalLinkCommand(sublime_plugin.TextCommand):
 
     def run(self, edit):

orgmode.tmLanguage

 			<string>\[code\]\s*</string>
 			<key>end</key>
 			<string>\s*\[/code\]</string>
+			<key>patterns</key>
+			<array>
+ 				<dict>
+					<key>include</key>
+					<string>#python_exception.reference</string>
+				</dict>
+			</array>
 		</dict>
 		<dict>
 			<key>name</key>
 			<key>match</key>
 			<string>(^|\s):[\w\d:]+:(\s|$)</string>
 		</dict>
+		<dict>
+			<key>name</key>
+			<string>orgmode.python.traceback</string>
+			<key>begin</key>
+			<string>^\s*Traceback \(most recent call last\):\s*$</string>
+			<key>end</key>
+			<string>^\s*\w+: .+$</string>
+			<key>patterns</key>
+			<array>
+ 				<dict>
+					<key>include</key>
+					<string>#python_exception.reference</string>
+				</dict>
+			</array>
+		</dict>
 	</array>
+	<key>repository</key>
+	<dict>
+		<key>python_exception.reference</key>
+		<dict>
+			<key>name</key>
+			<string>reference orgmode.python.traceback</string>
+			<key>match</key>
+			"^[ ]*File \"(...*?)\", line ([0-9]*)",
+			<string>File "(.+)", line (\d+), in (.*)$</string>
+			<key>captures</key>
+			<dict>
+				<key>1</key>
+				<dict>
+					<key>name</key>
+					<string>filepath</string>
+				</dict>
+				<key>2</key>
+				<dict>
+					<key>name</key>
+					<string>line</string>
+				</dict>
+				<key>3</key>
+				<dict>
+					<key>name</key>
+					<string>function</string>
+				</dict>
+			</dict>
+		</dict>
+	</dict>
 	<key>scopeName</key>
 	<string>text.orgmode</string>
 	<key>uuid</key>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.