When I paste text from other applications in to Cudatext I frequently am faced with the task of (1) removing extra spaces between words, and (2) removing unwanted line feeds/carriage returns at the end of lines so as to get a single line of text.
I often use a utility like https://codebeautify.org/text-cleaner to do that, but I would prefer to do it within Cudatext if possible.
Is there a plugin that addresses these tasks? If not, what is the best way to search for the endofline/carriage return characters so they can be replaced with nothing?
I see several options regarding switching between CR and LF but I don't see anything addressing the deletion of those characters entirely.
Thank you!
Cleaning Up Text - Deleting extra spaces and line feeds
-
- Posts: 14
- Joined: 11.07.2024 11:51
-
- Posts: 2265
- Joined: 25.08.2021 18:15
Re: Cleaning Up Text - Deleting extra spaces and line feeds
1. deletion of CR LF chars: command "Join lines" in CudaExt plugin (you have to select-all before calling it)
2. removing of dupl spaces: REGEX replace! replace with Regex flag from
\x20{2,}
to a space.
2. removing of dupl spaces: REGEX replace! replace with Regex flag from
\x20{2,}
to a space.
-
- Posts: 14
- Joined: 11.07.2024 11:51
Re: Cleaning Up Text - Deleting extra spaces and line feeds
And I already see how to assign those to a toolbar icon -- thank you!!
https://wiki.freepascal.org/CudaText#Ho ... ia_toolbar
https://wiki.freepascal.org/CudaText#Ho ... ia_toolbar
-
- Posts: 2265
- Joined: 25.08.2021 18:15
Re: Cleaning Up Text - Deleting extra spaces and line feeds
Ok. And i tried to make the SIMPLE plugin for that. w/out macros.
Use "Plugins / Make plugin" command and use this python code for __init__.py:
note: command is "cln" so adjust the "run" in the MakePlugin to "cln".
Use "Plugins / Make plugin" command and use this python code for __init__.py:
Code: Select all
import os
import re
from cudatext import *
class Command:
def cln(self):
s0 = ed.get_text_all()
s = s0.replace('\n', ' ')
s1 = re.sub(r'\x20{2,}', ' ', s)
if s1!=s0:
ed.set_text_all(s1)
msg_status('Cleaned')