Launch emacs from cygwin

cygwin and emacs logos with love heart in between

I have written about about using emacs in cygwin and how to launch emacs from cygwin, but I had some problems with the batch file approach in that emacs’ path differ from bash’s. Then ack fails to work from within emacs which makes me sad.

After googling around a bit, I saw a few suggestion that trie to fix the path in emacs, but I think a better approach is to launch emacs from within bash so it inherits the bash environment.

Here is my attempt using vbscript:

Dim WinScriptHost
Set WinScriptHost = CreateObject("WScript.Shell")

strCmd = "C:\cygwin\bin\bash --login -c '/usr/local/bin/emacsclient -c -a /usr/local/bin/emacs.exe"

    If WScript.Arguments.Count = 1 Then
        'strCmd = strCmd & " " &"""" & WScript.Arguments(0) & """'" 
		wScript.Echo strCmd
		strCmd = strCmd & "'" 'close single quote
    End If

WinScriptHost.Run strCmd,0 
Set WinScriptHost = Nothing

Save that script somewhere and then make a Windows Shortcut to it but incle the wscript.exe in the target:

C:\Windows\System32\wscript.exe C:\Users\jason\launchemacs1.vbs

You can then launch it from the Start Menu in Windows 7.

Printing from Windows to a samba shared CUPS-PDF printer sometimes fails

cups log with a red error cross on it

I had this problem where prints to our CUPS-PDF printer sometimes failed to be processed on the server. The job would disappear as though it has been printed but nothing else would happen. Printing from the same application to a Windows based PDF printer, and then printing the resulting PDF via Adobe Acrobat to the CUPS PDF printer would work fine. Printing the same PDF via Sumatra PDF to CUPS-PDF would also fail.

Further investigation revealed that the resulting print job files would differ. The jobs that fail looked like they contained a lot of binary data but the ones that succeeded looked like normal PDF files.

Then I discovered this entry in the Windows Event Viewer:

The document XXXX, owned by jason, failed to print on printer \\server\PDF. Try to print the document again, or restart the print spooler.
Data type: NT EMF 1.008. Size of the spool file in bytes: 2555904. Number of bytes printed: 0. Total number of pages in the document: 1. Number of pages printed: 0. Client computer: \\CLIENT. Win32 error code returned by the print processor: 0. The operation completed successfully.

Googleing that error took me to this RPi forum which had a solution buried down near the bottom. Thanks to Chemirocha for that tip. This bug has been plaguing me for a few years on and off!

Windows 7 Visual FoxPro ODBC Driver

Microsoft have made it virtually impossible to find out how to get this driver for Windows 7.

If you are getting the error “You must first install the current version of the Visual FoxPro ODBC Driver”, you need to download this driver and install it.

Tthe file you are after is called VFPODBC.msi and can be downloaded directly from Microsoft at the time of writing. No doubt they will move that link to ensure no one can find it again.

To use it on a 64 bit windows system, you need to run the 32  bit version of ODBC: C:\Windows\SysWOW64\odbcad32.exe

[update 2016-07-20]

or you could download it from here. I’ve tested and it seems to install fine in Windows 10, but I haven’t tested if it works as I don’t use FoxPro any more.


filename md5sum</>
VFPODBC.msi 4fbb57a7efabde9925af86a239e5c93c
VFPODBC.msi.xz aa85ab82c179e4c6b2ee9200b81f8956
filename sha512sum</>
VFPODBC.msi 84aa3f1bf8dd45c7f25575a69b55672b
VFPODBC.msi.xz 97bd6301442320df590f87cde5ffa23f

Free Palestine!

How to make a bootable usb stick in Windows 7 of a debian iso

Every so often I need to make a bootable USB stick in Windows 7 (64 bit) of a debian installer iso. For some reason my googling usually does not reveal a simple solution for this.

I asked on #debian on the OFTC network and got various suggestions. The first suggestions were to use win32 compiled variants of dd or rawwrite. The problem is that there seems to be multiple versions of these tools out there and the ones I tried all seemed to have issues of one sort or another, mostly to do with dd complaining that it would not run on 64 bit Windows. My other issue is that they are command line based. Not that I mind using the command line but it does feel fiddly when all you want to do is get on with writing the image to the USB stick so you can install Debian.

Next I came up with unetbootin. This looks promising and seems to work but it does some very strange rewriting of the boot menus you get on the resulting USB stick. I was confused by the menus when I first saw it and I’m sure novice users would have no idea what to do.

Finally dvs on #debian suggested win32diskimager. This is exactly what I wanted. A point and click solution.

screenshot of win32diskimager
screenshot of win32diskimager

Select the DVD image you want. If the file’s extension is .iso you’ll need to change the filter from *.img;*.IMG to *.* in order to see the file. Then select the Device you want to write to. Hit Write and go and have a cup of tea while it writes the ISO to the USB stick.

installing emacs in cygwin

Update: See my other post, launching emacs from cygwin

There are a few tricks to installing emacs in cygwin. Here’s what I do.

Installing cygwin

First, install cygwin.

Then, install the very nice tool apt-cyg which makes package management much easier in cygwin.

Then to save yourself lots of agony of trying to work out which cygwin packages you need to install to be able to compile emacs, here is the list of all the packages I have installed. It may be a little bit of overkill but it will save you time. I obtained the list like this:

jason@jade ~
$ apt-cyg show | tr '\n' ' '

Install them with:

$ apt-cyg install 
_autorebase _update-info-dir alternatives autoconf autoconf2.1 \
 autoconf2.5 automake automake1.10 automake1.11 automake1.12 \
automake1.4 automake1.5 automake1.6 automake1.7 automake1.8 \
 automake1.9 base-cygwin base-files bash bash-completion bc binutils \
bzip2 ca-certificates cmake coreutils cpio crypt csih curl cvs cvsps \
cygrunsrv cygutils cygwin cygwin-doc dash dbus diffutils dos2unix \
editrights file findutils gamin gawk gcc-tools-epoch1-autoconf \
gcc-tools-epoch1-automake gcc-tools-epoch2-autoconf \
gcc-tools-epoch2-automake gcc4 gcc4-core gcc4-g++ gccmakedep gettext \
gettext-devel git git-completion git-gui git-svn gitk gitk grep groff \
gsettings-desktop-schemas gsettings-desktop-schemas gzip imake \
ipc-utils less libX11_6 libX11_6 libXau6 libXau6 libXdmcp6 libXdmcp6 \
libXext6 libXext6 libXft2 libXft2 libXrender1 libXrender1 libXss1 \
libXss1 libapr1 libapr1 libaprutil1 libaprutil1 libasn1_8 libattr1 \
libblkid1 libbz2_1 libcharset1 libcloog0 libcom_err-devel libcom_err2 \
libcurl-devel libcurl4 libdb4.5 libdb4.5-devel libdb4.5-devel libdb4.8 \
libdb4.8 libdbus1_3 libdbus1_3 libedit0 libedit0 libexpat1 libfam0 \
libfam0 libffi4 libfontconfig1 libfontconfig1 libfreetype6 \
libfreetype6 libgcc1 libgcrypt11 libgdbm4 libgettextpo0 libgettextpo0 \
libggi2 libggi2-display-terminfo libgii1 libgii1 libglib2.0_0 \
libglib2.0_0 libgmp3 libgmpxx4 libgnutls26 libgomp1 libgpg-error0 \
libgssapi3 libhdb9 libhdb9 libheimbase1 libheimntlm0 libhx509_5 \
libiconv libiconv libiconv2 libidn-devel libidn-devel libidn11 \
libintl8 libkadm5clnt7 libkadm5clnt7 libkadm5srv8 libkadm5srv8 \
libkafs0 libkafs0 libkdc2 libkdc2 libkrb5-devel libkrb5-devel \
libkrb5_26 liblzma5 liblzo2_2 libmetalink3 libmpc1 libmpfr1 libmpfr4 \
libncurses-devel libncurses10 libncurses7 libncurses8 libncurses8 \
libncurses9 libncurses9 libncursesw-devel libncursesw10 libneon27 \
libneon27 libopenldap2_3_0 libopenldap2_3_0 libopenldap2_4_2 \
libopenssl098 libopenssl100 libp11-kit0 libpcre0 libpcre1 libpcre1 \
libpopt0 libppl libpq-devel libpq-devel libpq5 libpq5 libproxy1 \
libproxy1 libreadline6 libreadline6 libreadline7 libroken18 libsasl2 \
libsasl2-devel libsasl2-devel libserf0_1 libserf0_1 libserf1_0 \
libserf1_0 libsigsegv2 libsl0 libsl0 libsqlite3_0 libssh2-devel \
libssh2-devel libssh2_1 libssp0 libstdc++6 libstdc++6-devel libtasn1_3 \
libuuid1 libuuid1 libwind0 libwrap0 libxcb1 libxcb1 libxml2 login m4 \
make makedepend makedepend man mintty nano ncurses ncurses-demo \
ncursesw ncursesw-demo openldap-devel openldap-devel openssh openssl \
openssl openssl-devel openssl-devel perl perl-Error \
perl-Locale-gettext perl_vendor python rebase run sed stgit subversion \
subversion subversion-perl subversion-perl tar tcl tcl tcl-tk tcl-tk \
termcap terminfo terminfo-extra terminfo0 terminfo0 terminfo0-extra \
texinfo tzcode unzip util-linux w32api w32api-headers w32api-runtime \
wget which xorg-cf-files xorg-cf-files xz zlib zlib-devel zlib-devel \

Go and have a cup of tea while its installing.

git clone git://
cd emacs
./configure --with-w32 #  to ditch gtk and the concomitant gtk bug, thanks jlf

If make is successful, test the build by running emacs from the src directory:

src/emacs -Q

If that worked ok, you can:

make install

Setting up your home

I like my cygwin home directory to be the same as windows %USERPROFILE% so I set the environment variable HOME=%USERPROFILE%.

Set up a shortcut to launch emacs

Make a shortcut to c:\cygwin\bin\run.exe on your desktop, and rename it to emacs.
Edit the shortcut to:
Target: C:\cygwin\bin\run.exe /usr/local/bin/emacsclient "-c" "-a" "/usr/local/bin/emacs.exe" #

The target part makes sure emacs launches a new window whether or not its already running. If it is already running and as a server, it will create a new frame connected to the server.

The start in part makes sure the new instance’s default-directory is your home directory which I think makes most sense for when you are launching from a shortcut.

Drop the shortcut onto your start menu. You should now be able to launch emacs from the start menu, or by pressing the Windows key and typing emacs.

Flipping the mouse wheel scroll direction in Windows 7

I have been getting very confused between the mouse wheel scroll directions in Windows 7 and Mac OS X Lion. As I consider OS X to be the future, I decided to try and flip the mouse wheel scroll direction in Windows.

Turns out there is a registry setting to do this: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\HID\????\????\Device Parameters

Set the value of FlipFlopWheel to 1

You need to find the USB enumeration values (shown above as ????). You can get those by going to the Mouse Control Panel, click on the hardware tab and click Properties. then in the Details tab of the HID-compliant mouse Properties window, look at the Device Instance Path property. It will be something like: HID\VID_046D&PID_C049&MI_00\7&25DD4DC&0&0000

This is quite well documented on and there is even a link to a little .exe that automates the whole process for you. Although I have not tried it so I can’t vouch for it.

lookup smb windows hostnames from the command prompt in linux

There is this cool way of being able to lookup windows hostnames in linux. Ie so you can ping mywindowshostname and it will just find the ip and ping it.

All you have to do is edit the line in /etc/nsswitch.conf:


hosts: files dns


hosts: files dns wins

and install the winbind service. Thats all there is too it.

locate for windows

I have tried a number for desktop search programs like google desktop search and copernic, but none of them were any good for finding files and thats precicely what I wanted to use them for. I just found this great app, locate for win32. It does exactly what I was looking for. Get it here.