Windows 10

How to get up and running with Python in Emacs

I did some programming in Python many years ago (around 2001), but haven’t touched it since, though I always thought I would come back to it at some point. Today, I finally got around to installing and testing it a little.

The python installation on Windows 10 was impressively easy (get it at python.org). I had it up an running in the REPL (or the IDLE, as it is called in the case of Python) almost immediately. Writing a new script is as easy as opening a new file using the standard top menu, and pressing F5 to run it in the REPL. Wonderful. Now to get it working in Emacs.

A little bit of searching indicates there is lots of relatively advanced information available, but all I wanted at this point was a quick and simple way to get a REPL with python running in Emacs. How to do this was not obvious, but in the end this too turned out to be easy.

Running python:

  • Open a Python shell in Emacs: C-c C-z
    Note: When I installed Python, I made sure to add python to the environment variables. I’m assuming this is why this worked so easily. Apparently, support for python mode (python.el) is included from emacs24 and onwards, and once pythons was installed on my system, nothing more was needed for Emacs to find and run it.

  • Run a Python script: C-c C-c
  • This assumes the file is open in Emacs, and that a python shell is running.

  • Run a selected region of a loaded script: C-c C-r

    …And that’s basically it. You should now be able to open a file. write Python code in it, and compile it in the REPL, as well as enter Python commands directly in the REPL.

How to switch desktops when Hyper V steals your focus

I currently run Windows 10 as my main OS, yet I often run Windows 8.1 in a virtual machine under Hyper V to work on a project no longer supported in Windows 10. This is quite practical now that multiple desktops are supported out of the box: I typically run Windows 8.1 in full screen on a separate desktop, so it does not interfere with my other desktop(s).

Tip: In Windows 10, press the Windows key + Ctrl + D to create and switch to a new desktop. Hold down Ctrl and the Windows button while pressing the right or left arrow to switch between desktops. You can also use win + Tab, and click the desktop-icons at the bottom of the screen to switch between them.

One thing I found annoying was the difficulty of switching away from Hyper V and Windows 8.1, since the virtual machine will typically steal the focus. I’ve found a relatively simple solution now though: When the focus is in Hyper V, Ctrl + Alt + Left arrow will move it out and into the outer context – in my case away from my virtual Windows 8.1 machine, and back out to Windows 10. This shortcut is probably not new, but I was unaware of it until recently.

In short:

  • To move from a regular Windows 10 desktop and right into a full screen windows 8.1 desktop, I’ll use: Ctrl + Windows + arrow key.
  • To move back out from Windows 8.1, I’ll first press Ctrl + Alt + left arrow, followed by Ctrl + Windows + arrow key.

This may sound a little awkward, but I’ve found it surprisingly easy to get used to, and as far as I can tell, this appears to be the easiest way to escape from a VM.