10 Tips for Powerful Emacs on Windows

I avoided using Microsoft Windows for almost 15 years, but with my
new job at a Microsoft-enthralled development shop, those idyllic
days have come to an abrupt end. Because in the past I could always
use my trusty Linux and OS X machines, I never did push past the
hurdles of using Emacs on Windows. My utter reliance on Org-mode,
TRAMP, and Ediff (to name a few) made it essential to get Emacs
working on Windows if at all possible.

Now I am using Emacs on Windows XP and Windows 7 on a daily basis,
and am quite happy with the results. It was not easy to get to the
point of full functionality, so I wanted to share the magic that
makes it all work.

I have decided against using the Cygwin Emacs package for several reasons:

  • Running a windowed/multi-frame/pretty version requires running
    Cygwin-X, which is quite a lot of overhead just to run Emacs. I
    have had a few interface and display problems lately with Cygwin-X
    also.
  • Cool-though-seldom-used features that work in the native port do
    not work in the Cygwin port: Window opacity control, for example
  • Using the native port means I can always be running the latest
    released version from gnu.org
  • The native port just runs faster

On the other hand, Cygwin does play a crucial role in making the
native Emacs port work properly. I have tried and hated using PuTTY
and Plink, and various one-off ports of standard Unix commands.
Using Cygwin and its package management makes all this
much simpler and more reliable.

So all the hints given here use the “official” Emacs for Windows
(sometimes referred to as NTEmacs), as well as Cygwin (with no
dependency on Cygwin-X).

I really hope this helps some poor beleaguered Linux/OS X Emacs user
make the giant backwards leap. With these tips and little helpers like
Launchy, you won’t even have to
acknowledge that you’re running Windows!

Software download links

Here’s where you will find all the software referenced in the tips:

Tip #1: General Usage

  • Execute runemacs.exe or emacsclientw.exe. On your Linux and OS X
    systems, the binary names or emacs and emacsclient: just use the
    windows-specific wrappers included in the standard port when on MS Windows.
  • Add Cygwin /bin to exec-path.
          (if (file-directory-p "c:/cygwin/bin")
          (add-to-list 'exec-path "c:/cygwin/bin"))

Tip #2: Make TRAMP work nicely — and without PuTTY

There are people using PuTTY and Plink.exe to get this working, but
I like using good old OpenSSH much better: no translation required
for the keys I use, and I have it installed anyway in Cygwin.

  • Install Cygwin, including the OpenSSH package
  • In your Emacs init, set shell to bash
          (setq shell-file-name "bash")
          (setq explicit-shell-file-name shell-file-name)
  • In Emacs init, set tramp-default-method to “sshx” or “scpx”
          (cond  ((eq window-system 'w32)
          (setq tramp-default-method "scpx"))
          (t
          (setq tramp-default-method "scpc")))
  • Windows 7 note:   I was unable to get this to work on Win7 until I set the runemacs.exe binary to run in Windows XP (Service Pack 3) compatibility mode.
  • Test: Try M-x shell, then visit a TRAMP site such as /user@site: and try M-x shell from there!

Tip #3: Use SVN and GIT without tears

Version control should work out of the box — but SSH problems can
interfere sometimes. So once you get TRAMP working properly, you
should have no problems with VC.

  • Install subversion and git from Cygwin
  • Use built-in vc-dir, or psvn.el and magit.el

Tip #4: Display images in buffers, including doc-view

You may have noticed that your Windows Emacs has no ability to
display images. This is simply due to the fact that the port is
not distributed with the libraries necessary to display them.

The solution is to visit the GnuWin32 link above, download the
packages relevant to the types of images you want to display
(including zlib1 for compressed images), and copy the DLLs into the
bin directory of your Emacs installation (e.g, C:\Program
Files\emacs23-2\bin).

Images will only be displayed after restarting Emacs.

Here’s a list of DLLs that I now have in my installation:

  • jpeg62.dll
  • libXpm.dll
  • libjpeg-62.dll
  • libpng-bcc.lib
  • libpng.dll.a
  • libpng.la
  • libpng.lib
  • libpng12-0.dll
  • libpng12.def
  • libpng12.dll
  • libpng12.dll.a
  • libpng12.la
  • libtiff3.dll
  • zlib1.dll (for compression, not images)

Tip #5: Use W3M

The W3M web browser works fine once you install the w3m binary –
and once the image display step above is working, you will be able
to display images in the W3M buffers as well.

  • Install w3m from Cygwin
  • Test image display by hitting T (w3m-toggle-inline-images)
  • Example screenshot:
    W3M Browser in Emacs

Tip #6: Bring back Ediff and Smerge

Ediff is yet another thing which doesn’t work as it should. You
will get an error complaining about Dos-style versus Unix-style
paths. Fixing it is a simple matter of setting an environment variable.

  • Assure you have Cygwin’s diff package installed
  • Set the Windows environment variable nodosfilewarning=1
  • Restart Emacs, and verify that the environment variable is set by executing M-x shell, then typing env | grep dos, for example
  • Always, prior to running ediff, execute M-x shell

Tip #7: Spell using ISpell or Aspell

Fortunately very easy to get working by following Brian Wood’s directions using the ISpell package for Cygwin linked above.

Note added later:

Aspell is even easier to use: just install aspell and the correct language(s) in Cygwin, then use the following in your emacs init:

(setq-default ispell-program-name "aspell")

Tip #8: Maximized frame works using maxframe.el

Those of us who practice Distraction-Free Emacsing, or DFE, will
lament the inability to maximize the frame as we can do on other
systems (ie, a true maximized windows, with no OS window
decoration). The solution is provided by maxfame.el, linked above.

After loading maxframe.el, use M-x maximize-frame and M-x restore-frame

Tip #9: Print on PostScript printers

And finally, printing. Even this just didn’t work out of the box
for me. The solution was to use a nice little utility called
GSPrint from the GSView package linked above.

  • Install Ghostscript in Cygwin
  • Install GSView
          (when (and (string= (window-system) "w32") (file-exists-p "c:/Program Files/Ghostgum/gsview/gsprint.exe"))
          (progn
          ;;  Windows printer
          (setq-default ps-lpr-command (expand-file-name "c:/Program Files/Ghostgum/gsview/gsprint.exe"))
          (setq-default ps-printer-name t)
          (setq-default ps-printer-name-option nil)
          (setq ps-lpr-switches '("-query")) ; show printer dialog
          (setq ps-right-header '("/pagenumberstring load" ps-time-stamp-mon-dd-yyyy))))
          (if (eq window-system 'x)
          (setq ps-lpr-command "gtklp"))

Tip #10: Some things Just Work™: Nifty Emacs 23 features that work “out of the box”

Bonus tip — some things work already, no fiddling required!

Select any font you want

  • M-x menu-set-font (choose something lovely like Consolas or Inconsolata … or Comic Sans MS)
  • Example font selection, cross-OS
          ;;* Font selection
          (cond ((or (eq window-system 'mac) (eq window-system 'ns))
          (set-face-font 'default '"-apple-inconsolata-medium-r-normal--16-0-72-72-m-0-iso10646-1"))
          ((eq window-system 'w32)
          (set-face-font 'default '"-outline-Inconsolata-normal-normal-normal-mono-16-*-*-*-c-*-iso8859-1"))
          ((and (eq window-system 'x) (eq emacs-major-version 23))
          (set-face-font 'default '"-unknown-Inconsolata-normal-normal-normal-*-16-*-*-*-m-0-iso10646-1")
          (add-to-list 'default-frame-alist '(font . "-unknown-Inconsolata-normal-normal-normal-*-16-*-*-*-m-0-iso10646-1"))
          )
          ((eq window-system 'x)
          (set-face-font 'default '"10x20")))
     
          (add-hook 'before-make-frame-hook
          (lambda ()
          (set-frame-font "-unknown-Inconsolata-normal-normal-normal-*-16-*-*-*-m-0-iso10646-1")
          ))
  • M-x grep, M-x grep-find, M-x rgrep and friends (as long as
    you have the grep and find commands installed!)
  • M-x tetris, M-x doctor, M-x yow, M-x butterfly

Frame transparency

  • Transparent windows are not my favorite thing, as they tend to
    hamper DFE (see above). But there are occasions, like copying text from a
    web page into an Emacs buffer, where it can come in quite handy.

          (defun set-transparency (alpha-level)
          (interactive "p")
          (message (format "Alpha level passed in: %s" alpha-level))
          (let ((alpha-level (if (< alpha-level 2)
    				(read-number "Opacity percentage: " 85)
    				alpha-level))
    				(myalpha (frame-parameter nil 'alpha)))
    				(set-frame-parameter nil 'alpha alpha-level))
    				(message (format "Alpha level is %d" (frame-parameter nil 'alpha))))
This entry was posted in emacs and tagged , , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

11 Comments

  1. Posted May 23, 2010 at 2:03 pm | Permalink

    You give up on Ubuntu?

  2. Posted May 23, 2010 at 4:51 pm | Permalink

    I never gave up on Ubuntu … I am currently Lucid and will soon be Magnanimous (or whatever). But I must use MSWindows now on a daily basis.

    We should have lunch soon and catch up eh.

  3. Posted May 23, 2010 at 10:09 pm | Permalink

    I too prefer linux/os x as well, but I’m forced to use XP at work too.. the 2 apps I have come to love in my Windows work/development environment (aside from emacs) are 1) XKeymacs and 2) executor

    http://www.cam.hi-ho.ne.jp/oishi/indexen.html

    http://executor.dk/

  4. Posted August 17, 2010 at 4:30 pm | Permalink

    Great tips, but I can’t seem to get aspell to work. Just setting (setq-default ispell-program-name “aspell”) causes emacs to whine thusly: (file-error “Searching for program” “no such file or directory” “spell”)

    Any ideas?

  5. Posted September 7, 2010 at 7:27 pm | Permalink

    Evan: Did you set default-ispell-program-name:
    (setq-default ispell-program-name “aspell”)

    If so, is aspell.exe in your path (check by doing M-x shell RET aspell RET)

    Or, if you don’t want to put it into the PATH, you can add its directory to exec-path

    Hope this helps!

  6. Drew
    Posted October 12, 2010 at 2:12 pm | Permalink

    I recently tried to switch to emacs port to windows. How do you resolve the issue with FIND: Parameter format not correct when using grep, rgrep, etc.

  7. Posted November 11, 2010 at 11:03 am | Permalink

    @Drew: I don’t get that error. The problem is probably that you have the Windows system32 directory in your PATH environment prior to the Cygwin path. So for example, if you have something like

    PATH=C:\WINDOWS\system32;C:\cygwin\bin ….

    You will have the problem. The Windows FIND command is the one giving the parameter complaint.

  8. Drew Wells
    Posted November 11, 2010 at 11:12 am | Permalink

    After much pain and suffering, I decided to go with the GNU WIN32 that packages everything together. I’m a little hesitant to put cygwin commands before windows, because other things may be expecting the windows FIND and get they cygwin one instead. I know, I know this is sort of a cop out and now I’m tied to them, but it has been working very well (almost as well as emacs on Ubuntu).

    I do believe it was a path problem, however when I started hitting cygwin stupid things would break like rgrep. For example, rgrep expects paths like d:/workspace and cygwin expects them /cygdrive/d/workspace. I believe there is a fix for this too, in the end I gave up and uses windows compiled versions of the binaries that came with GNU WIN32.

    Thanks for the tips they were helpful!

  9. Posted December 8, 2010 at 9:06 am | Permalink

    Thanks for all of these tips!

  10. Posted December 8, 2010 at 1:45 pm | Permalink

    hi Greggory,
    I got really excited about your use of tramp in windows (avoiding the emacs cygwin compilation), but unfortunately got no luck with your approach. I’d really love being able to reach the point of working remotely on files tunneled by ssh. with my regular window emacs version (i’m currently using 23.1.91.1) .
    Could you please elaborate a little more on what you do to ssh a file after having set your tramp configs into the .emacs file?
    I don’t quite understand what you mean exactly with “Try M-x shell, then visit a TRAMP site such as /user@site: and try M-x shell from there!”
    Don’t you open it doing C-x C-f? Sorry but I might be missing something pretty obvious here. Thank you in advance for this!
    Ignacio

  11. Posted May 5, 2011 at 7:22 am | Permalink

    Great post! Lots of useful info. I was especially glad to see the tip for printing from Emacs on Windows. I’ve tried various workarounds before, with varying degrees of success/usefulness.

    A tip for those who are trying to use gsprint with Emacs on Windows 7: you will need to force gsprint to use the 64-bit version of gsview; by default, it tries to launch the 32-bit version.

    To see if you’re experiencing the same issue, try running gsprint from a CMD prompt. If you see the message “Failed to exec program c:\{path\to}\gswin32.exe”, read on.

    On my machine, I created a configuration file called gsprint.cfg containing the following two lines:

    -ghostscript
    “C:\Applications\gs\gs9.02\bin\gswin64c.exe”

    This is placed in the same directory as gsprint.exe.

    See documentation at http://pages.cs.wisc.edu/~ghost/gsview/gsprint.htm for more details.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*
  • randy moss combine results
  • tea party zombies download
  • search 78search 800 numbers
  • randy moss bio
  • dis systems
  • archos
  • randy moss yahoo stats
  • roses
  • dis quand reviendras-tu
  • xanadu bengals
  • zara phillips and the queen
  • 4pm cspancspan area 51cspan 90.1
  • freida pinto miral
  • search lsu.edu
  • mtv oddities
  • seagate
  • battleship aurora
  • greg olsen university of miami
  • mtv kings of leon
  • chad ochocinco sisterchad ochocinco twitter
  • tolerance
  • search engines cookiessearch engines definition
  • bonus
  • gears
  • hartmann
  • dis 0 0.9
  • vince young yahoo stats
  • radar
  • beers
  • search 2.0
  • homeless
  • dis boards cruise
  • search engines us
  • chad ochocinco johnson
  • bengals qb situation
  • gregg olsen books
  • zara phillips dating
  • vince young uncle rico gif
  • freida pinto green dress
  • bea luna
  • chicago bears media relations
  • framed
  • la ink 2011 season 5
  • deed
  • battleship vittorio veneto
  • di's hallmark
  • meant
  • chicago bears 61
  • vince young depression
  • cspan hosts
  • ratchet
  • new england patriots gillette stadium
  • chicago bears 08 record
  • chicago bears bleacher report
  • battleship yamato wreck
  • chicago bears training camp
  • la ink corey
  • chicago bears 1985
  • search engines watch
  • search engines questions
  • pendant
  • cspan facebook
  • connecticut renaissance faire
  • battleship egg hunt
  • serenity
  • kilo
  • bangles eternal flame mp3bengals forum
  • prairie
  • afternoon
  • greg olsen vikingsgreg olsen wife
  • springhill
  • tea party birthday
  • vince young quiz
  • bea zuberbühler
  • battleship ipad
  • betty
  • search engines of the world
  • bea 0b0 105
  • dis x
  • chicago bears tattoos
  • greg olsen vancouver
  • hp support 530
  • chicago bears expo
  • quran
  • legend
  • search engines 9
  • 60 search engines virus
  • zara phillips baby
  • freida pinto zac posen
  • connecticut education
  • battleship yamato 2010
  • search vim
  • hp support error 1005
  • pads
  • connecticut post
  • mtv executivesmtv fantasy factory
  • connecticut secretary of state
  • search 990 finder
  • rooster
  • homeowners
  • wein
  • chicago bears 96
  • vince young yahoo stats
  • worst
  • c span yesterdayc span zelaya
  • randy moss jail
  • new england patriots 98.5
  • hp support quick test pro
  • zara phillips baby
  • la ink games online
  • chicago bears pictures
  • chad ochocinco bears
  • zara phillips wedding hat
  • chad ochocinco vs skip bayless
  • chad ochocinco and cheryl burke
  • new england patriots jake locker
  • tijuana
  • hp support englandhp support forum
  • bengals arrests
  • c span video contest
  • mtv dougie
  • new england patriots 80
  • tea party zombies download
  • vince young redskins
  • cspan presidents
  • palma
  • bear gryllsbea hive dance studio
  • zara phillips kids
  • battleship galactica
  • randy moss 98 vikings
  • beagle
  • extending
  • hp support id
  • connecticut 5th district
  • vince young football camp
  • search tumblr
  • la ink cast
  • search 32
  • battleship wilmington nc
  • randy moss 07 08 highlights
  • hose
  • dis pater
  • crimper
  • la ink 03x05
  • mandolin
  • hp support 6500a plus
  • battleship bismarck wreck
  • search engines before google
  • cspan washington correspondents dinner 2011
  • reign
  • chad ochocinco quotes video
  • bea goldfishberg
  • dependency
  • spherical
  • coronado
  • randy moss vikings 2011
  • battleship lexington
  • mtv true life
  • vince young endorsementsvince young foundation
  • hiding
  • search and seizure
  • search engines usage statistics 2010
  • connecticut lottery
  • dressing
  • licensed
  • mtv overdrive
  • tea party nj
  • hp support chat
  • hp support greece
  • connecticut juvenile training schoolconnecticut kids
  • hp support error 1005
  • dis lyrics
  • bea 71 series staples
  • odessey
  • bea test
  • mtv 5 cover
  • new england patriots needs
  • la ink 04x01
  • vince young 99 yard video
  • rotation
  • search operatorssearch people
  • battleship hacked
  • bea verdi
  • zara phillips fascinator