Emacsサーバのセットアップ
Emcasのサーバを利用するためのセットアップを行いました。
まず、以下の環境変数を登録します。
HOME=d:\home ALTERNATE_EDITOR=%HOME%\emacs\bin\runemacs.exe EMACS_SERVER_FILE=%HOME%\.emacs.d\server\server
.emacsに以下の行を追加します。
(server-start)
emacsを起動するとエラーがでました。
Warning (initialization): An error occurred while loading `d:/home/.emacs': error: The directory d:/home/.emacs.d/server is unsafe To ensure normal operation, you should investigate and remove the cause of the error in your initialization file. Start Emacs with the `--debug-init' option to view a complete error backtrace.
unsafeとあるので、権限関係なのでしょうか?
とりあえず、メッセージに記述がある通り、--debug-initで再度emacsを起動しました。
以下のトレースバックが表示されました。
Debugger entered--Lisp error: (error "The directory d:/home/.emacs.d/server is unsafe") signal(error ("The directory d:/home/.emacs.d/server is unsafe")) error("The directory %s is unsafe" "d:/home/.emacs.d/server") server-ensure-safe-dir("d:\\home\\.emacs.d\\server\\") server-start() eval-buffer(#<buffer *load*> nil "d:/home/.emacs" nil t) ; Reading at buffer position 3225 load-with-code-conversion("d:/home/.emacs" "d:/home/.emacs" t t) ... ... ...
server.elの以下の関数でエラーがとなっているようです。
(defun server-ensure-safe-dir (dir) "Make sure DIR is a directory with no race-condition issues. Creates the directory if necessary and makes sure: - there's no symlink involved - it's owned by us - it's not readable/writable by anybody else." (setq dir (directory-file-name dir)) (let ((attrs (file-attributes dir))) (unless attrs (letf (((default-file-modes) ?\700)) (make-directory dir t)) (setq attrs (file-attributes dir))) ;; Check that it's safe for use. (unless (and (eq t (car attrs)) (eql (nth 2 attrs) (user-uid)) (or (eq system-type 'windows-nt) (zerop (logand ?\077 (file-modes dir))))) (error "The directory %s is unsafe" dir))))
関数を評価しながら確認したところ、以下の部分でチェックに引っかかっていました。
(eql (nth 2 attrs) (user-uid))
EMACS_SERVER_FILEでしていたserverディレクトリの権限ユーザがuser-uidとは違うようです。
そこで、このserverフォルダの権限を確認したところ、ログオンしているユーザではなくグループが登録されていました。一旦、フォルダのユーザをすべて削除して、ログオンユーザを登録しました。その後、emacsを起動するとエラーが出ずに起動しました。
あとは、コンテキストメニューの右クリックでEmacs編集メニューが表示されるよう、以下のレジストリを登録しました。
Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\*\shell\emacs] @="Edit with emacs(&A)" [HKEY_CLASSES_ROOT\*\shell\emacs\command] @="d:\\home\\emacs\\bin\\emacsclientw.exe \"%1\""
これで、編集したいファイルを右クリックしてコンテキストメニューから、既に起動済みのemacsで開くことができます。
追記
他の環境では、フォルダの権限を変更してもエラーが解消されませんでした。
とりあえず、server.elの
(eql (nth 2 attrs) (user-uid))
をコメントアウトすることで、とりあえず起動しています。