Page 1 of 1

Add Remove Blank Lines

Posted: 2015-04-02 12:54:48
by exegete77
When I tried to run the macro, I receive an error message (see attachment).

In previous versions of NWP I have been able to use it. Has the macro been modified in the last 2 years? IS there an updated macro?

Thanks

Re: Add Remove Blank Lines

Posted: 2015-04-02 14:04:35
by adryan
G’day, exegete77 et al

On my system, the current version of the Add or Remove Blank Lines macro is a .nwm file rather than a .pl one:–

$count = Find and Replace ‘\n\n+’, ‘\n’, ‘Eas’
If 0 == $count
Find and Replace ‘\n’, ‘\n\n’, ‘Eas’
End

It works fine when adding or removing blank lines, but one has to remember that it works only on a selection rather than on a whole (non-selected) document. It’s best to include the word “selection” or some other such mnemonic in the macro’s filename in such cases, to avoid the frustration of wondering why nothing happened when the macro was called.

These days, there are very few Perl macros in the Nisus-supplied set. For the record, I invoked one with no problem.

Cheers,
Adrian

Re: Add Remove Blank Lines

Posted: 2015-04-02 15:21:16
by exegete77
Thanks. I cleaned all those pl macros. But I can’t find the Add Remove Blank Lines macro on the NWP web site. Can you post it here?

Re: Add Remove Blank Lines

Posted: 2015-04-02 19:39:09
by phspaelti
I'm not sure that it should really have been necessary to clear out the Perl macros. The Perl version works fine for me (I'm using 2.1.1.beta).
That having been said, there is really no point to that macro being a Perl macro as it consists entirely of Nisus Macro code! The code is exactly as adryan says.
I'm posting it here as a file:

Re: Add Remove Blank Lines

Posted: 2015-04-02 21:54:09
by exegete77
Thanks, Phillip. Downloaded and worked as previously. I did notice a few others NWP asked about updating. So perhaps my macros were a bit out of date.

Re: Add Remove Blank Lines

Posted: 2015-04-06 05:35:30
by Þorvarður
adryan wrote:one has to remember that it works only on a selection rather than on a whole (non-selected) document. It’s best to include the word “selection” or some other such mnemonic in the macro’s filename in such cases, to avoid the frustration of wondering why nothing happened when the macro was called.
In such cases I always start macros with a conditional selection:

Code: Select all

# conditional selection
$textExpression = Read Selection
if $textExpression == ''
	prompt "You need to select some text first …"
	exit
End 

Re: Add Remove Blank Lines

Posted: 2015-04-06 17:39:54
by adryan
G’day, Þorvarður et al

Great idea! I’ll use it. Thanks.

Cheers,
Adrian

Re: Add Remove Blank Lines

Posted: 2015-04-07 02:57:57
by adryan
G’day, all

Actually, I’ve made what I think is an improvement:–

Code: Select all

# Ensure something is selected.

$textExpression = Read Selection

If $textExpression == ''
$proceed = Prompt "You need to select some text first…", '', 'OK, I will.'
If $proceed == 'OK, I will.'
	While $textExpression == ''
		Sleep '1'
		$textExpression = Read Selection
	End
End
End
This means that the macro doesn’t abort and then have to be invoked again if you failed to present it with a selection the first time around. It just waits for you to make your selection and then executes any subsequent code.

Cheers,
Adrian

Re: Add Remove Blank Lines

Posted: 2015-04-08 00:15:52
by phspaelti
adryan wrote:Actually, I’ve made what I think is an improvement:–
Cute trick!

I just thought I'd mention that you don't really need to use the "Read Selection" command. (Don't know if that command is wasteful or not, but it feels like overkill.)
There are a number of ways you could check for no selection, for example:

Code: Select all

if TextSelection.activeRange.length == 0
            …
Also the "Sleep" command doesn't require quotes for its argument. A number will do fine.