building a macro to go to the end of line

General questions about using TextPad

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

DA Ward

building a macro to go to the end of line

Post by DA Ward »

This has probably been asked, but I can't find it with any searches of this forum. So here goes:

I'm trying to put the text: objectname.writeline (" at the beginning of every line of a long existing code base, and the text: ") at the end of every line. (I'm not putting quotes around these lines of text because they contain quotes).

It was easy to record a macro to insert the needed text at the beginning of every line, but try as I may, I cannot come up with a keystroke series to go to the end of a line, in order to insert the ending text. Going to a particular column won't work, as these lines are sometimes very long and sometimes very short.

Can anyone help?

Doug Ward
Jens Hollmann

Re: building a macro to go to the end of line

Post by Jens Hollmann »

Try the "End" key?
Carlyle Sutphen

Re: building a macro to go to the end of line

Post by Carlyle Sutphen »

You don't need a macro, you need a search and replace regular expression.

F8
Find what: ^\(.+\)$
Replace with: objectname.writeline ("\1")
Put a check mark by regular expression under Conditions
The caret ancors the regular expression to the line begin. The dollar sign, to the line end. Backslash open parenthesis and backslash close parenthesis "remember" the matched text. A period matches any character and the plus sign means "at least once" so you don't modify empty lines.
mo

Re: building a macro to go to the end of line

Post by mo »

Howdy, that was interesting. I know nothing about these things. Is there one that can find a line or word with x copy in it and delete it and close up the space?

mo
Carlyle Sutphen

Re: building a macro to go to the end of line

Post by Carlyle Sutphen »

If you would give a concrete example of exactly what you want to do, yes.

In the mean time, since you say you know nothing of these things and I assume you would like to, I suggest a bit of reading.

In TextPad help: contents->how to...->find and replace text->use regular expressions

Since that assumes some rudimentary familiarity with REs ...
<b>Kinda basic:</b> http://uk.imdb.com/Help/Classes/Master/expressions
<b>More advanced:</b> http://sitescooper.org/tao_regexps.html
<b>Getting heavy now:</b> http://www.perldoc.com/perl5.6/pod/perlre.html
<b>For javascript:</b> http://www.beginnersjavascript.co.uk/le ... egexp.html
<b>For VB - demo help has tutorial: </b>http://www.aivosto.com/regexpr.html

And there are a lot more out there.

BTW, NT has a command like unix' grep: findstr.exe which will probably also run on win98. It's also in the pay-for version of the win98 reskit:
http://content.techweb.com/winmag/libra ... ea0068.htm
mo

Re: building a macro to go to the end of line

Post by mo »

Yes I would like to learn more and thank you for the suggested reading.

Here are a couple of examples...this particular problem comes up a lot for me it seems.

(Converting a Front Page created website to CSS):

One, Two, Three lines of code, all identical, (useless), preceeding every paragraph. which I would like to strip out and not replace with anything. At this time I can sometimes do this by including in the find and replacing with a piece of code that already exists before the paragraph i.e. <p>. Related issue: Textpad does not seem to want to find lines that carry over to a second line...sometimes it does and sometimes it doesn't ... perhaps this relates to line breaks with spaces?

A certain word used repeatedly that should just be eliminated, not replaced with anything.

Thanks for the help.
I will check out your reading list.

mo
Carlyle Sutphen

Re: building a macro to go to the end of line

Post by Carlyle Sutphen »

Stop using FrontPage if you're just going to rewrite it. It's too much work. Just take a deep breath, clench your teeth together and dive in. Write your pages from scratch with TextPad rather than generating and then modifying them. You'll be glad you did.

This is where you really need to start:
http://www.webreference.com/html/tutorials/
mo

Re: building a macro to go to the end of line

Post by mo »

Hello again...yes I stopped using it a while back but I have a large site that was made with it that is still far from completely rewritten.

Here is another example of this situation I just encountered:

Here's an example I just encountered:

I have a number of lines which read:

<p class="MozPali">muÂÂhassatissa</p>
<p class="MozPali">asampaj¤nassa</p>
<p class="MozPali">Dukkhaµ supati</p>
<p class="MozPali">dukkhaµ paÂibujjhati</p>
<p class="MozPali">p¤pakaµ supinaµ passati</p>
<p class="MozPali">devat¤ na rakkhanti</p>
<p class="MozPali">asuci muccati</p>

I use your regular expression trick to select the line and place new code at the beginning and end:


<p><span class="mozp"><p class="MozPali">muÂÂhassatissa</p></span></p>
<p><span class="mozp"><p class="MozPali">asampaj¤nassa</p></span></p>
<p><span class="mozp"><p class="MozPali">Dukkhaµ supati</p></span></p>
<p><span class="mozp"><p class="MozPali">dukkhaµ paÂibujjhati</p></span></p>
<p><span class="mozp"><p class="MozPali">p¤pakaµ supinaµ passati</p></span></p>
<p><span class="mozp"><p class="MozPali">devat¤ na rakkhanti</p></span></p>
<p><span class="mozp"><p class="MozPali">asuci muccati</p></span></p>

And I end up with a useless bit <p class="MozPali"> and an extra </p>.

How would I set up to delete these useless fragments without replacing them with anything.

(I already suspect you will suggest that the original search and replace have been done a different way...so that is welcome too.)
Carlyle Sutphen

Re: building a macro to go to the end of line

Post by Carlyle Sutphen »

Find what: ^<p class="MozPali">\([^<]+\)</p>$
Replace with: <p><span class="mozp">\1</p>
Study grasshopper.
mo

Re: building a macro to go to the end of line

Post by mo »

Thanks again. The new element there is the square bracket. (by the way, I get the yen symbol for your forward slash...so is the square bracket really a square bracket?)

I still need the secret to deleting without replacing.

I will study, masta, but that comes later in the day for me as I have to balance paying attention to several things at once during the day. I can do editing, I can't do much reading.

mo
Carlyle Sutphen

Re: building a macro to go to the end of line

Post by Carlyle Sutphen »

Where are you seeing the yen symbol? In the browser? In your email program? What operating system are you using? What browser? What locale settings?

Look again at the find and replace strings. It <b><u>is</u></b> "deleting" what you don't specifically tell it to remember. The "memory" is in the form of so called registers, one for each set of \(...\).
Carlyle Sutphen

Re: building a macro to go to the end of line

Post by Carlyle Sutphen »

Oh, btw, you would be surprised how much time you would save by investing it in a little reading. Just open a reference in a window and keep it right there at the ready.
mo

Re: building a macro to go to the end of line

Post by mo »

Please excuse me, sir, for this response to what seems to be a persistant concentration on my manner of doing things. I have told you I appreciate what you have contributed to my knowledge. However you know nothing of how I learn best or what my needs are. There are certain areas where my time is best spent learning just what I need to know and forgetting the rest. For this manner of learning, asking questions of knowledgable persons is a reasonable approach. Repproach me if I ask a question twice in the same way, not for asking questions. This is a forum set up to ask questions, so resentment of questions seems to me to be the erroneous behavior here; directing one's energies towards deflecting questions, belittling remarks and redirecting the energies of questioners seems to be the waste of time here. I am 60 years old, and as it happens most of my life I have been being paid very good money for managing my own and other people's time and money. Additionally, at this time I spend most of my day in educational work and reading. I am no stranger to learning; when I speak of not having time to read the reading you suggest that is a polite way of saying it is largely irrelevant to my needs and mostly directed at instructing me to do what I already know how to do. What I need from this forum is the answers to specific questions.

Finally, by your misdirected paternal instincts, you have created a situation forcing me either to become subserviant to you when such is neither useful nor desirable to me and therefore necessitates a response such as this. The net result of this is that I will find it very uncomfortable to return to this forum. Hense your actions have served neither yourself nor this forum nor me well.

You would be surprised at how thinking about this will improve your life.

mo
Carlyle Sutphen

Re: building a macro to go to the end of line

Post by Carlyle Sutphen »

Mike,

please excuse me for having conveyed the impression that I am resentful of questions. Were that so, I would not participate in such a forum. I have not deflected even one question but answered them, explained how they work and pointed to resources where such information can be gathered quickly and efficiently. The nearest, first and foremost of my suggestions is the help pages delivered with TextPad.

Excuse me, also, for thinking the term grasshopper would be humorous to you. You have confirmed the nagging reservations I have had since having pressed the send button, oh, too hurriedly. It was certainly not my intention to belittle you in the least. My Aunt Martha is in her mid-70's and has been grateful for my tips, pointers and tutoring via email (she's in the US and I am in Germany). I truly respect her and your accomplishments in the face of an increasingly daunting, even for me at 45, exponentially increasing technical complexity.

It is not at all paternal instincts nor a desire for subservience which prompts my seriously well intentioned mentions of the usefulness of self help. I truly believe that keeping the help screen readily available could save much time because there would not be the lapse of time involved in waiting for the question to be read and answered, not to mention the answers which completely miss the target, requiring the question be rephrased and posted anew.

There is nothing in coming to this forum which serves me. The one question which brought me here has gone unanswered. I probably spend far to much time researching and testing before answering. My gain in knowledge is not immediately required and is therfore, by your standards, a waste of time.

Carlyle Sutphen

--
"A human being should be able to change a diaper, plan an invasion, butcher
a hog, conn a ship, design a building, write a sonnet, balance Accounts,
build a wall, set a bone, comfort the dying, take orders, give orders,
cooperate, act alone, solve equations, analyze a new problem, pitch manure,
program a computer, cook a tasty meal, fight efficiently, die gallantly.
Specialization is for insects."

Robert Heinlein
mo

Re: building a macro to go to the end of line

Post by mo »

OK, no hard feelings,don't worry about it, be happy...I'm not saying don't think about it, from long experience teaching, the best way to answer a question is directly, as though you were a hostile witness on the stand. That way you give the person what they asked for and you do not risk giving them more than they wish to hear. I have said and say again I appreciate the answers you have given and I assure you I have kept your reading list and will get to the relevant materials.
Post Reply