Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[errors-] add sysopen-error command to view vd source code in editor #2618

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions visidata/textsheet.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import textwrap
import re

from visidata import vd, BaseSheet, options, Sheet, ColumnItem, asyncthread
from visidata import Column, vlen
Expand Down Expand Up @@ -62,6 +63,22 @@ class ErrorSheet(TextSheet):
guide = '''# Error Sheet'''
precious = False

def sysopen_error(self, col, row):
'''Open an external editor for the file relevant to the cursor line
in the Error Sheet. If the cursor is on the first line, use the file
mentioned at the end of the stack trace'''
if self.rows and self.cursorRowIndex == 0:
searchidx = len(self.rows) - 1
else:
searchidx = self.cursorRowIndex
pat = re.compile(r'^ +File "(.*)", line (\d+), in ')
for _, text in self.rows[searchidx::-1]: # rowdef: [linenum, text]
match = pat.search(text)
if match:
vd.launchEditor(match.group(1), f'+{match.group(2)}')
return


class ErrorCellSheet(ErrorSheet):
columns = [
ColumnItem('linenum', 0, type=int, width=0),
Expand Down Expand Up @@ -102,6 +119,7 @@ def recentErrorsSheet(self):

TextSheet.addCommand('^O', 'sysopen-sheet', 'sheet.sysopen(sheet.cursorRowIndex)', 'open copy of text sheet in $EDITOR and reload on exit')

ErrorSheet.addCommand('Enter', 'sysopen-error', 'sysopen_error(cursorCol, cursorRow)', 'open traceback line in $EDITOR')

TextSheet.options.save_filetype = 'txt'

Expand Down