Insert an incremental number every N occurrances of a search

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
User avatar
tcebob
Posts: 80
Joined: Fri Mar 28, 2003 1:20 am

Insert an incremental number every N occurrances of a search

Post by tcebob »

I have an ever-expanding file of Vlisp program functions. Each function begins with (defun --short for define function. Sometimes I screw around with one or another and, woops, make a mistake or delete something I shouldn't. This file loads every time Autocad starts up. Or tries to but quits at the bad place.

It would be good to insert a numbered print message after every 5 or so functions so the last one executed can be seen on the screen. The following is a start:

Code: Select all

FIND:      (\(defun)
REPLACE: \(princ plcno\)\n\1
As it is it will put the (princ plcno) above the existing (defun. But then I have to go through the whole file and replace plcno with a sequential number. So, 2 questions:

1. Incremental number. I know it's in there somewhere bur right now can't find it.

2. How to find every 5th occurance of (defun?

tcebob
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

1. Incremental number. I know it's in there somewhere bur right now can't find it.
Try these steps:

Configure/Word Wrap Off
Configure/Block Select Mode
Select columns to fill
Edit/Fill Block

======================
Re the xth instance across multiple lines, you may be able to do something with WildEdit and Regex.
Hope this was helpful.............good luck,
Bob
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Re: Insert an incremental number every N occurrances of a se

Post by ben_josephs »

tcebob wrote:1. Incremental number. I know it's in there somewhere bur right now can't find it.
Use \i:
Find what: (\(defun)
Replace with: (princ \i)\n\1

[X] Regular expression
This assumes you are using Posix regular expression syntax:
Configure | Preferences | Editor

[X] Use POSIX regular expression syntax
tcebob wrote:2. How to find every 5th occurence of (defun?
You can only do this in TextPad if the number of newlines between successive defuns is fixed.
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

Once again, thanks to ben_josephs for adding another tool to my TextPad toolbox.

After all this time, I never saw \i before, and it's right there in Help pages.
This isn't even familiar, like I forgot it or something.
Obviously a new function slipped into my computer overnight. :oops:

Every day TextPad gets better and better.
Hope this was helpful.............good luck,
Bob
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Yes, sir, Officer Obie, I cannot tell a lie, I put that function into that computer.
Post Reply