Macros and spaces at the end of a line

I have become used to using the macro feature a lot.

One of the things which makes recording macros difficult is that lines may have trailing spaces.
Pressing the END button will put the cursor after these spaces, not afte the last word.

For example, suppose I have a number of lines with field names, and I wish to convert these into variables.

I would do this by recording a macro:
I would press END to put the cursor at the end of the line, thenpress SHIFS+LEFT to select the fieldname and press CRTL-C to copy it.
Move the cursor to the beginning of the field name, and prefix it with e.g. "v_".
Then move to the beginning of the line, and move to e.g colomn 30 by presisng RIGTH 30 times.
Then type the tablename + ".", then press CTRL-V to insert the fieldname and finally type "%type".

I can then repeat this macro as many time as I want to declare multiple variables.
I could declare variables for all fieldnames in a table, very quickly.

All of this is very handy.
But is the line have spaces at the end, then the first step pressing END + SHIFT-LEF will select the last word + trailing spaces. That wont do.

So in these cases I use another tool to prepare the file by removing all trailing spaces in the file, then reload the file.
After that my macro mechanism works fine.

Similarly if I press SHIFT-RIGHT the next word will be selected, including trailing spaces.
This is why I am required to work from the end of the line, and not begin from the start of a line.

To sum it up: fantastic to have a macro recording tool. Unfortunately the way the editor handles spaces makes recording a macro difficult.

Possible solution: could the editor be capable of automatically removing traling spaces on a line, such as e.g. the Delphi editor does?

(Note; I sometimes copy text from another editor into PLSQL developer, just so I can use the macro mechanism. Great tool! )
 
I am pretty sure that it has been asked for before, so it should be on the list of things to do.

It is quite possible to do, I have even thought of making a plug-in for just that purpose. You could include it as the first thing in your macro.

Does anyone have any idea if there is a reason NOT to strip trailing spaces from every line in the editor?
 
@Scott: Does anyone have any idea if there is a reason NOT to strip trailing spaces from every line in the editor?

Not for the source code files. It may be useful to keep trailing spaces for template/layout/data files, but I'm not sure if anyone edit them in PL/SQL Developer.

Ultra-Edit has option "Trim trailing spaces on Save" and menu command to trim those as well.
 
Trailing spaces can be siginificant in multi-line strings, so a "trim" function would have to parse the PL/SQL to ensure that these strings are untouched. It can be done of course, and like Scott says, it's on the list.
 
How about either

- only stripping trailing blanks from the lines selected in the editor before the command is called

or

- a new end-of-line command that on execution does

if end-of-line
then
find last non-blank of line
else
find end-of-line
end if;

???????????
 
If anyone is interested in trying it out, the BETAs of my new Begin-Of-Line and End-Of-Line plugins are ready for trial.

Put the plugin in your plugin directory, use Tools / Preferences / User Interface / Key Configuration to assign "End" to "Edit / End-Of-Line" and "Home" to "Edit / Begin-Of_Line" (say Yes when it warns that that key is already in use).

In Macros press End once to go to the absolute end of the line (after all chars, even spaces), press End again to go to the first spot AFTER the last non-blank char on the line. Press Home to go to column 1 and press it again to go to the first non-blank character of the line.

Operators are standing by to answer your calls.
 
Marco,
How do I create a plugin that adds new command and NOT have it show up in any of the menus? If there is a way, how do we assign the new command to a key if it isn't in any menu?

Also, it would be nice to be able to get just the line that the cursor is on, without having to have the line selected.

Thank you.
 
How do I create a plugin that adds new command and NOT have it show up in any of the menus?
I don't think that is possible. I will double-check though.
Also, it would be nice to be able to get just the line that the cursor is on, without having to have the line selected.
That is possible with the standard Windows message functions.
If anyone is interested in trying it out, the BETAs of my new Begin-Of-Line and End-Of-Line plugins are ready for trial.
If you could send it to me, that would be great.
Operators are standing by to answer your calls.
:)
 
I have forgotten anything I use to know about using Windows messages to get work done. Is it something simple (as in, do you have an example)?

I have sent you the dlls just now. They are still beta, so please don't put them on the download page (I want to tidy their insides up).
 
I have forgotten anything I use to know about using Windows messages to get work done. Is it something simple (as in, do you have an example)?
I think it should work like this:
  • Use EM_GETSEL to determine the cursor position
  • Use EM_LINEFROMCHAR to determine the line number of that position
  • Use EM_GETLINE to get the text of that line

I have sent you the dlls just now. They are still beta, so please don't put them on the download page (I want to tidy their insides up).
Got it.
 
Marco,
Thank you.

The plugin doc says tht ide_geteditorhandle returns integer, but at compile Delphi complains that

Code:
edithandle : integer;

begin

edithandle := ide_geteditorhandle; <== incompatible types integer and pchar
so I change it to
Code:
edithandle : pchar;
the_line : string;

begin

edithandle := ide_geteditorhandle;

sendmessage( edithandle, em_getline, line_num, the_line );
 
I think you have incorrectly declared IDE_GetEditorHandle. It returns an integer, which is the handle. It does not return a PChar.
 
You can trim trailing spaces by using the "Regular expression" option on search and replace page. Type in the "Text to find" box:
[][]*$

Hit "replace all", it will remove all the white spaces.
 
Thank you. Will this work in a macro, or must it be a separate step before running the macro?

Also, be careful with lines like Marco mentioned in his post of 2006-05-18 15:19
 
Back
Top