Add Remove Blank Lines

Get help using and writing Nisus Writer Pro macros.
Post Reply
exegete77
Posts: 180
Joined: 2007-09-20 17:58:56

Add Remove Blank Lines

Post by exegete77 » 2015-04-02 12:54:48

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
Attachments
Screen Shot 2015-04-02 at 13.53.25.png
Screen Shot 2015-04-02 at 13.53.25.png (32.32 KiB) Viewed 4480 times
iMac 21.5” / MBP 13” Retina
Mac user since 1990

adryan
Posts: 178
Joined: 2014-02-08 12:57:03
Location: Australia

Re: Add Remove Blank Lines

Post by adryan » 2015-04-02 14:04:35

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
MacBook Pro (mid-2014)
macOS Sierra 10.12.6
Nisus Writer user since 1996

exegete77
Posts: 180
Joined: 2007-09-20 17:58:56

Re: Add Remove Blank Lines

Post by exegete77 » 2015-04-02 15:21:16

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?
iMac 21.5” / MBP 13” Retina
Mac user since 1990

User avatar
phspaelti
Posts: 916
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Add Remove Blank Lines

Post by phspaelti » 2015-04-02 19:39:09

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:
Attachments
Add or Remove Blank Lines.nwm
(17.59 KiB) Downloaded 119 times
philip

exegete77
Posts: 180
Joined: 2007-09-20 17:58:56

Re: Add Remove Blank Lines

Post by exegete77 » 2015-04-02 21:54:09

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.
iMac 21.5” / MBP 13” Retina
Mac user since 1990

Þorvarður
Posts: 251
Joined: 2012-12-19 05:02:52

Re: Add Remove Blank Lines

Post by Þorvarður » 2015-04-06 05:35:30

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 

adryan
Posts: 178
Joined: 2014-02-08 12:57:03
Location: Australia

Re: Add Remove Blank Lines

Post by adryan » 2015-04-06 17:39:54

G’day, Þorvarður et al

Great idea! I’ll use it. Thanks.

Cheers,
Adrian
MacBook Pro (mid-2014)
macOS Sierra 10.12.6
Nisus Writer user since 1996

adryan
Posts: 178
Joined: 2014-02-08 12:57:03
Location: Australia

Re: Add Remove Blank Lines

Post by adryan » 2015-04-07 02:57:57

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
MacBook Pro (mid-2014)
macOS Sierra 10.12.6
Nisus Writer user since 1996

User avatar
phspaelti
Posts: 916
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Add Remove Blank Lines

Post by phspaelti » 2015-04-08 00:15:52

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.
philip

Post Reply