-
Notifications
You must be signed in to change notification settings - Fork 93
some changes to make it work like Emacs vertical file completion. #185
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
c6c13fd
988b8a5
9066872
c4dcae7
26a17b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,9 @@ | |
| {"keys": ["ctrl+l"],"command": "advanced_new_file_updir", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why L? Is that how emacs does it? Please add some comments above the binding to explain their inspiration because I (for example) wouldn't know otherwise. Probably to the readme as well. |
||
| "context": [{"key": "setting.anf_panel"}] | ||
| }, | ||
| {"keys": ["enter"],"command": "advanced_new_file_confirm", | ||
| "context": [{"key": "setting.anf_panel"}] | ||
| }, | ||
|
Comment on lines
+21
to
+23
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this prevent submitting the inserted new file name when the completion list is not visible? It would also not match the native completions UX if |
||
| {"keys": ["ctrl+j"],"command": "insert", "args": {"characters": "\t"}, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose this is how tab completion works currently, but I find that questionable when you could instead bind the tab key to a proper command instead. |
||
| "context": [{"key": "setting.anf_panel"}] | ||
| }, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| from operator import itemgetter | ||
| # import numpy as np | ||
|
|
||
| def sort_by_fuzzy(query, choices): | ||
| if not query or not choices: | ||
| return choices | ||
| choices_ratio = {} | ||
| for choice in choices: | ||
| choices_ratio[choice] = levenshtein_ratio(query, choice) | ||
|
|
||
| # print(choices_ratio) | ||
| return [key[0] for key in sorted(choices_ratio.items(), key=itemgetter(1), reverse=True)] | ||
|
|
||
| def levenshtein_ratio(s, t): | ||
| """ levenshtein_ratio_and_distance: | ||
| Calculates levenshtein distance between two strings. | ||
| If ratio_calc = True, the function computes the | ||
| levenshtein distance ratio of similarity between two strings | ||
| For all i and j, distance[i,j] will contain the Levenshtein | ||
| distance between the first i characters of s and the | ||
| first j characters of t | ||
| """ | ||
| # Initialize matrix of zeros | ||
| rows = len(s)+1 | ||
| cols = len(t)+1 | ||
| distance = [[0 for i in range(cols)] for j in range(rows)] | ||
| # distance = np.zeros((rows, cols),dtype=int) | ||
|
|
||
| # Populate matrix of zeros with the indeces of each character of both strings | ||
| for i in range(1, rows): | ||
| for k in range(1,cols): | ||
| distance[i][0] = i | ||
| distance[0][k] = k | ||
|
|
||
| # Iterate over the matrix to compute the cost of deletions,insertions and/or substitutions | ||
| for col in range(1, cols): | ||
| for row in range(1, rows): | ||
| if s[row-1].lower() == t[col-1].lower(): | ||
| cost = 0 # If the characters are the same in the two strings in a given position [i,j] then the cost is 0 | ||
| else: | ||
| # In order to align the results with those of the Python Levenshtein package, if we choose to calculate the ratio | ||
| # the cost of a substitution is 2. | ||
| cost = 1 | ||
| distance[row][col] = min(distance[row-1][col] + 1, # Cost of deletions | ||
| distance[row][col-1] + 1, # Cost of insertions | ||
| distance[row-1][col-1] + cost) # Cost of substitutions | ||
|
|
||
| # Computation of the Levenshtein Distance Ratio | ||
| ratio = ((len(s)+len(t)) - distance[row][col]) / (len(s)+len(t)) | ||
| if rows < cols: | ||
| ratio = max(ratio, ((len(s)+len(t)) - distance[row][row]) / (len(s)+len(t))) | ||
| return ratio | ||
|
|
||
| # if __name__ == '__main__': | ||
| # print(levenshtein_ratio('test', 'test')) | ||
| # print(levenshtein_ratio('test', 'test tt')) | ||
| # print(levenshtein_ratio('test', 'taebsct')) | ||
| # print(levenshtein_ratio('test', 'tabtest')) | ||
| # print(levenshtein_ratio('test', 'tst tt')) | ||
| # print(sort_by_fuzzy('def', ['advanced_new_file', 'AdvancedNewFile.py', 'AdvancedNewFile.sublime-settings', 'Default (Linux).sublime-keymap', 'Default (OSX).sublime-keymap', 'Default (Windows).sublime-keymap', 'Default.sublime-commands'])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This setting needs more context. I'd guess it is for filtering out the completions, but guessing is all I can do from reading this.