coteditor / CotEditor

Lightweight Plain-Text Editor for macOS
https://coteditor.com
Other
6.24k stars 427 forks source link

Manipulating white space #1534

Closed zackbatist closed 9 months ago

zackbatist commented 9 months ago

First of all, thanks for making this great software. It was one of the applications I was most excited to download after upgrading from a much older and unsupported computer.

Is your feature request related to a problem? Please describe. I commonly work with text copied and pasted from other documents, which I have to re-format and re-arrange in markdown. In some cases there is redundant white space. In other cases, paragraphs get pasted in with jagged right edges, breaking in ways that are not commensurate with the flow of the text. Additionally, some tidily arranged paragraphs do not have line breaks at the end of each sentence, which is the way I prefer to work (with a double line break at the end of each paragraph). It would be great to have some simple text manipulation tools to resolve these issues and format the text to conform to the way I like to work with it, rather than having to manually go through the document line by line to account for these discrepancies.

Describe the solution you'd like Add text transformation tools that allow the user to remove or add redundant white space from specific parts of a line or according to specific patterns.

Remove redundant spaces: For every instance with two or more consecutive white spaces, replace with only one white space. Make an option to exclude instances at the start of a line (when indents are counted as double or quadruple white spaces, for instance).

Remove jagged right edges: For every group of text bounded by double line breaks (e.g. a discrete paragraph), identify single new lines and replace them with a single white space instead. Give the option to also remove hyphens that are sometimes applied to connect parts of a word spanning two lines (remove hyphen and do not apply a white space).

Break paragraph into lines: For every group of text bounded by double liune breaks (e.g. a discrete paragraph, identify a pattern of period + white space and replace with a new line instead.

Describe alternatives you've considered See the obsidian text format plugin (https://github.com/Benature/obsidian-text-format), which includes a "merge broken paragraph" feature. This does not fully account for my desired use case, but seems similar in spirit.

Additional context N/A

1024jp commented 9 months ago

One of CotEditor's development philosophies is to avoid complicating the UI by easily implementing trivial commands. From this point of view, I will not implement your request straightforwardly. (In addition, it is not the same for all users what is redundant spaces or jagged edges.)

Instead, I'd like to suggest that you utilize the multiple replacement feature that CotEditor already has. This feature enables you to modify documents in a preset procedure by using the regular expression.

For instance, your “Remove redundant spaces” can be realized by setting the find string as (?<=\S)[\t ]{2,} and the replacement string as (single space) by checking the RE column.

Screenshot 2023-10-14 at 12 08 08
1024jp commented 9 months ago

Another suggestion can be creating CotEditor scripts to perform those regular expression replacements. In this way, you can even perform the modification from the main menu (the Script menu) and provide shortcut keys.

zackbatist commented 9 months ago

I understand where you're coming from, but I still believe it would fit naturally within either the substitutions or transformations menus. I think it's a common enough problem (and regular expressions is difficult enough to do on your own) that this is warranted. I may post here again with a link to a blog post that explain some common expressions that relate to this issue.

I was not aware of the "Multiple replace" menu until you showed it to me. This is one reason I love using this software (always finding cool new things!)