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

Add option for line preprocessing #44

Closed
wants to merge 3 commits into from
Closed

Add option for line preprocessing #44

wants to merge 3 commits into from

Conversation

chrsmutti
Copy link
Contributor

@chrsmutti chrsmutti commented Oct 14, 2018

Add an option for the user manipulate the line that will be fed to the sorting algorithm, using a regular expression. This enables more powerful sorting alternatives without adding to much complexity.

With this regex the user will be able to select a part of a line to use as the sorting parameter, or maybe ignore some words.

vscode-line-sort

Using ^[Tt]he (.*)$

Fixes #40.
Fixes #33.

Add an option for the user manipulate the line that will
be fed to the sorting algorithm, using a regular expression.
This enables more powerful sorting alternatives without adding
to much complexity.
@Tyriar
Copy link
Owner

Tyriar commented Oct 15, 2018

I tried to test this using ^a+ (.*)$ and this text:


a bc
dac

But it didn't seem to work, am I doing something wrong?

@Tyriar Tyriar self-assigned this Oct 15, 2018
@chrsmutti
Copy link
Contributor Author

Thanks for testing it! That regex (^a+ (.*)$) would match a group bc for the first line, but it doesn't match any groups for the second line, so the line stays the same dac. The result would be, as you said:

a bc // ordered as bc
dac  // ordered as dac

What was the expected result? A regex that would change the sorting order would be \w ?(.*). That would leave us with the groups bc and ac, resulting in:

dac  // ordered as ac
a bc // ordered as bc

If you have an opinion on improving the underlying implementation and/or user interface I would gladly take it!

@Tyriar
Copy link
Owner

Tyriar commented Nov 26, 2018

Thanks for the example, my mistake. First thing I tried after that was ^([Tt]he|[Aa]) (.*)$ but it didn't seem to work because I think the ([Tt]he|[Aa]) is the first capture group? Do you think we also need a capture group number setting?

@chrsmutti
Copy link
Contributor Author

A capture group number setting is a great idea to make it really customizable! I'll work on it.

Added the option for the user to specify which capture group
will be used for sorting whenever linePreprocessorRegex is set
by setting the linePreprocessorRegexCaptureGroup config.
@chrsmutti
Copy link
Contributor Author

Hey @Tyriar, sorry for taking so long.

Added a linePreprocessorRegexCaptureGroup that defaults to 1, works great and adds tons of extra customization to the extension.

@rivy
Copy link

rivy commented Aug 4, 2019

This might be more generally and more flexibly implemented as a comparison customization, as @Tyriar suggested in #40 (comment), eg a.match(/(the|a)\s+(.*)/i)[2] > b.match(/(the|a)\s+(.*)/i)[2].

@chrsmutti chrsmutti closed this Apr 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature request: custom sort Sorting "the" and other articles, as natural
3 participants