From 943ad3b53b6d30c85870af4caa6dd6d7c044a7bc Mon Sep 17 00:00:00 2001 From: Filios92 Date: Sun, 4 Feb 2018 18:44:16 +0100 Subject: [PATCH 1/7] Add navigation with j/k/PgUp/PgDn, command to close all results views, fix for file path regex --- Default (Linux).sublime-keymap | 37 +++++++++++ Default (OSX).sublime-keymap | 37 +++++++++++ Default (Windows).sublime-keymap | 37 +++++++++++ Lookup Results.hidden-tmLanguage | 2 +- cscope.py | 103 ++++++++++++++++++++++++++----- 5 files changed, 201 insertions(+), 15 deletions(-) diff --git a/Default (Linux).sublime-keymap b/Default (Linux).sublime-keymap index e4cc429..d68f57d 100644 --- a/Default (Linux).sublime-keymap +++ b/Default (Linux).sublime-keymap @@ -51,6 +51,43 @@ "command": "cscope_visiter", "context": [{"key": "selector", "operand": "text.find-in-files"}] }, + { + "keys": ["j"], + "command": "cscope_visiter", + "context": [ + {"key": "selector", "operand": "text.find-in-files"}, + {"key": "setting.cscope_results"} + ], + "args": {"direction": "down"} + }, + { + "keys": ["k"], + "command": "cscope_visiter", + "context": [ + {"key": "selector", "operand": "text.find-in-files"}, + {"key": "setting.cscope_results"} + ], + "args": {"direction": "up"} + }, + { + "keys": ["pageup"], + "command": "cscope_visiter", + "context": [ + {"key": "selector", "operand": "text.find-in-files"}, + {"key": "setting.cscope_results"} + ], + "args": {"direction": "up2"} + }, + { + "keys": ["pagedown"], + "command": "cscope_visiter", + "context": [ + {"key": "selector", "operand": "text.find-in-files"}, + {"key": "setting.cscope_results"} + ], + "args": {"direction": "down2"} + }, + { "keys": ["ctrl+l", "ctrl+x"], "command": "close_cscope_tabs"}, { "keys": ["ctrl+shift+["], "command": "goback" diff --git a/Default (OSX).sublime-keymap b/Default (OSX).sublime-keymap index 815532d..ba8db10 100644 --- a/Default (OSX).sublime-keymap +++ b/Default (OSX).sublime-keymap @@ -51,6 +51,43 @@ "command": "cscope_visiter", "context": [{"key": "selector", "operand": "text.find-in-files"}] }, + { + "keys": ["j"], + "command": "cscope_visiter", + "context": [ + {"key": "selector", "operand": "text.find-in-files"}, + {"key": "setting.cscope_results"} + ], + "args": {"direction": "down"} + }, + { + "keys": ["k"], + "command": "cscope_visiter", + "context": [ + {"key": "selector", "operand": "text.find-in-files"}, + {"key": "setting.cscope_results"} + ], + "args": {"direction": "up"} + }, + { + "keys": ["pageup"], + "command": "cscope_visiter", + "context": [ + {"key": "selector", "operand": "text.find-in-files"}, + {"key": "setting.cscope_results"} + ], + "args": {"direction": "up2"} + }, + { + "keys": ["pagedown"], + "command": "cscope_visiter", + "context": [ + {"key": "selector", "operand": "text.find-in-files"}, + {"key": "setting.cscope_results"} + ], + "args": {"direction": "down2"} + }, + { "keys": ["ctrl+l", "ctrl+x"], "command": "close_cscope_tabs"}, { "keys": ["super+shift+["], "command": "goback" diff --git a/Default (Windows).sublime-keymap b/Default (Windows).sublime-keymap index e4cc429..d68f57d 100644 --- a/Default (Windows).sublime-keymap +++ b/Default (Windows).sublime-keymap @@ -51,6 +51,43 @@ "command": "cscope_visiter", "context": [{"key": "selector", "operand": "text.find-in-files"}] }, + { + "keys": ["j"], + "command": "cscope_visiter", + "context": [ + {"key": "selector", "operand": "text.find-in-files"}, + {"key": "setting.cscope_results"} + ], + "args": {"direction": "down"} + }, + { + "keys": ["k"], + "command": "cscope_visiter", + "context": [ + {"key": "selector", "operand": "text.find-in-files"}, + {"key": "setting.cscope_results"} + ], + "args": {"direction": "up"} + }, + { + "keys": ["pageup"], + "command": "cscope_visiter", + "context": [ + {"key": "selector", "operand": "text.find-in-files"}, + {"key": "setting.cscope_results"} + ], + "args": {"direction": "up2"} + }, + { + "keys": ["pagedown"], + "command": "cscope_visiter", + "context": [ + {"key": "selector", "operand": "text.find-in-files"}, + {"key": "setting.cscope_results"} + ], + "args": {"direction": "down2"} + }, + { "keys": ["ctrl+l", "ctrl+x"], "command": "close_cscope_tabs"}, { "keys": ["ctrl+shift+["], "command": "goback" diff --git a/Lookup Results.hidden-tmLanguage b/Lookup Results.hidden-tmLanguage index d811536..2b940ee 100644 --- a/Lookup Results.hidden-tmLanguage +++ b/Lookup Results.hidden-tmLanguage @@ -9,7 +9,7 @@ match - (.*):$ + ^(((?!scope: ).)*):$ captures 1 diff --git a/cscope.py b/cscope.py index 96d82de..116ca6a 100644 --- a/cscope.py +++ b/cscope.py @@ -41,6 +41,13 @@ def get_setting(key, default=None, view=None): pass return get_settings().get(key, default) +def update_result_selection(view, selection_index, selection): + view.settings().set('cscope_results_sel', selection_index) + view.add_regions('selection', [selection], 'comment', 'dot') + view.show(selection) + view.sel().clear() + view.sel().add(sublime.Region(selection.a, selection.a)) + class CscopeDatabase(object): def __init__(self, view, executable): @@ -170,10 +177,32 @@ class CscopeVisiter(sublime_plugin.TextCommand): def __init__(self, view): self.view = view - def run(self, edit): + def run(self, edit, **args): if self.view.settings().get('syntax') == CSCOPE_SYNTAX_FILE: + if args.get('direction'): + d = args.get('direction') + r = self.view.get_regions('results') + if r == []: + return + view_height = len(r) - 1 + s = self.view.settings().get('cscope_results_sel') + what = { + 'up': -1, + 'down': 1, + 'up2': -20, + 'down2': 20 + } + if d not in what: + return + s = s + what[d] + if s < 0: s = 0 + if s > view_height: s = view_height + + update_result_selection(self.view, s, r[s]) + return + root_re = re.compile(r'In folder (.+)') - filepath_re = re.compile(r'^(.+):$') + filepath_re = re.compile(r'^(((?!scope: ).)+):$') filename_re = re.compile(r'([a-zA-Z0-9_\-\.]+):') linenum_re = re.compile(r'^\s*([0-9]+)') @@ -295,24 +324,31 @@ def __init__(self, view, platform, database, symbol, mode, executable): # switch statement for the different formatted output # of Cscope's matches. def append_match_string(self, match, command_mode, nested): - match_string = "{0}".format(match["file"]) + match_string = {} + match_string['main'] = "{0}".format(match["file"]) if command_mode in [0, 4, 6, 8]: if nested: - match_string = ("{0:>6}\n{1:>6} [scope: {2}] {3}").format("..", match["line"], match["scope"], match["instance"]) + match_string['head'] = ("{0:>6}\n").format("..") + match_string['main'] = ("{0:>6} [scope: {1}] {2}").format(match["line"], match["scope"], match["instance"]) else: - match_string = ("\n{0}:\n{1:>6} [scope: {2}] {3}").format(match["file"].replace(self.database.root, "."), match["line"], match["scope"], match["instance"]) + match_string['head'] = ("\n{0}:\n").format(match["file"].replace(self.database.root, ".")) + match_string['main'] = ("{0:>6} [scope: {1}] {2}").format(match["line"], match["scope"], match["instance"]) elif command_mode == 1: if nested: - match_string = ("{0:>6}\n{1:>6} {2}").format("..", match["line"], match["instance"]) + match_string['head'] = ("{0:>6}\n").format("..") + match_string['main'] = ("{0:>6} {1}").format(match["line"], match["instance"]) else: - match_string = ("\n{0}:\n{1:>6} {2}").format(match["file"].replace(self.database.root, "."), match["line"], match["instance"]) + match_string['head'] = ("\n{0}:\n").format(match["file"].replace(self.database.root, ".")) + match_string['main'] = ("{0:>6} {1}").format(match["line"], match["instance"]) elif command_mode in [2, 3]: if nested: - match_string = ("{0:>6}\n{1:>6} [function: {2}] {3}").format("..", match["line"], match["function"], match["instance"]) + match_string['head'] = ("{0:>6}\n").format("..") + match_string['main'] = ("{0:>6} [function: {1}] {2}").format(match["line"], match["function"], match["instance"]) else: - match_string = ("\n{0}:\n{1:>6} [function: {2}] {3}").format(match["file"].replace(self.database.root, "."), match["line"], match["function"], match["instance"]) + match_string['head'] = ("\n{0}:\n").format(match["file"].replace(self.database.root, ".")) + match_string['main'] = ("{0:>6} [function: {1}] {2}").format(match["line"], match["function"], match["instance"]) elif command_mode == 7: - match_string = ("\n{0}:").format(match["file"].replace(self.database.root, ".")) + match_string['main'] = ("\n{0}:").format(match["file"].replace(self.database.root, ".")) return match_string @@ -395,9 +431,10 @@ def run_cscope(self, mode, word): def run(self): matches = self.run_cscope(self.mode, self.symbol) self.num_matches = len(matches) - self.output = "In folder " + self.database.root + \ + header = "In folder " + self.database.root + \ "\nFound " + str(len(matches)) + " matches for " + CSCOPE_SEARCH_MODES[self.mode] + \ - ": " + self.symbol + "\n" + 50*"-" + "\n\n" + "\n".join(matches) + ": " + self.symbol + "\n" + 50*"-" + "\n" + self.output = [ header, matches ] class CscopeCommand(sublime_plugin.TextCommand): @@ -505,6 +542,8 @@ def display_results(self, symbol, output): cscope_view.set_syntax_file(CSCOPE_SYNTAX_FILE) cscope_view.set_read_only(True) + cscope_view.settings().set('cscope_results', True) + cscope_view.settings().set('cscope_results_sel', 0) def run(self, edit, mode): self.mode = mode @@ -571,7 +610,43 @@ def rebuild_database(self): class DisplayCscopeResultsCommand(sublime_plugin.TextCommand): def run(self, edit): - self.view.insert(edit, CscopeCommand.cscope_output_info['pos'], CscopeCommand.cscope_output_info['text']) + r = [] + header, matches = CscopeCommand.cscope_output_info['text'] + self.view.insert(edit, CscopeCommand.cscope_output_info['pos'], header) + for m in matches: + head = '\n' + m['head'] + start = self.view.size() + self.view.insert(edit, start, head) + start = self.view.size() + self.view.insert(edit, start, m['main']) + region = sublime.Region(start, self.view.size()) + r.append(region) + self.view.add_regions('results', r) + if r: update_result_selection(self.view, 0, r[0]) if get_setting("display_outline") == True: symbol_regions = self.view.find_all(CscopeCommand.cscope_output_info['symbol'], sublime.LITERAL) - self.view.add_regions('cscopesublime-outlines', symbol_regions[1:], "text.find-in-files", "", sublime.DRAW_OUTLINED) + self.view.add_regions('cscopesublime-outlines', symbol_regions[1:], "entity.name.filename.find-in-files", "", sublime.DRAW_OUTLINED) + +class UpdateCscopeResultSelection(sublime_plugin.ViewEventListener): + def __init__(self, *args, **kwargs): + super(UpdateCscopeResultSelection, self).__init__(*args, **kwargs) + self.mouse_point = -1 + + @classmethod + def is_applicable(cls, settings): + return settings.get('cscope_results') + + def on_selection_modified(self): + mouse_point = self.view.sel()[0].a + if mouse_point == self.mouse_point: + return + self.mouse_point = mouse_point + r = self.view.get_regions('results') + for x in r: + if x.contains(mouse_point): + update_result_selection(self.view, r.index(x), x) + break + +class CloseCscopeTabsCommand(sublime_plugin.TextCommand): + def run(self, edit): + [x.close() for x in self.view.window().views() if x.settings().get('cscope_results')] From 184ea07076cc276448e546cfda074e7ef3da31a2 Mon Sep 17 00:00:00 2001 From: Filios92 Date: Sun, 4 Feb 2018 20:11:51 +0100 Subject: [PATCH 2/7] Creating database in first project path --- cscope.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cscope.py b/cscope.py index 116ca6a..999efcb 100644 --- a/cscope.py +++ b/cscope.py @@ -131,11 +131,11 @@ def update_location(self, filename): # If we haven't found an existing database location and root # directory, and the user has a project defined for this, and - # there's only one path in that project, let's just assume that that + # there's one or more paths in that project, let's just assume that first # path is the root of the project. This should be a safe assumption # and should allow us to create an initial database, if one doesn't # exist, in a sane place. - if self.root is None and self.location is None and len(project_info_paths) == 1: + if self.root is None and self.location is None and len(project_info_paths) >= 1: self.root = project_info_paths[0] print('CscopeDatabase: Database not found but setting root: {}' .format(self.root)) From e5e94d99b15bce0344c930236e8d1dc133292690 Mon Sep 17 00:00:00 2001 From: Filios92 Date: Sun, 4 Feb 2018 20:36:58 +0100 Subject: [PATCH 3/7] Closing opened moved to main TextCommand, keyboard shortcuts for closing opened tabs and rebuilding DB, OSX fix --- Default (Linux).sublime-keymap | 9 ++++++++- Default (OSX).sublime-keymap | 9 ++++++++- Default (Windows).sublime-keymap | 9 ++++++++- Default.sublime-commands | 5 +++++ cscope.py | 9 +++++---- 5 files changed, 34 insertions(+), 7 deletions(-) diff --git a/Default (Linux).sublime-keymap b/Default (Linux).sublime-keymap index d68f57d..42cd70a 100644 --- a/Default (Linux).sublime-keymap +++ b/Default (Linux).sublime-keymap @@ -87,7 +87,14 @@ ], "args": {"direction": "down2"} }, - { "keys": ["ctrl+l", "ctrl+x"], "command": "close_cscope_tabs"}, + { "keys": ["ctrl+l", "ctrl+x"], + "command": "cscope", + "args": { "mode": "close_opened_results" } + }, + { "keys": ["ctrl+l", "ctrl+f"], + "command": "cscope", + "args": { "mode": "database_rebuild" } + }, { "keys": ["ctrl+shift+["], "command": "goback" diff --git a/Default (OSX).sublime-keymap b/Default (OSX).sublime-keymap index ba8db10..bc233a8 100644 --- a/Default (OSX).sublime-keymap +++ b/Default (OSX).sublime-keymap @@ -87,7 +87,14 @@ ], "args": {"direction": "down2"} }, - { "keys": ["ctrl+l", "ctrl+x"], "command": "close_cscope_tabs"}, + { "keys": ["super+l", "super+x"], + "command": "cscope", + "args": { "mode": "close_opened_results" } + }, + { "keys": ["super+l", "super+f"], + "command": "cscope", + "args": { "mode": "database_rebuild" } + }, { "keys": ["super+shift+["], "command": "goback" diff --git a/Default (Windows).sublime-keymap b/Default (Windows).sublime-keymap index d68f57d..42cd70a 100644 --- a/Default (Windows).sublime-keymap +++ b/Default (Windows).sublime-keymap @@ -87,7 +87,14 @@ ], "args": {"direction": "down2"} }, - { "keys": ["ctrl+l", "ctrl+x"], "command": "close_cscope_tabs"}, + { "keys": ["ctrl+l", "ctrl+x"], + "command": "cscope", + "args": { "mode": "close_opened_results" } + }, + { "keys": ["ctrl+l", "ctrl+f"], + "command": "cscope", + "args": { "mode": "database_rebuild" } + }, { "keys": ["ctrl+shift+["], "command": "goback" diff --git a/Default.sublime-commands b/Default.sublime-commands index 16a50be..919c549 100644 --- a/Default.sublime-commands +++ b/Default.sublime-commands @@ -43,5 +43,10 @@ "caption": "Cscope: Rebuild database", "command": "cscope", "args": { "mode": "database_rebuild" } + }, + { + "caption": "Cscope: Close all opened results", + "command": "cscope", + "args": { "mode": "close_opened_results" } } ] diff --git a/cscope.py b/cscope.py index 999efcb..b9fe3f3 100644 --- a/cscope.py +++ b/cscope.py @@ -26,6 +26,7 @@ 8: "files #including this file" } CSCOPE_CMD_DATABASE_REBUILD = "database_rebuild" +CSCOPE_CMD_CLOSE_OPENED = "close_opened_results" def get_settings(): return sublime.load_settings("CscopeSublime.sublime-settings") @@ -546,6 +547,10 @@ def display_results(self, symbol, output): cscope_view.settings().set('cscope_results_sel', 0) def run(self, edit, mode): + if mode == CSCOPE_CMD_CLOSE_OPENED: + [x.close() for x in self.view.window().views() if x.settings().get('cscope_results')] + return + self.mode = mode self.executable = get_setting("executable", "cscope") @@ -646,7 +651,3 @@ def on_selection_modified(self): if x.contains(mouse_point): update_result_selection(self.view, r.index(x), x) break - -class CloseCscopeTabsCommand(sublime_plugin.TextCommand): - def run(self, edit): - [x.close() for x in self.view.window().views() if x.settings().get('cscope_results')] From 12e0562b5227a49db1a5973c7896f5ad39ea6f91 Mon Sep 17 00:00:00 2001 From: Filios92 Date: Sun, 4 Feb 2018 21:00:34 +0100 Subject: [PATCH 4/7] Better handling of selection updating --- cscope.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cscope.py b/cscope.py index b9fe3f3..3bac579 100644 --- a/cscope.py +++ b/cscope.py @@ -42,12 +42,13 @@ def get_setting(key, default=None, view=None): pass return get_settings().get(key, default) -def update_result_selection(view, selection_index, selection): +def update_result_selection(view, selection_index, selection, update_sel=True): view.settings().set('cscope_results_sel', selection_index) view.add_regions('selection', [selection], 'comment', 'dot') view.show(selection) - view.sel().clear() - view.sel().add(sublime.Region(selection.a, selection.a)) + if update_sel: + view.sel().clear() + view.sel().add(sublime.Region(selection.a, selection.a)) class CscopeDatabase(object): @@ -649,5 +650,5 @@ def on_selection_modified(self): r = self.view.get_regions('results') for x in r: if x.contains(mouse_point): - update_result_selection(self.view, r.index(x), x) + update_result_selection(self.view, r.index(x), x, False) break From b9f9a1c4d2c9dbe96560817b28e7ae33d89503ae Mon Sep 17 00:00:00 2001 From: Filios92 Date: Sun, 4 Feb 2018 22:18:30 +0100 Subject: [PATCH 5/7] Add option for treating next folders in project as additional source dirs --- CscopeSublime.sublime-settings | 4 ++++ cscope.py | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/CscopeSublime.sublime-settings b/CscopeSublime.sublime-settings index 85ef125..6f7cdd9 100644 --- a/CscopeSublime.sublime-settings +++ b/CscopeSublime.sublime-settings @@ -31,4 +31,8 @@ // An optional custom command used to build cscope's database. // This must be in array format. //"database_build_command": [ "cscope-indexer", "-r" ], + + // On default build command, whether to treat folders in project (after the 1st one) as + // additional source directories + "auto_next_source_dirs": false, } diff --git a/cscope.py b/cscope.py index 3bac579..014856e 100644 --- a/cscope.py +++ b/cscope.py @@ -155,6 +155,14 @@ def rebuild(self): if not (cscope_arg_list and isinstance(cscope_arg_list, list)): cscope_arg_list = [self.executable, '-Rbq'] + # If the user has a project with more than one path and we're putting + # the database in the first one, treat other paths as additional source dirs + if get_setting('auto_next_source_dirs') and hasattr(self.view.window(), 'project_data'): + project_info = self.view.window().project_data() + if project_info and 'folders' in project_info and project_info['folders'][0]['path'] == self.root: + for folder in project_info['folders'][1:]: + cscope_arg_list += ["-s", folder['path']] + print('CscopeDatabase: Rebuilding database in directory: {}, using command: {}' .format(self.root, cscope_arg_list)) From 580142c65b57869af6ff5eaee7f476617adfe677 Mon Sep 17 00:00:00 2001 From: Filios92 Date: Sun, 8 Apr 2018 21:54:44 +0200 Subject: [PATCH 6/7] Fix for ST2, comments and naming --- CscopeSublime.sublime-settings | 2 +- Default (Linux).sublime-keymap | 4 +- Default (OSX).sublime-keymap | 4 +- Default (Windows).sublime-keymap | 4 +- cscope.py | 67 +++++++++++++++++++------------- 5 files changed, 47 insertions(+), 34 deletions(-) diff --git a/CscopeSublime.sublime-settings b/CscopeSublime.sublime-settings index 6f7cdd9..85ae5cd 100644 --- a/CscopeSublime.sublime-settings +++ b/CscopeSublime.sublime-settings @@ -34,5 +34,5 @@ // On default build command, whether to treat folders in project (after the 1st one) as // additional source directories - "auto_next_source_dirs": false, + "auto_next_source_dirs": false } diff --git a/Default (Linux).sublime-keymap b/Default (Linux).sublime-keymap index 42cd70a..d83f281 100644 --- a/Default (Linux).sublime-keymap +++ b/Default (Linux).sublime-keymap @@ -76,7 +76,7 @@ {"key": "selector", "operand": "text.find-in-files"}, {"key": "setting.cscope_results"} ], - "args": {"direction": "up2"} + "args": {"direction": "pageup"} }, { "keys": ["pagedown"], @@ -85,7 +85,7 @@ {"key": "selector", "operand": "text.find-in-files"}, {"key": "setting.cscope_results"} ], - "args": {"direction": "down2"} + "args": {"direction": "pagedown"} }, { "keys": ["ctrl+l", "ctrl+x"], "command": "cscope", diff --git a/Default (OSX).sublime-keymap b/Default (OSX).sublime-keymap index bc233a8..51bc709 100644 --- a/Default (OSX).sublime-keymap +++ b/Default (OSX).sublime-keymap @@ -76,7 +76,7 @@ {"key": "selector", "operand": "text.find-in-files"}, {"key": "setting.cscope_results"} ], - "args": {"direction": "up2"} + "args": {"direction": "pageup"} }, { "keys": ["pagedown"], @@ -85,7 +85,7 @@ {"key": "selector", "operand": "text.find-in-files"}, {"key": "setting.cscope_results"} ], - "args": {"direction": "down2"} + "args": {"direction": "pagedown"} }, { "keys": ["super+l", "super+x"], "command": "cscope", diff --git a/Default (Windows).sublime-keymap b/Default (Windows).sublime-keymap index 42cd70a..d83f281 100644 --- a/Default (Windows).sublime-keymap +++ b/Default (Windows).sublime-keymap @@ -76,7 +76,7 @@ {"key": "selector", "operand": "text.find-in-files"}, {"key": "setting.cscope_results"} ], - "args": {"direction": "up2"} + "args": {"direction": "pageup"} }, { "keys": ["pagedown"], @@ -85,7 +85,7 @@ {"key": "selector", "operand": "text.find-in-files"}, {"key": "setting.cscope_results"} ], - "args": {"direction": "down2"} + "args": {"direction": "pagedown"} }, { "keys": ["ctrl+l", "ctrl+x"], "command": "cscope", diff --git a/cscope.py b/cscope.py index 014856e..0b9bc45 100644 --- a/cscope.py +++ b/cscope.py @@ -43,9 +43,13 @@ def get_setting(key, default=None, view=None): return get_settings().get(key, default) def update_result_selection(view, selection_index, selection, update_sel=True): + # Set index of new selection, highlight it and move view to it view.settings().set('cscope_results_sel', selection_index) + if view.get_regions('selection'): + # Do not scroll view on first open (prevents glitch on ST2) + view.show(selection) view.add_regions('selection', [selection], 'comment', 'dot') - view.show(selection) + # Update cursor position to new result if update_sel: view.sel().clear() view.sel().add(sublime.Region(selection.a, selection.a)) @@ -189,6 +193,7 @@ def __init__(self, view): def run(self, edit, **args): if self.view.settings().get('syntax') == CSCOPE_SYNTAX_FILE: + # Handle keyboard navigation if args.get('direction'): d = args.get('direction') r = self.view.get_regions('results') @@ -199,8 +204,8 @@ def run(self, edit, **args): what = { 'up': -1, 'down': 1, - 'up2': -20, - 'down2': 20 + 'pageup': -20, + 'pagedown': 20 } if d not in what: return @@ -334,30 +339,34 @@ def __init__(self, view, platform, database, symbol, mode, executable): # switch statement for the different formatted output # of Cscope's matches. def append_match_string(self, match, command_mode, nested): + # 'head': contains file name or separator '..' + # 'main': contains main line with result of lookup match_string = {} match_string['main'] = "{0}".format(match["file"]) + result_separator = ("{0:>6}\n").format("..") if command_mode in [0, 4, 6, 8]: if nested: - match_string['head'] = ("{0:>6}\n").format("..") + match_string['head'] = result_separator match_string['main'] = ("{0:>6} [scope: {1}] {2}").format(match["line"], match["scope"], match["instance"]) else: match_string['head'] = ("\n{0}:\n").format(match["file"].replace(self.database.root, ".")) match_string['main'] = ("{0:>6} [scope: {1}] {2}").format(match["line"], match["scope"], match["instance"]) elif command_mode == 1: if nested: - match_string['head'] = ("{0:>6}\n").format("..") + match_string['head'] = result_separator match_string['main'] = ("{0:>6} {1}").format(match["line"], match["instance"]) else: match_string['head'] = ("\n{0}:\n").format(match["file"].replace(self.database.root, ".")) match_string['main'] = ("{0:>6} {1}").format(match["line"], match["instance"]) elif command_mode in [2, 3]: if nested: - match_string['head'] = ("{0:>6}\n").format("..") + match_string['head'] = result_separator match_string['main'] = ("{0:>6} [function: {1}] {2}").format(match["line"], match["function"], match["instance"]) else: match_string['head'] = ("\n{0}:\n").format(match["file"].replace(self.database.root, ".")) match_string['main'] = ("{0:>6} [function: {1}] {2}").format(match["line"], match["function"], match["instance"]) elif command_mode == 7: + match_string['head'] = '' match_string['main'] = ("\n{0}:").format(match["file"].replace(self.database.root, ".")) return match_string @@ -624,39 +633,43 @@ def rebuild_database(self): class DisplayCscopeResultsCommand(sublime_plugin.TextCommand): def run(self, edit): - r = [] + results = [] # results regions header, matches = CscopeCommand.cscope_output_info['text'] self.view.insert(edit, CscopeCommand.cscope_output_info['pos'], header) for m in matches: + # insert header/file name head = '\n' + m['head'] start = self.view.size() self.view.insert(edit, start, head) + # insert line with result start = self.view.size() self.view.insert(edit, start, m['main']) + # get and save region of line with result region = sublime.Region(start, self.view.size()) - r.append(region) - self.view.add_regions('results', r) - if r: update_result_selection(self.view, 0, r[0]) + results.append(region) + self.view.add_regions('results', results) + if results: update_result_selection(self.view, 0, results[0]) if get_setting("display_outline") == True: symbol_regions = self.view.find_all(CscopeCommand.cscope_output_info['symbol'], sublime.LITERAL) self.view.add_regions('cscopesublime-outlines', symbol_regions[1:], "entity.name.filename.find-in-files", "", sublime.DRAW_OUTLINED) -class UpdateCscopeResultSelection(sublime_plugin.ViewEventListener): - def __init__(self, *args, **kwargs): - super(UpdateCscopeResultSelection, self).__init__(*args, **kwargs) - self.mouse_point = -1 +if sublime.version()[0] >= '3': + class UpdateCscopeResultSelection(sublime_plugin.ViewEventListener): + def __init__(self, *args, **kwargs): + super(UpdateCscopeResultSelection, self).__init__(*args, **kwargs) + self.mouse_point = -1 - @classmethod - def is_applicable(cls, settings): - return settings.get('cscope_results') + @classmethod + def is_applicable(cls, settings): + return settings.get('cscope_results') - def on_selection_modified(self): - mouse_point = self.view.sel()[0].a - if mouse_point == self.mouse_point: - return - self.mouse_point = mouse_point - r = self.view.get_regions('results') - for x in r: - if x.contains(mouse_point): - update_result_selection(self.view, r.index(x), x, False) - break + def on_selection_modified(self): + mouse_point = self.view.sel()[0].a + if mouse_point == self.mouse_point: + return + self.mouse_point = mouse_point + r = self.view.get_regions('results') + for x in r: + if x.contains(mouse_point): + update_result_selection(self.view, r.index(x), x, False) + break From c59dc983b914e955ee5d2a6345377848940e46ea Mon Sep 17 00:00:00 2001 From: Filios92 Date: Sun, 8 Apr 2018 21:56:35 +0200 Subject: [PATCH 7/7] Remove sublime-keymap changes --- Default (Linux).sublime-keymap | 44 -------------------------------- Default (OSX).sublime-keymap | 44 -------------------------------- Default (Windows).sublime-keymap | 44 -------------------------------- 3 files changed, 132 deletions(-) diff --git a/Default (Linux).sublime-keymap b/Default (Linux).sublime-keymap index d83f281..e4cc429 100644 --- a/Default (Linux).sublime-keymap +++ b/Default (Linux).sublime-keymap @@ -51,50 +51,6 @@ "command": "cscope_visiter", "context": [{"key": "selector", "operand": "text.find-in-files"}] }, - { - "keys": ["j"], - "command": "cscope_visiter", - "context": [ - {"key": "selector", "operand": "text.find-in-files"}, - {"key": "setting.cscope_results"} - ], - "args": {"direction": "down"} - }, - { - "keys": ["k"], - "command": "cscope_visiter", - "context": [ - {"key": "selector", "operand": "text.find-in-files"}, - {"key": "setting.cscope_results"} - ], - "args": {"direction": "up"} - }, - { - "keys": ["pageup"], - "command": "cscope_visiter", - "context": [ - {"key": "selector", "operand": "text.find-in-files"}, - {"key": "setting.cscope_results"} - ], - "args": {"direction": "pageup"} - }, - { - "keys": ["pagedown"], - "command": "cscope_visiter", - "context": [ - {"key": "selector", "operand": "text.find-in-files"}, - {"key": "setting.cscope_results"} - ], - "args": {"direction": "pagedown"} - }, - { "keys": ["ctrl+l", "ctrl+x"], - "command": "cscope", - "args": { "mode": "close_opened_results" } - }, - { "keys": ["ctrl+l", "ctrl+f"], - "command": "cscope", - "args": { "mode": "database_rebuild" } - }, { "keys": ["ctrl+shift+["], "command": "goback" diff --git a/Default (OSX).sublime-keymap b/Default (OSX).sublime-keymap index 51bc709..815532d 100644 --- a/Default (OSX).sublime-keymap +++ b/Default (OSX).sublime-keymap @@ -51,50 +51,6 @@ "command": "cscope_visiter", "context": [{"key": "selector", "operand": "text.find-in-files"}] }, - { - "keys": ["j"], - "command": "cscope_visiter", - "context": [ - {"key": "selector", "operand": "text.find-in-files"}, - {"key": "setting.cscope_results"} - ], - "args": {"direction": "down"} - }, - { - "keys": ["k"], - "command": "cscope_visiter", - "context": [ - {"key": "selector", "operand": "text.find-in-files"}, - {"key": "setting.cscope_results"} - ], - "args": {"direction": "up"} - }, - { - "keys": ["pageup"], - "command": "cscope_visiter", - "context": [ - {"key": "selector", "operand": "text.find-in-files"}, - {"key": "setting.cscope_results"} - ], - "args": {"direction": "pageup"} - }, - { - "keys": ["pagedown"], - "command": "cscope_visiter", - "context": [ - {"key": "selector", "operand": "text.find-in-files"}, - {"key": "setting.cscope_results"} - ], - "args": {"direction": "pagedown"} - }, - { "keys": ["super+l", "super+x"], - "command": "cscope", - "args": { "mode": "close_opened_results" } - }, - { "keys": ["super+l", "super+f"], - "command": "cscope", - "args": { "mode": "database_rebuild" } - }, { "keys": ["super+shift+["], "command": "goback" diff --git a/Default (Windows).sublime-keymap b/Default (Windows).sublime-keymap index d83f281..e4cc429 100644 --- a/Default (Windows).sublime-keymap +++ b/Default (Windows).sublime-keymap @@ -51,50 +51,6 @@ "command": "cscope_visiter", "context": [{"key": "selector", "operand": "text.find-in-files"}] }, - { - "keys": ["j"], - "command": "cscope_visiter", - "context": [ - {"key": "selector", "operand": "text.find-in-files"}, - {"key": "setting.cscope_results"} - ], - "args": {"direction": "down"} - }, - { - "keys": ["k"], - "command": "cscope_visiter", - "context": [ - {"key": "selector", "operand": "text.find-in-files"}, - {"key": "setting.cscope_results"} - ], - "args": {"direction": "up"} - }, - { - "keys": ["pageup"], - "command": "cscope_visiter", - "context": [ - {"key": "selector", "operand": "text.find-in-files"}, - {"key": "setting.cscope_results"} - ], - "args": {"direction": "pageup"} - }, - { - "keys": ["pagedown"], - "command": "cscope_visiter", - "context": [ - {"key": "selector", "operand": "text.find-in-files"}, - {"key": "setting.cscope_results"} - ], - "args": {"direction": "pagedown"} - }, - { "keys": ["ctrl+l", "ctrl+x"], - "command": "cscope", - "args": { "mode": "close_opened_results" } - }, - { "keys": ["ctrl+l", "ctrl+f"], - "command": "cscope", - "args": { "mode": "database_rebuild" } - }, { "keys": ["ctrl+shift+["], "command": "goback"