What tricks do you use to avoid damaging cables when adjusting the gears? I was trying to adjust gears, and being my first time, I ended up damaging the cable. I mean that I "smashed" it, the threads became apart, and it was dangerous to deal with it. I replaced the cable, but I would like to avoid the problem in the future. Is there any trick, apart from being careful? I'm thinking something like coating the cable with a bit of glue. Is it ok?
I put the cable in, find a length that's 'approximate enough', and crimp the cable end onto the cable before I clamp it into the derailleur. This will prevent the end from fraying, like you say, and becoming difficult to deal with. It will get flattened under the derailleur clamp, but this can't be avoided.

If you don't crimp the end in first (or leaving it long is another way, but it doesn't always work), then you will have to deal with the frayed cable and sometimes need to wind it back together to get it into the cable end.