Automatic advance of Left Indent . . .

Get help using and writing Nisus Writer Pro macros.
Post Reply
goldste4
Posts: 98
Joined: 2010-02-22 15:06:48

Automatic advance of Left Indent . . .

Post by goldste4 » 2011-01-11 12:50:23

Hello All,

Is there a way, through a macro, to have the Left Indent (not the First Line Indent) advance one tab stop at a time (using the ruler settings currently active for paragraph at the insertion point)?

This macro would do the same as the Indent button on the toolbar, but without changing the first line of the paragraph.

Thanks in advance for any suggestions.

Josh

Kino
Posts: 400
Joined: 2008-05-17 04:02:32

Re: Automatic advance of Left Indent . . .

Post by Kino » 2011-01-13 10:12:46

Unfortunately no proper command for changing Left Indent is available. We have headIndent as an Attributes Object Property which shows the value of headIndent but does not allow you to change it (i.e. it is not writable as you see in the Macro Reference).

I tried to write a macro changing it by altering the underlying RTF code but could not. Various causes seem to make RTF representation of headIndent different. Handling all those different scenarios is beyond my poor ability, sorry.

Kino

User avatar
martin
Official Nisus Person
Posts: 4251
Joined: 2002-07-11 17:14:10
Location: San Diego, CA
Contact:

Re: Automatic advance of Left Indent . . .

Post by martin » 2011-01-13 14:07:28

Kino is right, there's not a good way to do this in a macro. Parsing the RTF is always ugly and not recommended, and says nothing about Kino's awesome macro wrangling abilities!

goldste4
Posts: 98
Joined: 2010-02-22 15:06:48

Re: Automatic advance of Left Indent . . .

Post by goldste4 » 2011-01-13 14:16:22

Thanks to you both for the response. It looks like I'll just have to make the change manually when I occasionally need to. I was hoping to be able to recreate Wordperfect's hard left indent feature (ol' F7!) which I always found very handy for formatting things on the fly.
Thanks,
Josh

Kino
Posts: 400
Joined: 2008-05-17 04:02:32

Re: Automatic advance of Left Indent . . .

Post by Kino » 2011-02-04 07:03:54

How about this? Instead of changing the amount of hanging indent staying in the same paragraph style, switching to another paragraph style having a larger hanging indent? In the attached rtf file, 21 paragraph styles from Indent 0 to Indent 20 are defined like this.
IndentStyles.png
IndentStyles.png (18.93 KiB) Viewed 5695 times
HangingIndentation_a_rtf.zip
(3.63 KiB) Downloaded 228 times
To switch, for example, from Indent 0 to Indent 1, from Indent 4 to Indent 5, etc., you can use IncreaseNumberedParaStyleLevel macro included in Outline_dot_Macros .zip posted as attachment to my posting here:
http://www.nisus.com/forum/viewtopic.php?p=19028#p19028
Also, you can switch from Indent 5 to Indent 4, from Indent 1 to Indent 0, etc. by running DecreaseNumberedParaStyleLevel macro in the same zip archive.

If this way of editing fits your needs (I’m not very sure), then, you would like to customize those Indent # styles.

 · The macros do not rely on specific paragraph style names. They just switch to a paragraph style of the same base name having a different number (+1 or -1) at the end. Under this condition, any style names are OK.

 · All Indent # styles in the rtf file are based on Indent style (without a number). Changes in Indent style, e.g. amount of first line indent, font size, line spacing, etc., will be reflected in all Indent # styles.

EDIT: I replaced the attached rtf file with a new one. In the older file, irrelevant styles such as Header, Footer, Footnote, etc. were inappropriately based on Indent style.
Last edited by Kino on 2011-02-04 23:55:47, edited 1 time in total.

goldste4
Posts: 98
Joined: 2010-02-22 15:06:48

Re: Automatic advance of Left Indent . . .

Post by goldste4 » 2011-02-04 09:51:31

Hello Kino,

Your suggestion works great and is exactly what I need. Much thanks.

However, there is one important exception. On paragraphs with a list style (I tend to apply list styles to already applied para styles), the indent styles do not seem to have any affect. Once I remove the list style from the paragraph the indent style works. I add a list style, the indent style is there, but its ruler seems to be over ridden. Now, it just occurred to me that is probably exactly what the list styles are supposed to do!

I would like the flexibility of being able to apply any 'indent' style to any list style and level rather than having to encode a particular list style and level into each indent.

Do you know any way around this tension between the indent and list styles?

Again, thanks.
Josh

Kino
Posts: 400
Joined: 2008-05-17 04:02:32

Re: Automatic advance of Left Indent . . .

Post by Kino » 2011-02-04 22:49:12

Is this what are you looking for? Tab stops are used to control tabs within the list items.
NumberListIndent.png
NumberListIndent.png (27.58 KiB) Viewed 5671 times
NumberListIndent_rtf.zip
(4.5 KiB) Downloaded 260 times
In this rtf file, in addition to Indent <number> styles, # Indent 0, # Indent 1 . . . # Indent 21 have been defined, for which IncreaseNumberedParaStyleLevel and DecreaseNumberedParaStyleLevel macros work. (Oup! ugly macro names. Please rename them as you like.)

You can customize those paragraph styles by modifying # Indent paragraph style (without number) and List for # Indent list style on which they are based.

And yet another macro which switches the current paragraph style, for example, from Indent 2 to # Indent 2 or from # Indent 2 to Indent 2.
SwitchParagraphStyle_20110205_nwm.zip
(4.48 KiB) Downloaded 235 times

Code: Select all

stylePair1 = 'Indent'
$stylePair2 = '# Indent'

$doc = Document.active
if $doc == undefined
	exit
end
$sel = $doc.textSelection

$switchParaStyle = Hash.new $stylePair1, $stylePair2, $stylePair2, $stylePair1
$nameToStyle = Hash.new
foreach $style in $doc.paragraphStyles
	if $nameToStyle{$style.name} == undefined
		$nameToStyle{$style.name} = $style
	end
end

$name = $num = ''
$sel.text.attributesAtIndex($sel.location).paragraphStyleName.find '^(?<name>.+\S)(?<num>\s*[0-9]+)$', 'E$'
if $name.length
	if $num.length
		$newParaStyleName = $switchParaStyle{$name} & $num
		if Defined $nameToStyle{$newParaStyleName}
			Push Target Selection $sel
				$nameToStyle{$newParaStyleName}.apply
			Pop Target Selection
		end
	end
end

goldste4
Posts: 98
Joined: 2010-02-22 15:06:48

Re: Automatic advance of Left Indent . . .

Post by goldste4 » 2011-02-05 06:16:39

Hello Kino,

Thanks again, this certainly gets me towards what I was looking for. Unfortunately, I need the #indent styles to work on any level of the list style. Here is an example from (yesterdays!) lecture notes to illustrate what I mean:
NWP Indent Screen Capture 3.jpg
NWP Indent Screen Capture 3.jpg (63.24 KiB) Viewed 5664 times
In this example, I am using indents on the second level of the list style (I've manually moved the left indent marker each time I need it), but I also use it on the first and third (or whatever) levels too. (I've gotten into the habit of formatting the lectures this way because WordPerfect, which I used previously, would allow you to insert a hanging indent code anywhere in the line with one keystroke that would give you this effect).

However, I can only get your otherwise very helpful #indent styles to work on level 1 on the list style and not on any others.

Thanks for all your efforts on this.

Josh

Kino
Posts: 400
Joined: 2008-05-17 04:02:32

Re: Automatic advance of Left Indent . . .

Post by Kino » 2011-02-05 11:26:22

Now I see. I have been wondering how you use hanging indent and why you stick to it. I’d like to have looked at the image — or rather an attached sample document file — in your very first posting. That must have simplified many things.

Anyway, hopefully this one will meet your needs.
IndentedNumberLists_20110206_rtf.zip
(7.86 KiB) Downloaded 219 times
IndentedNumberLists.png
IndentedNumberLists.png (36.1 KiB) Viewed 5656 times
In the attached rtf file, (?:# )?Indent [A-I] - [0-5], i.e. Indent A - 0, Indent A - 1, Indent A - 2, Indent A - 3, Indent A - 4, Indent A - 5, Indent B - 0 . . . Indent I - 5 and their counterparts having a list style, i.e. # Indent A - 0, # Indent A - 1, # Indent A - 2, # Indent A - 3, # Indent A - 4, # Indent A - 5, # Indent B - 0 . . . # Indent I - 5 are defined, for which Increase Numbered Para Style Level and Decrease Numbered Para Style Level macros work.

If ‘Indent . . .’ or ‘# indent . . .’ styles already defined in the rtf file are not sufficient, I think it would not be so difficult for you to add new ones. As you see, in those styles, A-I correspond to List Style’s different Levels and 0-5 to different amounts of hanging indent.

And here is a revised version of Switch Paragraph Style macro posted in my last message on this thread:
SwitchParagraphStyle_20110206_nwm.zip
(4.42 KiB) Downloaded 233 times

Code: Select all

$diff = '# '

$doc = Document.active
if $doc == undefined
	exit
end
$sel = $doc.textSelection

$nameToStyle = Hash.new
foreach $style in $doc.paragraphStyles
	if $nameToStyle{$style.name} == undefined
		$nameToStyle{$style.name} = $style
	end
end

$findDiff = '^' & $diff
$paraStyleName = $sel.text.attributesAtIndex($sel.location).paragraphStyleName
$found = $paraStyleName.find($findDiff, 'E-i')

if Defined $found
	$range = Range.new 0, $diff.length
	$paraStyleName.deleteInRange $range
else
	$paraStyleName = $diff & $paraStyleName
end

if Defined $nameToStyle{$paraStyleName}
	Push Target Selection $sel
		$nameToStyle{$paraStyleName}.apply
	Pop Target Selection
end
EDIT: Fixed typos.

Post Reply