Insert List Number . . .
Page 1 of 1

Author:  goldste4 [ 2011-01-23 09:09:43 ]
Post subject:  Insert List Number . . .

Hello All,

I use numbered paragraphs all the time in my lecture writing and find that not infrequently (although I haven't been able to figure out the pattern), when I press return to start a new paragraph the next list number does not appear and I have to manually add it (e.g., Format > List > <list style>; or the equivalent from the list palette).

Now, here is the question: is there a macro that could insert the list number based on the current list style? I already have a number of list styles assigned to keyboard short cuts, but was hoping that there would be a macro with more flexibility than hard coding (so to speak) each list style to a separate key. Any thoughts?


Author:  Kino [ 2011-01-24 04:40:51 ]
Post subject:  Re: Insert List Number . . .

goldste4 wrote:
is there a macro that could insert the list number based on the current list style?
Does this work for you?
Attachment: [4.34 KiB]
Downloaded 304 times
$doc =
if $doc == undefined

$originalSel = $doc.textSelection

if Select Previous List Item
   $style = $doc.textSelection.text.displayAttributesAtIndex($doc.textSelection.location).listStyle
   $doc.setSelection $originalSel
The macro above looks for a list style applied on text before the insertion point and if such a list style is found, it will be applied on the current selection (or insertion point).

Or perhaps are your ‘numbered paragraphs’ defined in the style sheet? Something like posted to Nisus Writer Template forum?

If so, the following macro would be preferable. This macro assumes that a Heading paragraph style is defined for each and every Body Text style: Heading 1 for Body Entry 1, Heading 2 for Body Entry 2 and so on.

When you run the macro...

[1] it gets the paragraph style at the insertion point;

[2] it moves the insertion point to the end of paragraph,

[3] it inserts a newline;

[4a] if the paragraph style got in the first step has $headingBaseName, the same paragraph style will be applied on the new paragraph;

[4b] if the paragraph style has $bodyBaseName AND if the corresponding Heding style exists, the latter will be applied on it.

If your documents have similar pairs of Heading paragraph styles and Body Text paragraph styles, I think you can get the macro below to work for you by customizing the definitions in the first two variables: $headingBaseName and $bodyBaseName.
Attachment: [4.67 KiB]
Downloaded 316 times
$headingBaseName = 'Heading'
$bodyBaseName = 'Body Entry'

$doc =
if $doc == undefined

$nameToStyle =
foreach $style in $doc.paragraphStyles
   if $nameToStyle{$} == undefined
      $nameToStyle{$} = $style

$sel = $doc.textSelection
$styleName = $sel.text.attributesAtIndex($sel.location).paragraphStyleName
$applyStyle = false
$bodyBaseName = '^' & $bodyBaseName
if $styleName.rangeOfString $headingBaseName
   $applyStyle = true
elsif $styleName.findAndReplace($bodyBaseName, $headingBaseName, 'E-i')
   if Defined $nameToStyle{$styleName}
      $applyStyle = true

Send Selector 'moveToEndOfParagraph:'
Send Selector 'insertNewline:'
if $applyStyle == true

Personally I seldom use List styles or paragraph styles in which a List style is embedded. So I may misunderstand what you mean. If none of the macros above fits your needs, please post a sample document here.

Author:  goldste4 [ 2011-01-24 10:13:58 ]
Post subject:  Re: Insert List Number . . .

Hello Kino,
The first of your two macros was exactly what I was looking for!
Much thanks,

Author:  martin [ 2011-01-24 14:53:17 ]
Post subject:  Re: Insert List Number . . .

Thanks to Kino for another macro solution! Though in this case, I'm wondering if it's necessary..
when I press return to start a new paragraph the next list number does not appear

Normally when you press return, the list style will remain applied. I believe the only case where it wouldn't be maintained is if your list style is enforced via your paragraph style, and the return key triggers your "next" paragraph style.

For example, you might have a "Heading 1" paragraph style that enforces the "Numbered List" list style. When you're working in Heading 1, pressing return will trigger the next style, which is likely "Normal", which does not have any list style applied. If you always/often want to continue numbering after pressing return, why not create/assign a next paragraph style that also enforces your list style?

Author:  goldste4 [ 2011-01-24 16:02:44 ]
Post subject:  Re: Insert List Number . . .

Hi Martin,

I don't think that is the problem since I don't embed the list style into the paragraph styles, but rather just use my "normal" paragraph style and apply a list style to it afterwards. (I do this in part because I use a wide variety of unnumbered headings, quotations, etc, all mixed in within my numbered paragraphs, and just find it easier to delete the automatic number when I don't need it than to be applying different styles and having to remember which I'm using now. Also the files are converted from WordPerfect and to get the formatting right after the conversion, I just Select All and then apply the list style I need and delete the automatic numbers on the occasional paragraphs were I don't need them).

In any case, where I most frequently (but, again, it is not consistent) have trouble getting NWP to continue the list after pressing return is when I am editing a paragraph, and hit enter at the end of one paragraph to insert a new numbered paragraph between two existing ones. Sometimes I get the new numbered paragraph, and sometimes just a new un-listed (so to speak) paragraph to which that I then have to add the list style. Sometimes, if I have this problem, if I delete a character or two from end of the previous paragraph and then hit return again the next paragraph will now appear with the list number (and I go back and add the deleted '.' or what not).

Anyway, the problem is frequent enough that Kino's macro is handy (as well as simply for continuing the list after some paragraphs that I don't want as part of the list), but not so frequent that it is terribly annoying (plus the files I'm working on, as I mentioned, were converted from WordPerfect which seems to sometimes introduce general weirdness into things).


Author:  martin [ 2011-01-24 18:02:16 ]
Post subject:  Re: Insert List Number . . .

Hrm, that sounds weird to me Josh, I wonder if there's a bug at work. Could you send/post an example file so I can try and reproduce the list item issue myself?

Author:  goldste4 [ 2011-01-27 19:15:12 ]
Post subject:  Re: Insert List Number . . .


I just wanted to post, for anyone following this thread, that Martin has very kindly cleared up the problem I was having with list styles. I had not understood that NWP interprets any change in paragraph style (i.e., the 'next' paragraph style is different from the current paragraph style) to signal that the automatic list is ending, and so I interpreted the behaviour I was seeing in NWP as inconsistent.

Thanks Martin for the excellent customer service as usual!


Page 1 of 1 All times are UTC - 8 hours
Powered by phpBB® Forum Software © phpBB Group