Reply to topic  [ 9 posts ] 
Add Remove Blank Lines 
Author Message

Joined: 2007-09-20 17:58:56
Posts: 179
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 3516 times ]

_________________
iMac 21.5” / MBP 13” Retina
Mac user since 1990
2015-04-02 12:54:48
Profile

Joined: 2014-02-08 12:57:03
Posts: 170
Location: Australia
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


2015-04-02 14:04:35
Profile

Joined: 2007-09-20 17:58:56
Posts: 179
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


2015-04-02 15:21:16
Profile
User avatar

Joined: 2007-02-07 00:58:12
Posts: 876
Location: Japan
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 103 times

_________________
philip
2015-04-02 19:39:09
Profile

Joined: 2007-09-20 17:58:56
Posts: 179
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


2015-04-02 21:54:09
Profile

Joined: 2012-12-19 05:02:52
Posts: 225
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:
# conditional selection
$textExpression = Read Selection
if $textExpression == ''
   prompt "You need to select some text first …"
   exit
End


2015-04-06 05:35:30
Profile

Joined: 2014-02-08 12:57:03
Posts: 170
Location: Australia
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


2015-04-06 17:39:54
Profile

Joined: 2014-02-08 12:57:03
Posts: 170
Location: Australia
G’day, all

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

Code:
# 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


2015-04-07 02:57:57
Profile
User avatar

Joined: 2007-02-07 00:58:12
Posts: 876
Location: Japan
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:
if TextSelection.activeRange.length == 0
            …

Also the "Sleep" command doesn't require quotes for its argument. A number will do fine.

_________________
philip


2015-04-08 00:15:52
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 9 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software