Author Topic: I am looking for commands for handling characters.  (Read 8600 times)

Gardener

  • Community Member
  • Posts: 15
  • Hero Points: 0
I am looking for commands for handling characters.
« on: July 10, 2009, 09:17:35 pm »
Two questions:
1. What is the command for getting the character at the current cursor? I'm sure this is obvious to those that know, but I could not find the command.
2. How do I compare the current character to a string of characters?

Here is pseudo code:

if (current_char = ' ') {
  // delete leading white spaces
  while (current_char = ' ') {
    delete_char();
  }
else
  // delete until a special character
  while (current_char != '():, ') {
    delete_char();
  }
}

hs2

  • Senior Community Member
  • Posts: 2727
  • Hero Points: 281
Re: I am looking for commands for handling characters.
« Reply #1 on: July 10, 2009, 09:34:57 pm »
Just a few snippets:
Code: [Select]
achar := get_text (1); // current char at cursor.

while ( isspace (get_text (1)) )
   delete_char ();

while ( verify (bracechars, get_text (1), 'M') )
   delete_char ();

Some more useful fct.s:
Code: [Select]
get_text_right
get_text_left
linewrap_delete_char
...

Good luck,
HS2

Gardener

  • Community Member
  • Posts: 15
  • Hero Points: 0
Re: I am looking for commands for handling characters.
« Reply #2 on: July 10, 2009, 11:03:32 pm »
Thanks, this looks good. I needed to use linewrap_delete_char because it got stuck at the end of the line.
I want to handle end of line conditions specially. How can I tell if the current character is the EOL? I tried using \n in the character string, but that did not seem to work.

The corner case I'm trying to cover is like this:
Suppose this is my current line

If my cursor is in the middle of the word "line", when I execute the macro, it deletes to the end of the word (as I want), but keeps on going through all linewraps. I would like to stop at the EOL.

Here's my macro:
// DeleteToStopChar deletes white space and non-white space until it hits a stop character
  _command DeleteToStopChar() name_info(','VSARG2_MACRO|VSARG2_MARK|VSARG2_REQUIRES_MDI_EDITORCTL)
{
  _str StopCharacters = '()[]{}.,;: /\n';                     // characters to stop at

  if (isspace(get_text(1) ) )                               // check to see if it is a space
    while (isspace(get_text(1) ) )                          // continue deleting while it is a space
      linewrap_delete_char();                               // delete the space

  else if ( ! verify (StopCharacters, get_text(1), 'M') )   // check to see if it is not a StopCharacter
    while ( ! verify (StopCharacters, get_text(1), 'M') )   // continue deleting while it is not a StopCharacter
      linewrap_delete_char();                               // delete the non StopCharacer

  else
    linewrap_delete_char();                                 // delete the StopCharacter
}

hs2

  • Senior Community Member
  • Posts: 2727
  • Hero Points: 281
Re: I am looking for commands for handling characters.
« Reply #3 on: July 11, 2009, 10:07:25 am »
Sorry .. I don't get it. Do you want to continue with the next line (using linewrap_delete_char) or not (using delete_char) ?
Is the EOL char different to 'end of line' ?
HS2

Gardener

  • Community Member
  • Posts: 15
  • Hero Points: 0
Re: I am looking for commands for handling characters.
« Reply #4 on: July 13, 2009, 03:21:02 pm »
Sorry for not being clear.

I have 2 computers running Slick Edit. I am running the same version of Slick Edit and used the 14.0 feature of exporting the office computer's configuration and importing to the home computer's configurations. Last week, when I started writing and using this macro, I was on my home computer. I am now at my office, trying to use the same macro.

When the last word on the line does not contain a StopCharacter,  using delete_char causes the macro to hang. I figured this was because the macro was programmed to loop on delete_char until it gets to a StopCharacter. Since the EOL (End of Line) was not a StopCharacter, the macro sits there forever. This happens on both computers.

On the home computer, I switched to using linewrap_delete_char, but then when I got to the last word in the line, it deleted to the end of the line and all subsequent blank lines until it got to a line with text in it. This was too much deleting, since I wanted it to stop at the end of the line.
I have now tried this on my office computer, but I don't get the multiple line deletions. As a matter of fact it stops at the end of the line, exactly as I want it.

This makes me think there is a difference between the setup on both computers. Unfortunately, I think not everything about the configurations was transferred. I will try the old technique of copying the configuration folder and see if that makes both computers behave the same. I will have to do this tonight and let you know the results.

FYI: Here is the current version of the macro:
// DeleteToStopChar deletes white space and non-white space until it hits a stop character
  _command DeleteToStopChar() name_info(','VSARG2_MACRO|VSARG2_MARK|VSARG2_REQUIRES_MDI_EDITORCTL)
{
  _str StopCharacters = '()[]{}.,;: /';                     // characters to stop at

  if (isspace(get_text(1) ) ) {                             // check to see if it is a space
    message("Deleted spaces");
    while (isspace(get_text(1) ) )                          // continue deleting while it is a space
      linewrap_delete_char();                               // delete the space
//    delete_char();                                        // delete the space
  }

  else if ( ! verify (StopCharacters, get_text(1), 'M') ) { // check to see if it is not a StopCharacter
    message("Deleted until StopCharacter");
    while ( ! verify (StopCharacters, get_text(1), 'M') )   // continue deleting while it is not a StopCharacter
      linewrap_delete_char();                               // delete the non StopCharacer
//    delete_char();                                        // delete the non StopCharacer - macro hangs at the end of the line
  }

  else {
    message("Deleted single character");
    linewrap_delete_char();                                 // delete the single character
//  delete_char();                                          // delete the single character
  }
}







hs2

  • Senior Community Member
  • Posts: 2727
  • Hero Points: 281
Re: I am looking for commands for handling characters.
« Reply #5 on: July 14, 2009, 01:40:46 am »
@Gardener
You could change the logic of your macro by deleting only known chars or extend the StopChars check to break on EOL:
Example:
Code: [Select]
while ( !verify (StopCharacters, get_text(1), 'M') && !verify ("\n\r", get_text(1), 'M') )
resp.
Code: [Select]
while ( verify (StopCharacters, get_text(1)) && verify ("\n\r", get_text(1)) )
Note that you can omit the 'M' option to verify against 'not matching'.
Try 'help verify' on cmdline or just press 'F1' when the cursor is on the function.

Good luck,
HS2

Gardener

  • Community Member
  • Posts: 15
  • Hero Points: 0
Re: I am looking for commands for handling characters.
« Reply #6 on: July 14, 2009, 05:21:20 pm »
Thanks for the suggestion - good idea. I appreciate you willing to take the time to help.

I was stuck on how to get new line coded. I tried using \n in my StopCharacters string, but it got treated as separate characters: '\' and 'n'.

Can you explain to me or give me a reference as to how Slick Edit treats strings enclosed with ' and ' vs " and "?

By the way: home vs. office. I have copied the 14.0.1 directory from my office computer to my home computer. When I tried the macro at home it behaved differently from the office. Running same versions, with the same 14.0.1 directory, what else needs to be done to get the same behavior?

hs2

  • Senior Community Member
  • Posts: 2727
  • Hero Points: 281
Re: I am looking for commands for handling characters.
« Reply #7 on: July 14, 2009, 07:22:46 pm »
Quote
Can you explain to me or give me a reference as to how Slick Edit treats strings enclosed with ' and ' vs " and "?
Good question... this can only be answered by the real experts - The SlickTeam - I think.
However, in general they show the same behaviour as far as I know.

If the contents of the config dirs is really the same, both installations work exactly the same way.
I'm doing the same sync (home vs. office) since a while and it works as expected.
So where is the difference ? Maybe the 'file under test' is different (line endings) ?

HS2

chrisant

  • Senior Community Member
  • Posts: 1413
  • Hero Points: 131
Re: I am looking for commands for handling characters.
« Reply #8 on: July 14, 2009, 08:07:38 pm »
Single-quote versus double-quote string literals are treated differently.
See Help | Contents, and look in Slick-C Macro Programming Guide \ Language Constructs \ String Literals.

Here is part of the text:

Quote
Double-quoted strings are identical to C++ string literals.

...

If single quotes are used, two single quotes consecutively represent one single quote character. If double quotes are used, a backslash followed by a double quote represents one double quote character. The operator :== used in the example below compares two strings for exact equality. The Slick-C® language does have an operator ==. However, this operator strips leading and trailing spaces and tabs from both operands.

The Help text also has two different tables, one for double-quoted strings and one for single-quoted strings, showing which backslash-escaping characters combinations are recognized by each type of string literal.
« Last Edit: July 14, 2009, 08:31:30 pm by chrisant »

hs2

  • Senior Community Member
  • Posts: 2727
  • Hero Points: 281
Re: I am looking for commands for handling characters.
« Reply #9 on: July 14, 2009, 08:19:11 pm »
Thanks for the valuable refresh chrisant !
I knew that escaping was different but didn't remember the details and where it's documented...
HS2