Solutions to Some Emacs Problems

I’ve been using Emacs exclusively for a couple of years, on both Windows and Mac machines. Prior to that I had used it intermittently, mainly on Unix machines, for over 20 years.

In setting up and customizing Emacs I’ve hit a few Emacs problems whose solutions were not easily found on the web. I’m listing my solutions here in the hope that others will find them useful. The issues covered here are very specific. I’ll be writing about aspects of Emacs of more general interest in the future.

Copy and Paste Problems on Mac

I encountered an intermittent problem on the Mac, originally when exporting from Org mode, giving the strange error

"quit: pasteboard doesn't contain valid data"

This error was then produced every time I did a kill (copy) or yank (paste). Pasting anything from another app (say Firefox) seemed to cure the problem, at least for a while. I eventually tracked the problem down to this configuration line that I’d put in my .emacs:

(setq save-interprogram-paste-before-kill nil)

Making that code execute only when Emacs is running under Windows cured the problem.

Executables

On Windows I had trouble getting Emacs to find the git executable, despite the relevant directory being on the exec-path. In the end I had to set, in my .emacs,

(custom-set-variables
...
 '(magit-git-executable "c:\\program files (x86)\\git\\bin\\git.exe")
 '(vc-git-program "c:\\program files (x86)\\git\\bin\\git.exe")
...)

I run git from magit; the second of those lines is needed for vc-annotate.

System Name

In my .emacs I set the Emacs window size based on the system-name variable, as I want a different window size for a laptop versus a large desktop screen. When travelling I’ve found that the window on my MacBook Pro sometimes opens too large and looks very strange, with a missing top line of the window. It seems that being on different wireless networks can change the value of system-name. I have not found a solution, other than to resize the window with the mouse when Emacs starts.

Take Command Shell

On Windows, I use the excellent Take Command shell instead of the CMD shell that comes with Windows. In order to get LaTeX to work as I wanted I needed to tell Emacs to use this shell:

(setq TeX-shell "d:/tcmd/tcc.exe")