Conditional delete

Discussion, questions and support.
david
Posts: 21
Joined: Jun 1st, ’17, 20:08

Post by david » Jun 22nd, ’18, 01:41

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.
User avatar
Marko
Posts: 1719
Joined: Mar 2nd, ’13, 21:02

Post by Marko » Jun 22nd, ’18, 17:24

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
david
Posts: 21
Joined: Jun 1st, ’17, 20:08

Post by david » Jun 24th, ’18, 23:43

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! :)
User avatar
Marko
Posts: 1719
Joined: Mar 2nd, ’13, 21:02

Post by Marko » Jun 25th, ’18, 16:18

Does this work?
if (clipboard=" ") or (clipboard="`n")
david
Posts: 21
Joined: Jun 1st, ’17, 20:08

Post by david » Jun 25th, ’18, 16:22

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.
User avatar
Marko
Posts: 1719
Joined: Mar 2nd, ’13, 21:02

Post by Marko » Jun 25th, ’18, 17:59

In which editor do you work and what is the purpose of the script?
david
Posts: 21
Joined: Jun 1st, ’17, 20:08

Post by david » Jun 25th, ’18, 19:51

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
User avatar
Marko
Posts: 1719
Joined: Mar 2nd, ’13, 21:02

Post by Marko » Jun 25th, ’18, 20:06

Sorry, I still don't understand. What's your goal? Do you need to edit the whole text by removing blank lines?
david
Posts: 21
Joined: Jun 1st, ’17, 20:08

Post by david » Jun 25th, ’18, 21:03

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.
User avatar
Marko
Posts: 1719
Joined: Mar 2nd, ’13, 21:02

Post by Marko » Jun 26th, ’18, 14:05

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.
Post Reply