Windows 環境での Tramp

リモートホストファイルシステムEmacs からアクセスする際には Tramp を使うのが便利です。

Windows 環境で Tramp を使うために、これまで MSYS2 の ssh を使ってきました。この ssh は msys-2.0.dll がリンクされている msys のバイナリであるため path の表記が Emacs のものとは異なります。例えば Emacs から

c:/folderA/folderB

と見える path は ssh でアクセスするには

/c/folderA/folderB

という path にする必要があります。そのため path をコンバートするラッパーを経由させたり .emacs に結構な量のコードを書いたりしなければなりませんでした。

最近、plink が MSYS2 の環境で用意されていることを知りました。インストールするには

$ pacman -S mingw-w64-x86_64-putty
$ pacman -S mingw-w64-x86_64-putty-ssh

とするだけで OK です。puttyplinkEmacs と同じ mingw64 のバイナリなのでパスの表記はもちろん Emacs と同一です。

Emacs から plink 経由で Tramp を使うためには .emacs

(setq tramp-default-method "plink")

と書いておくだけです。

HTML メール

私はメーラーMew を使っています。最近は HTML メールが多いので、.emacs

(when (and (fboundp 'shr-render-region)
           (fboundp 'libxml-parse-html-region))
  (setq mew-prog-text/html 'shr-render-region))

と指定して eww で HTML のレンダリングをさせています。また eww で表示が崩れる場合については C-x C-e でブラウザ (Firefox) で表示するように

(setq mew-prog-text/html-ext
      '("c:/Program Files (x86)/Mozilla Firefox/firefox.exe" ("file:%s")))

を指定しています。

Emacs 25.1 の IME パッチ

私は普段 Windows 7 の MSYS2 環境で作業しています。

エディターは Emacs を使っていますが、IME を使うためにパッチを当ててい ます。Emacs 25.1 がリリースされたので、そのパッチを https://github.com/K-Arakawa/emacs-ime-patch に置いてみました。

.emacs

(cond ((string= (window-system) "w32")
       (setq default-input-method "W32-IME")
       (setq-default w32-ime-mode-line-state-indicator "[--]")
       (setq w32-ime-mode-line-state-indicator-list '("[--]" "[あ]" "[--]"))
       (w32-ime-initialize)
       (require 'smart-ime)
       ;; Register 指定時に IME を OFF にする
       (with-eval-after-load "register"
         (fset 'saved-read-key (symbol-function 'read-key))
         (defun read-key-with-ime-off (&optional prompt)
           (let ((im current-input-method)
                 (key))
             (deactivate-input-method)
             (setq key (saved-read-key prompt))
             (activate-input-method im)
             key))
         (fset 'saved-register-read-with-preview (symbol-function 'register-read-with-preview))
         (defun register-read-with-preview (prompt)
           "Read and return a register name, possibly showing existing registers.
Prompt with the string PROMPT.  If `register-alist' and
`register-preview-delay' are both non-nil, display a window
listing existing registers after `register-preview-delay' seconds.
If `help-char' (or a member of `help-event-list') is pressed,
display such a window regardless."
           (cl-letf (((symbol-function 'read-key)
                      (symbol-function 'read-key-with-ime-off)))
             (saved-register-read-with-preview prompt))))))

と書いておけば OK です。