Home About Archive RSS

More on Emacs on Windows

Today, I spent some time configuring (native) Emacs on Windows again. I needed to clean up some configuration around kalender.el, my Norwegian Bokmål calendar. Once I was working on it, I also improved my configuration around a few other issues plaguing native Emacs on Windows.

One thing I looked at was dictionary mode. (Notice that Emacs uses different facilities for dictionary-lookup and spell-checking.) On my GNU/Linux systems, I install a dictd server and some dictionaries so I don't need to be connected to the internet to use dictionary-lookup-definition. Since there is no dictd server package for Windows, I first tried to use dict.org to look up words. When I tried dictionary-lookup-definition, Emacs just froze. It did not use a lot of CPU, but it just did not respond do anything, including C-g. I had to kill it with the three-finger salute (C-M-d).

The main network at work is very locked down, so blocked ports could be the reason it doesn't work. Since I teach programming and basic IT, we need a network where we can do things like SSH which we cannot on the main network, so IT has supplied another network for that purpose, but I only have access to that network in the classrooms I teach, not at my desk, so I could not test doing it on another network. I don't have time to lookup word definitions when I am in a classroom, so either it works on the main network, or I consider it a feature I cannot use on Windows, which is what I do in my config now. Maybe I could add some code to check if the relevant network ports are open before trying a dictionary-lookup by advising the function that does the lookup or using a hook and keep the feature enabled so I can potentially use it when I am on other networks if I find out that the network is the problem? I would have to look a bit further into it.

I have previously determined that there is no aspell-no available on chocolatey or msys2 that I can install, and that makes spell checking also non-functional for me on Windows. My working language is Norwegian Bokmål, so even if I also write some English from time to time, and could use aspell-en and just set it to English on Windows, that would give me a lot of false positives most of the time. On GNU/Linux, I set it to nb (Norwegian Bokmål) and change manually to british (English) when needed. Maybe I could make a toggle function that would toggle language on GNU/Linux and toggle on/off on Windows? This needs a bit more investigation.

I have had a change of heart concerning which shell to use in Shell Mode. Even though Bash from Git Bash in Shell mode works, sometimes I actually need to use PowerShell to configure WSL2, Hyper-V or the like. Since I like to have as few windows open as possible since Windows ironically is terrible at handling windows, it makes more sense to use PowerShell in shell mode and stay within Emacs instead of launching a new window. (Some people think window snapping solves the inefficiencies of a floating window manager or desktop environment, but it doesn't since you have to do it manually with a keyboard shortcut or even more inefficiently by mousing around and dragging the windows to the edges. A tiling WM does it automatically which saves time and interruptions from flow. With very conservative numbers, I have calculated that I could save 3 work days during a 190 day school year if I used a tiler at work instead of the floater in Windows 11. I have dual-booted to get both the efficiencies of a tiler and access to all free software (development) tools I use for months, but since I need some tools inside Windows to do parts of my work, it makes sense to try to solve the problems in Windows instead of fighting it. WSLg would be sweet if it actually worked…)

Another reason is that Eshell provides a good shell experience that just works on any operating system, and I have thought that I would look into it more for some time, so I decided to use Eshell for everything I would use shell mode for up to this point and have PowerShell in shell mode in Windows for Windows-specific tasks. Eshell is nice because it, like shell mode, is an Emacs buffer that behaves like a normal buffer. Both Eshell and Shell mode have trouble with ncurses and other TUI programs, but Eshell is a bit cleverer than shell mode in that it can use a terminal package like ansi-term or eat to draw up those programs without leaving Eshell, so it is a better solution for all kinds of shell programs than shell mode which only does non-TUI CLI programs. It is also a better solution than ansi-term or other terminal packages that behaves like standalone terminal emulators and not ordinary Emacs buffers, with all the extra context-switching that adds, like Shift-Insert instead of C-y and C-c M-x instead of just M-x etc. It also integrates well with the rest of Emacs and you can use Elisp functions as well as traditional Unix shell commands (which are implemented in Elisp in Eshell so no external shell is needed). I am looking forward to getting to know Eshell better.

Another thing I looked into today was killing and yanking (or copying and pasting) on Windows. I have set Emacs to use UTF-8 and Unix line endings, but Windows still uses a 90s style non-UTF-8 text encoding based on its locale, so when I copied some Norwegian text today, all Æ, Ø, Å, æ, ø, å charcters got other glyphs once yanked into Emacs. I found out that I could just give the function set-clipboard-coding-system a text-encoding as a parameter and this problem would disappear. The documentation I found was out of date and said I should use utf-16le which did not work at all. After a bit of trial and error with the config file, I found that iso-latin-1 worked. I set this in the same section of my config as I set UTF-8 with Unix line ending to be default.

© Einar Mostad 2010 - 2025. Content is licensed under the terms of CC BY SA except code which is GNU GPL v3 or later.