nisus.com
https://www.nisus.com/forum/

Add Remove Blank Lines
https://www.nisus.com/forum/viewtopic.php?f=17&t=6023
Page 1 of 1

Author:  exegete77 [ 2015-04-02 12:54:48 ]
Post subject:  Add Remove Blank Lines

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 3519 times ]

Author:  adryan [ 2015-04-02 14:04:35 ]
Post subject:  Re: Add Remove Blank Lines

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

Author:  exegete77 [ 2015-04-02 15:21:16 ]
Post subject:  Re: Add Remove Blank Lines

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?

Author:  phspaelti [ 2015-04-02 19:39:09 ]
Post subject:  Re: Add Remove Blank Lines

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

Author:  exegete77 [ 2015-04-02 21:54:09 ]
Post subject:  Re: Add Remove Blank Lines

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.

Author:  Þorvarður [ 2015-04-06 05:35:30 ]
Post subject:  Re: Add Remove Blank Lines

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

Author:  adryan [ 2015-04-06 17:39:54 ]
Post subject:  Re: Add Remove Blank Lines

G’day, Þorvarður et al

Great idea! I’ll use it. Thanks.

Cheers,
Adrian

Author:  adryan [ 2015-04-07 02:57:57 ]
Post subject:  Re: Add Remove Blank Lines

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

Author:  phspaelti [ 2015-04-08 00:15:52 ]
Post subject:  Re: Add Remove Blank Lines

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.

Page 1 of 1 All times are UTC - 8 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/