Reply to topic  [ 10 posts ] 
A macro to move a selection after a title 
Author Message

Joined: 2011-05-01 23:38:35
Posts: 12
Sometimes when I write a chapter of a book I feel the need to write down a note (ie todo, question, ...) in the text.
I press return, write the note, assign a style to it (ie "todo" style changes color and font size), I press return and keep writing.
When I reread the chapter I would like to move either all of those notes or a single note under a different heading named Todos

This is my objective:
I would love to be able to create two macros able to (1) move a single selection or (2) all of those todo styled paragraghs right after a heading with a certain name (Todos) (usually at the beginning of the chapter).

I just learned how to select a particular style, but can't get how to move a selection under a styled header (Header2) with a predefined name ("Todos").

Any hints?

Thanks

Francesco


2011-05-05 02:25:00
Profile

Joined: 2007-03-03 09:55:06
Posts: 494
Location: Europe
Hello, Francesco.

I assume that each of your todos is a paragraph. If so, you can append-copy them while you go. Select the paragraph(s) by clicking four times and then right-click and select Append Copy (I don’t know what’s its name in your language). When you’re done with it, go to where you want to gather all your todos and paste.

Cheers, Henry.


2011-05-06 10:54:34
Profile
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
You could also select all those "to do" paragraphs, copy them all at once (NWP will copy a multipart selection), and then paste them wherever you like. Let us know if you have any trouble.


2011-05-06 15:50:32
Profile WWW
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
Oh, I forgot to mention, in case it wasn't apparent, how to select all those paragraphs at once:
1. Place the selection in any paragraph using your "to do" paragraph style.
2. Use the menu Format > Paragraph Style > Select All Style (or the menu from the paragraph style tag).


2011-05-06 15:52:52
Profile WWW

Joined: 2011-05-01 23:38:35
Posts: 12
Hi everybody,

Re: I assume that each of your todos is a paragraph. If so, you can append-copy them while you go...

Thanks Henri for your help. I appreciate the append-copy solution you offered.

Nevertheless that solution would require too much effort on my part :-). I just want to run a macro and it is able to move the current paragraph directly under a styled header (ie header 2) with a predefined name (ie "To Dos"). Or to execute a second macro, that is able to take all of the "some sort of style" (ie "Todo" Styled paragraph) paragraphs and move them under a styled header (ie header2)

Re: Martin - Yes I think this might work. I start working on this: Format > Paragraph Style > Select All Style

I am not sure how a macro can identify the point after a paragraph with style "Header2" and with content "Todos", programmatically. I'll work on that too.

I'll let you know. I'm kind of a rookie with nisus macros... Thanks for you help

Francesco


2011-05-10 08:36:50
Profile
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
cirillof wrote:
I just want to run a macro and it is able to move the current paragraph directly under a styled header (ie header 2) with a predefined name (ie "To Dos").

When you say "predefined name", do you mean that your paragraph's text is "To Dos"? Like the actual text in your document body is typed as "To Dos"? If so, here's a macro that moves the paragraph containing the current selection underneath such a target paragraph:
Code:
Select Paragraph
Cut
If Find Next '^To Dos\n', 'E'
   # paste after the target paragraph
   Select End
   Paste
Else
   # could not find the target paragraph
   Undo
   Prompt 'Could not find a "To Dos" paragraph.'
End

That macro doesn't care what style you have applied to the target paragraph, so long as its text is exactly just "To Dos".


2011-05-11 12:26:42
Profile WWW

Joined: 2011-05-01 23:38:35
Posts: 12
re: When you say "predefined name", do you mean that your paragraph's text is "To Dos"?

correct

Your code is ok and simpler than expected.

Question:

If Find Next '^To Dos\n', 'E'

Is it possible to put a double check:
1 the paragraph = '^To Dos\n'
>> AND <<
>> 2 the paragraph has style "header 2" <<

?

Thanks Martin

Francesco


2011-05-11 14:17:17
Profile
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
Glad to help. As to your question, there are two ways to make sure the target paragraph also has the proper heading style applied.

Here's the explicit way:
Code:
If Find Next '^To Dos\n', 'E'
   If Menu State 'Paragraph Style:Heading 2'
      # paragraph found and in proper heading style
      ...

You could also use an attribute sensitive find expression. You do that by applying the desired attributes to the code in the macro, and adding 'u' to the options string, eg:
Code:
If Find Next '^To Dos\n', 'Eu'

Just be careful that your "Find Next" macro code has only exactly the attributes you want.


2011-05-11 14:53:32
Profile WWW

Joined: 2011-05-01 23:38:35
Posts: 12
Hi Martin,

Yes, "Menu State" works.

Question:
Code:
If Find Next '^To Dos\n', 'Eu'


I am not clear on how to use the attribute to define a particular "style state" in a macro using u.

I took a look at the macro specification but wasn't able to get to how to represent paragraph properties by using "u".

At the same time the idea seems promising even for other macros I would need.

Thanks again.

Francesco


2011-05-11 21:51:54
Profile
Official Nisus Person
User avatar

Joined: 2002-07-11 17:14:10
Posts: 4251
Location: San Diego, CA
cirillof wrote:
I am not clear on how to use the attribute to define a particular "style state" in a macro using u.

The 'u' option turns on the attribute sensitive matching for the whole find expression/pattern (eg: ".+"). So whatever formatting you have applied to the expression in the actual macro code will be used when matching. I'll attach an example macro that does some simple matching that should give you the idea.


Attachments:
SelectExample.nwm [22.48 KiB]
Downloaded 267 times
2011-05-12 09:35:21
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 10 posts ] 

Who is online

Users browsing this forum: No registered users and 4 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