Reply to topic  [ 4 posts ] 
Insert Double Square Bracket Macro 
Author Message
User avatar

Joined: 2008-01-20 11:08:35
Posts: 89
Location: California
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=17&t=3955&p=18420&hilit=comments+inline#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:
$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.



2011-04-16 14:44:17
Profile WWW

Joined: 2006-12-08 00:46:44
Posts: 416
Location: London or Exeter, UK
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


2011-04-19 03:00:40
Profile
User avatar

Joined: 2008-01-20 11:08:35
Posts: 89
Location: California
Hi xiamenese

Try this.
Code:
#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
   


2011-04-19 09:28:04
Profile WWW

Joined: 2006-12-08 00:46:44
Posts: 416
Location: London or Exeter, UK
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


2011-04-23 00:00:42
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 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