What I used to do was, if I got an idea in my head, either a piece of melody or a line of lyrics, I got into a zone where I just let that one snippet go around in my head, repeating itself; I kind of allowed myself to just stay with that one fragment even though it was all I had.
I usually found that eventually if I let it fly around in my head, something else joined the party. The next bit would start evolving out of it, like a root growing a stem, and then the stem grows a leaf, etc.
If I was not at home, I made sure to record it -- before cell phones, I carried a microcassette recorder, and before those, I phoned my home answering machine and hummed the melody or spoke the words into it.
When I got back home to my instruments and recording stuff, I would get my guitar, or keyboard, and start finding a chord that goes with my fragment. Then I would just repeat and repeat, playing and singing, and again more stuff would start coming.
I don't know if this would work all the time for someone else, all I know is it seemed to be how things happened with me. I would wind up with a whole first verse, or a chorus, and then I'd just keep playing over and over what I had so far. I nearly always found that things would just start "growing" out of repeating whatever fragment I had so far.
I think I would also try out other chords to see if the next segment suggested itself out of the random chords I tried. I'm not really sure what would happen -- when I composed a song and it was flowing, I got into a zone where I didn't really know what I was trying or doing, it just kind of emerged.