Insert Double Square Bracket Macro

Get help using and writing Nisus Writer Pro macros.
Post Reply
User avatar
loulesko
Posts: 124
Joined: 2008-01-20 11:08:35
Location: California
Contact:

Insert Double Square Bracket Macro

Post by loulesko »

Martin posted a macro that converted inline comments, identified as text between double square brackets [[like this]], to comments in the comments section. This changed my life because I prefer to write notes inline as I write. Here's the post: http://nisus.com/forum/viewtopic.php?f= ... ine#p18420

To make the process even more streamline, I wrote a macro that inserts double square brackets and then puts the cursor in the middle of them. And then if you run the macro again, it identifies that the cursor is in front of the closing brackets and pops the cursor to the end and adds a space.

So I can hit the keyboard short cut and instantly have the cursor between [[and]] and then I hit the short cut again [[and]] I'm here. When I'm done writing I run the convert to comments macro and all is good.

My macro also identifies if you've highlighted text and puts [[around highlighted text]] as well.

To make this work I used some code that was written by Kino in another post that moved the cursor left and right. Thanks Kino.

Code: Select all

$value = Read Selection

IF $value

Type Text "[[$value]]"

else

$text = ""

$sel = TextSelection.active

# if you have not reached the end of the text object...
if $sel.bound < $sel.text.length 
   $posRight = Range.new $sel.bound, 2
   TextSelection.setActiveRange $posRight
   $text = Read Selection
end
if $text == "]]"
   Select End 
   Type Text " "
Else
   $origloc = Range.new $sel.location, 0
   TextSelection.setActiveRange $origloc
   Type Text "[[]]"

   # move two characters left
   $sel = TextSelection.active
   if $sel.location > 0  # if you are not in the very beginning of the text object...
      $posLeft = Range.new $sel.location - 2, 0
      TextSelection.setActiveRange $posLeft
end
end

END
Last edited by loulesko on 2011-04-24 14:57:18, edited 2 times in total.
User avatar
xiamenese
Posts: 543
Joined: 2006-12-08 00:46:44
Location: London or Exeter, UK

Re: Insert Double Square Bracket Macro

Post by xiamenese »

Hi Loulesko,

Thanks for posting this. I think I'm going to find it very useful. There is only one thing I personally would like added to it, so if you (or Kino) could point out the way to me (I have never written macros ever in my life and wouldn't know where to start!) I'd be really grateful ... how do I get it to colour the pairs of brackets inserted by the macro and the text between them red? I know I can do it manually, but if it happened automatically, that would be heaven.

Thanks again, even without the red addition.

Mark
User avatar
loulesko
Posts: 124
Joined: 2008-01-20 11:08:35
Location: California
Contact:

Re: Insert Double Square Bracket Macro

Post by loulesko »

Hi xiamenese

Try this.

Code: Select all

#NisusMacroProperty Name: Double Bracket

$value = Read Selection

IF $value
Menu “Text Color:Red”
Type Text "[[$value]]"
Menu “Text Color:Remove Text Color Attribute”

else

$text = ""

$sel = TextSelection.active

# if you have not reached the end of the text object...
if $sel.bound < $sel.text.length 
   $posRight = Range.new $sel.bound, 2
   TextSelection.setActiveRange $posRight
   $text = Read Selection
end
if $text == "]]"
   Select End 
   Menu “Text Color:Remove Text Color Attribute”
   Type Text " "
Else
   $origloc = Range.new $sel.location, 0
   TextSelection.setActiveRange $origloc
   Menu “Text Color:Red”
   Type Text "[[]]"
   Menu “Text Color:Remove Text Color Attribute”

   # move two characters left
   $sel = TextSelection.active
   if $sel.location > 0  # if you are not in the very beginning of the text object...
      $posLeft = Range.new $sel.location - 2, 0
      TextSelection.setActiveRange $posLeft
end
end

END
	
User avatar
xiamenese
Posts: 543
Joined: 2006-12-08 00:46:44
Location: London or Exeter, UK

Re: Insert Double Square Bracket Macro

Post by xiamenese »

Hi Loulesko,

Thanks very much for this ... perfect. Now to see if Keith can set Scrivener to export inline comments with double brackets, rather than single ones, and I'll think I've gone to heaven!

Mark
Post Reply