The notion of “flow”, also known colloquially as being “in the zone”, is a state where one just breezes through the task at hand and one is fully focused on the task as subjective time distorts. Part of sports psychology deals with training athletes to get into the zone. One thing that athletes are told to do is ignore the manual details of the sport and focus on their goals. For example, professional golfers perform better when they focus on putting that little white ball in the cup and ignore their swing.
Programmers and musicians can also get in “the zone” (do we have coaches for either?), but I’m not sure if I’ve really been in the zone for either. One of the characteristics of having flow is losing the sense of self. But after what might otherwise being classified as having flow (especially when it comes to music), I often start to notice that I’m doing something (e.g., reading sheet music or just improvising) and then I’m like Wile E. Coyote stepping over a cliff: the horrible reality of gravity sets in and then things suddenly become extremely difficult. The same goes for long walks: sometimes, I suddenly realize that if I stop moving my legs, I won’t ever get to my destination and walking suddenly becomes mentally draining. Was I just on autopilot or did I just leave the zone? And how often do you achieve a state of flow?
It sounds like you left the zone in these cases you describe, and you became mindful. Being mindful is also good, by the way, but perhaps not while you’re trying to program code.
I find it fairly easy to get in flow while programming or writing. But I find it notoriously hard to remain mindful.