Page 1 of 2

Conditional delete

Posted: Jun 22nd, ’18, 01:41
by david
Hello!

I have a simple script that helps me format some texts: {End}{Space}{Del}{150}

I would like to know if the {Del} could be done conditionally. For example, if the character that is going to delete is a blank space, proceed, if not, then skip that delete and end, since its the last command. Is there a way to do this condition?

Thanks so much for the help and for such a great software!

Best regards,
David.

Re: Conditional delete

Posted: Jun 22nd, ’18, 17:24
by Marko
Something like this (Type: Command)?

Code: Select all

send {End}{Space}
send +{Right} ;select character on the right
send ^c ;copy it to clipboard
if (clipboard=" ")
	send {Del}
sleep 150

Re: Conditional delete

Posted: Jun 24th, ’18, 23:43
by david
Thanks a lot!

I have seen that I need to check also for space OR newline. So, I tried this, but it's not working:

if (clipboard=" " or clipboard="\n")

Can you kindly suggest what would work?

Thanks again for the help! :)

Re: Conditional delete

Posted: Jun 25th, ’18, 16:18
by Marko
Does this work?
if (clipboard=" ") or (clipboard="`n")

Re: Conditional delete

Posted: Jun 25th, ’18, 16:22
by david
Unfortunately it does not :(

When having a new line, it stops since it does not recognises it correctly and keeps it selected like this: http://share.epiclemon.com/sU6C

What do you suggest?

Thanks a lot for your help.

Re: Conditional delete

Posted: Jun 25th, ’18, 17:59
by Marko
In which editor do you work and what is the purpose of the script?

Re: Conditional delete

Posted: Jun 25th, ’18, 19:51
by david
The program is called Sigil, which is an epub creator. For example, when I select a text like this http://share.epiclemon.com/sXbJ it is pasted like this, so it is really a newline. Don't know why it does not work.

totalidad

del

Re: Conditional delete

Posted: Jun 25th, ’18, 20:06
by Marko
Sorry, I still don't understand. What's your goal? Do you need to edit the whole text by removing blank lines?

Re: Conditional delete

Posted: Jun 25th, ’18, 21:03
by david
I am trying to remove unwanted format from the text. So, for example, this is what I have: http://share.epiclemon.com/sWmS which basically has a newline at the end and added spacing, so I need this: http://share.epiclemon.com/sXRO. Basically what I was doing before is taking that space out by pressing delete and then adding a space. So, this is merely formatting the text.

What I do on my script of fastkeys, the basic one, is just with one key, have fastkeys do end, delete (which deletes the newline character), space. So that I can have what I need. The problem is that sometimes, when doing that with a text that is OK, it deletes a character, because there is no newline, so it does end, delente (real character), space. So, I wanted to improve it so that my script takes into account this special scenario and works fine. The problem here is that the script does not recognises the newline character.

Don't know if I could explain myself now. Let me know if this is clear or if you need for me to record my screen to show exactly what is going on.

Thanks so much for your help.

Re: Conditional delete

Posted: Jun 26th, ’18, 14:05
by Marko
You could remove all blank lines and added spacing in the selected text at once.
For example, create a new Shortcut, Type: Command with the command below. Then select your text and press a shortcut.

Code: Select all

send ^c
sleep 100
text:=Clipboard
newtext:=""
Loop, parse, text, `n,`r
{
	line:=A_LoopField
	line=%line%
	If (line<>"")
		newText.=line "`r`n"
}
clipboard:=newtext
sleep 100
send ^v
return
It could be that your editor handles newlines/line breaks differently so you would need to adjust. If you have text saved in a text file, you could simply change the file content. If the above script doesn't work you can send me your unformatted text file to our support mail.