I do three things to write
1. Bash a guitar, with my fingers in different places at different times until I like the sound, then try to remember and reproduce where I put my fingers. Zero logic, zero premeditation, I make a point of trying to forget any theory I know.
2. Bash a guitar and try to reproduce things that resemble sound that happen in my head when I dont happen to have a guitar in my hands to bash. These, for some reason, are often the best.
2.5. Think about parts of the song that I already have and what might happen next when I'm not actually playing. Play it in your head, Write down ideas, play on guitar later.
3. To make a song feel contigious and flow well, when I have a thing resembling a riff, I play it over and over, mutating it by little bits and/or when it feels right to change it, do so and if I like what happens next, thats the next bit of the song, if I dont, back to the riff I have settled on and try again.
3.5 dont stop playing. Breaks can be good, but little fits and starts mean you never really get into it. When you pick up the guitar, sound from it should be as continuous and fluid as possible (imo).