In addition to planning your day, tidying things up, and just plain leaving early (to make up for staying late other times), let me suggest something that probably seems very counter-intuitive:
Try to avoid stopping at a "natural stopping point"
You worry that if you get half an hour into a coding task, you'll find it hard to load up context when you get back to it the next day. But my experience is precisely the opposite. Say you are going to write a simple function. You know there will be some initialization, a loop to process all the X in the Y, and some cleanup. I will literally add the file to my project, declare the function, add three comments (maybe writing the for or while construct around one of them) and then -- go home.
In the morning, when you get in, you don't need to remember what you were doing or consult your notes -- it's all right there for you. Why go home with an empty file, or a blank sheet of paper, waiting for you in the morning? Instead, at least write a title or a subject line. At least write the name of the function. If you're supposed to write a document, make the folder, create an empty document with the right name, and put the title of the document at the top of the first page. Apply a style sheet.
Get started. Then leave. You may be VERY pleasantly surprised -- it is much easier to get started if you didn't stop at a natural stopping point. Launching off from these points is super easy.
In fact, it's so easy that I sometimes use a variant of this to trick myself into working on something I don't want to work on. I just do the "get started" part - making the new project or empty folder or whatever. Making a file called outline and pasting in the outline from email. Downloading the spec or release notes. Finding the link to that video I need to watch. None of this really counts as working on the thing I don't want to work on, it's just the getting started stuff that would enable me to actually work on it, so I do these tasks without resistance. And then I find, when I've done them, that my resistance falls away and I'm able to do the task itself.
Try it.