Using a Text Factory to remove white space

885 views
Skip to first unread message

brian schroeder

unread,
Feb 7, 2017, 1:43:29 PM2/7/17
to BBEdit Talk

Hi.  How could you use a text factory to remove white space?  Thanks.


Change:   


       F,sec,   cfm,           vdc

  F,  sec,   cfm


To:


F,sec,cfm,vdc

F,sec,cfm


Christopher Stone

unread,
Feb 7, 2017, 4:46:52 PM2/7/17
to BBEdit-Talk
On Feb 07, 2017, at 12:29, brian schroeder <b.schro...@gmail.com> wrote:
Hi.  How could you use a text factory to remove white space?  Thanks.


Hey Brian,

Open a new Text Factory.

Leave the target as (nothing to process)

Select “Replace All”

Select “Options”

Turn on “grep”

Search for:

[[:blank:]]+

Replace with:

Nothing

Save it here:

~/Library/Application Support/BBEdit/Text Filters/

Personally I subcategorize Text Filters like so:

~/Library/Application Support/BBEdit/Text Filters/Textfactories/removeHorizontalWhitespace.textfactory

Run the Text Factory from the menu Text > Apply Text Filter > [Your Text Factory], or give it a keyboard shortcut in the BBEdit prefs.

Personally I'd rather use AppleScript than a Text Factory, because it's faster – and I have more control.

-------------------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2017/02/07 15:00
# dMod: 2017/02/07 15:33 
# Appl: BBEdit
# Task: General Handler for Find/Replace – operates on selection if exists – otherwise the whole document.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @BBEdit, @Handler, @Find, @Replace, @Document, @Selection, @RegEx
-------------------------------------------------------------------------------------------

bbReplaceText("[[:blank:]]+", "")

-------------------------------------------------------------------------------------------
--» HANDLERS
-------------------------------------------------------------------------------------------
on bbReplaceText(findPattern, replacePattern)
   tell application "BBEdit"
      if (contents of the selection) ≠ "" then
         tell front text window's its text of selection
            replace findPattern using replacePattern options {search mode:grep, case sensitive:false}
         end tell
      else
         tell front text window's its text
            replace findPattern using replacePattern options {search mode:grep, case sensitive:false, starting at top:true}
         end tell
      end if
   end tell
end bbReplaceText
-------------------------------------------------------------------------------------------

--
Best Regards,
Chris

John Muccigrosso

unread,
Feb 8, 2017, 9:39:46 AM2/8/17
to BBEdit Talk, listm...@suddenlink.net
If you really want all white space (tabs, newlines, etc) then use "\s+" as the search pattern.

This is such a fast search and replace, I'd probably use the usual dialog or write a quick perl or shell script for it.

brian schroeder

unread,
Feb 10, 2017, 1:43:02 PM2/10/17
to BBEdit Talk
That helps a lot.

Thanks, Chris!

Thanks, John!

-Brian

Christopher Stone

unread,
Feb 10, 2017, 7:30:40 PM2/10/17
to BBEdit-Talk
On Feb 10, 2017, at 12:36, brian schroeder <b.schro...@gmail.com> wrote:
That helps a lot.
Thanks, Chris!


Hey Brian,

You're welcome.

Just for giggles here are a couple of text-filters.

A simple one-liner `sed` script to remove all horizontal whitespace.

#!/usr/bin/env bash
# ------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2017/02/10 17:53
# dMod: 2017/02/10 18:13
# Task: Remove all horizontal whitespace.
# Tags: @Remove, @Horizontal, @Whitespace
# ------------------------------------------------------------------------------

sed -E 's![[:blank:]]+!!g'

Another simple `sed` script to remove all horizontal whitespace and blank lines.

#!/usr/bin/env bash
# ------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2017/02/10 17:53
# dMod: 2017/02/10 18:11
# Task: Remove all leading, trailing whitespace and delete blank lines.
# Tags: @Remove, @Leading, @Trailing, @Whitespace, @Delete, @Blank, @Lines
# ------------------------------------------------------------------------------

sed -En '
    s![[:blank:]]+!!g
    /^$/d
    p
'

BBEdit text-filters operate on the selection if there is one, otherwise they operate on the whole front document.

Text filters are installed here:

~/Library/Application Support/BBEdit/Text Filters/

Text filters are run from:

BBEdit Menu Bar > Text > Apply Text Filter > <your_filter>

And of course you can give them keyboard shortcuts in BBEdit's Menus & Shortcuts preferences.

--
Best Regards,
Chris

Bill Kochman

unread,
Feb 14, 2017, 3:19:26 AM2/14/17
to bbe...@googlegroups.com
Greetings again,

No doubt this has been asked before, but I probably missed it.

I find it annoying that each time that I open the spell checker under the “Edit” menu, I have to first set it to U.S. English, because by default it is set to British English. Mind you, I have absolutely nothing against British English. In fact, I have read the KJV Bible for 46 years of my life, and I love women with a British accent. :)

But I am an American who reads and writes American English.

I found no way in BBEdit’s prefs to set the default for this option.

Furthermore, even though I set U.S. English as my primary language in the "Language & Region" prefs pane in System Preferences -- and rebooted my computer as was required of me -- and set Apple's built-in dictionary to the Oxford U.S. English dictionary as my default dictionary, it has had no bearing on BBEdit's behavior. It STILL defaults to British English -- even though the spell checker's menu on the bottom says "Automatic by Language” -- and it STILL insists that I use British spelling.

Why is BBEdit behaving like such a renegade? That is only supposed to be for us snarky humans, I do believe. :)

Is there one of those "super secret" BBEdit Terminal commands which will force BBEdit to follow MY command, instead of its own?

I am wondering if this has anything to do with my location and IP address. Is that possibly used by BBEdit to determine which way the language wind blows here? :)

Thanks in advance.

Kind regards,

Bill


Christopher Stone

unread,
Feb 14, 2017, 5:29:31 PM2/14/17
to BBEdit-Talk
On Feb 14, 2017, at 02:19, Bill Kochman <wordwe...@gmail.com> wrote:
Why is BBEdit behaving like such a renegade? That is only supposed to be for us snarky humans, I do believe. :)


Hey Bill,

I just checked my spelling window.  It is well behaved and bringing up the U.S. English dictionary as default.

I'd suggest you escalate this problem to Bare Bones support.

--
Best Regards,
Chris

Bill Kochman

unread,
Feb 14, 2017, 5:43:53 PM2/14/17
to bbe...@googlegroups.com
Hello Chris,

I have two questions for you then:

Are you located in the continental U.S.A.?

If so, do you have “Location Services” enabled in Security & Privacy/Privacy”?

For me, both answers are negative, so I am wondering if that may have something to do with the fact that BBEdit is being such a stinker.

I am sure that Rich or Patrick has probably already read this, and are aware of my inquiry. Well, I would think so, at least. :)

Bill

Rod Buchanan

unread,
Feb 15, 2017, 9:29:15 AM2/15/17
to bbe...@googlegroups.com

Go to 

System Preferences -> Keyboard -> Text

and check the "Spelling:" dropdown.  Mine says "Automatic by Language" and BBEdit behaves as it should.

I am in the US.


--
This is the BBEdit Talk public discussion group. If you have a
feature request or would like to report a problem, please email
"sup...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>
---
You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bbedit+un...@googlegroups.com.
To post to this group, send email to bbe...@googlegroups.com.
Visit this group at https://groups.google.com/group/bbedit.

-- 
Rod


Bill Kochman

unread,
Feb 15, 2017, 9:35:56 AM2/15/17
to bbe...@googlegroups.com
Hello Rod,

Thank you so much! Finally, it works! I had to set it to U.S. English.

So what I have learned from this, is that the preferred language setting in “Language & Region” only sets the language for menus, dialogs, etc.

For actual spelling language — as in for a text editor -- I need to go to Keyboard/Text.

Again, thank you.

Bill Kochman

Bill Kochman

unread,
Feb 24, 2017, 7:04:32 AM2/24/17
to bbe...@googlegroups.com
Hello again.

I don’t know if this is possible or not, but I thought I would ask.

While I obviously realize that Googlebot couldn’t give a hoot regarding how my sitemap.xml file is organized, being a perfectionist, I am.

Thus, I want to organize my sitemap according to my personal liking; that is, with pages with the highest priority at the top, followed in sequence by those with lower priorities.

Furthermore, I want all pages which belong to a particular directory to be listed together as well. In other words, all docs in the “Articles” directory will be grouped together. All docs in the “Poetry” directory will be grouped together. All docs in the “VerseLists” directory will be grouped together. And on and on it goes.

So, to accomplish this, I thought I could use the “Process lines containing” option, and then, using a grep pattern in the file name, lastmod date and priority fields, I could copy all four strings contained in a URL section — in other words, from the opening “<url>” tag to the closing “</url>” tag to a new document.

However, BBEdit does not seem to want to have anything to do with processing a multi-line selection contains three grep patterns.

In short, if I give BBEdit something like this . . .

<url>
<loc>https://www\.billkochman\.com/Articles/(.+?)\.html</loc>
<lastmod>(.+?)</lastmod>
<changefreq>weekly</changefreq>
<priority>(.+?)</priority>
</url>

. . . and ask it to copy all URL sections which meet that criteria to a new document, it does nothing . . . not even an alarm beep saying “You can’t do that!”.

And, yes, I do have the grep box checked in the processing window.

So is there a way to process an entire section of lines like that, and treat it as a whole, or is this an exercise in futility?

Thank you.

Kind regards,

Bill K.

Patrick Woolsey

unread,
Feb 24, 2017, 10:06:45 AM2/24/17
to bbe...@googlegroups.com
By design, BBEdit's line processing commands target whole lines
only since processing partial and/or blocks of lines is (in
general) quite a bit more complicated.

Instead, I recommend you try the "Extract" command (which is
tailor-made for just this sort of task :-) and you can configure
& apply this command in the Find or Multi-File Search windows or
invoke it directly via Search -> Extract.


Regards,

Patrick Woolsey
==
Bare Bones Software, Inc. <http://www.barebones.com/>



On 2/24/17 at 7:04 AM, wordwe...@gmail.com (Bill Kochman) wrote:

[...]

Bill Kochman

unread,
Feb 25, 2017, 2:36:46 AM2/25/17
to bbe...@googlegroups.com
Hello Patrick,

Thanks for the suggestion. I will try the “Extract” option the next time that I have to perform a task like that.

As is, I went ahead and purchased Sheila Dixon’s “Integrity Plus”, which is the commercial version of “Integrity”. Aside from proving to be an excellent website link checker, it also generates sitemaps, and allows the user to set update frequency and priority lives for individual files, or even for whole directories of files. And it has other nice features.

Kind regards,

Bill K.

Oliver Boermans

unread,
Feb 25, 2017, 5:24:07 AM2/25/17
to bbe...@googlegroups.com
Hi Bill,

In BBEdit I would first reformat the XML:

Markup > Utilities > Format 

Select *Mode: Compact* to put all the code on one line.

Then search </url><url>
and replace with </url>\n<url>

 So now each <url> tag is on one line.

This will make the “per line” tools more useful.

Once you are done sorting you could revisit Format.

Cheers
Ollie


--
This is the BBEdit Talk public discussion group. If you have a
feature request or would like to report a problem, please email
"sup...@barebones.com" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>
---
You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bbedit+unsubscribe@googlegroups.com.

Bill Kochman

unread,
Feb 25, 2017, 6:56:35 AM2/25/17
to bbe...@googlegroups.com
Hello Ollie,

Thank you for taking the time to reply.

As I told Patrick earlier today, I already resolved the issue by purchasing a copy of Sheila Dixon’s excellent “integrity Plus” app.

While that issue is now taken care of, I will definitely keep your message archived here, and your point in mind, for any future tasks where it may come in handy.

Thanks again.

Kind regards,

Bill K.
Reply all
Reply to author
Forward
0 new messages