windows Emacs - 调用时出错(服务器启动)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/885793/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 06:22:45  来源:igfitidea点击:

Emacs - Error when calling (server-start)

windowsemacselispdot-emacsserver-mode

提问by λ Jonas Gorauskas

I am currently using GNU Emacs 23.0.93.1 in Windows Vista SP1. In my .emacs file I make a call to (server-start)and that is causing an error with the message The directory ~/.emacs.d/server is unsafe. Has anyone seen this and know a fix or workaround? ... other than leaving server turned off ;)

我目前在 Windows Vista SP1 中使用 GNU Emacs 23.0.93.1。在我的 .emacs 文件中,我调用(server-start)并导致错误消息The directory ~/.emacs.d/server is unsafe。有没有人看到这个并知道修复或解决方法?...除了离开服务器关闭;)

Here is the stack trace:

这是堆栈跟踪:

Debugger entered--Lisp error: (error "The directory ~/.emacs.d/server is unsafe")
  signal(error ("The directory ~/.emacs.d/server is unsafe"))
  error("The directory %s is unsafe" "~/.emacs.d/server")
  server-ensure-safe-dir("~\.emacs.d\server\")
  server-start(nil)
  call-interactively(server-start t nil)
  execute-extended-command(nil)
  call-interactively(execute-extended-command nil nil)

回答by RealityMonster

I found this solution on EmacsWiki:

我在 EmacsWiki 上找到了这个解决方案:

"The problem is the ownership of the directory ~/.emacs.d/server when you also have “Administrators” rights on your account. Create the directory ~/.emacs.d/server and set the owner of this directory to your login name and the problem is gone. As I have a “Dutch” version of Windows 7 I don't know the English terms exactly but here's the procedure:

“问题是目录 ~/.emacs.d/server 的所有权,当您的帐户还具有“管理员”权限时。创建目录 ~/.emacs.d/server 并将此目录的所有者设置为您的登录名名称和问题消失了。因为我有一个“荷兰”版本的 Windows 7,我不完全知道英文术语,但这里是过程:

Click R-mouse on ~/.emacs.d/server and select “Properties” (last item in menu). From Properties select the Tab “Security” and then select the button “Advanced”. Then select the Tab “Owner” and change the owner from Administrators (<your-pc-name>\Administrators)into <your-login-name> (<your-pc-name>\<your-login-name>. Now the server code will accept this directory as secure because you are the owner.

单击 ~/.emacs.d/server 上的 R 鼠标并选择“属性”(菜单中的最后一项)。从“属性”中选择“安全”选项卡,然后选择“高级”按钮。然后选择选项卡“所有者”并将所有者从 更改Administrators (<your-pc-name>\Administrators)<your-login-name> (<your-pc-name>\<your-login-name>。现在服务器代码将接受此目录作为安全目录,因为您是所有者。

Hope this helps for all you guys, it solved the problem for me anyway.

希望这对你们所有人都有帮助,无论如何它为我解决了问题。

W.K.R. Reutefleut"

WKR 路透社”

It definitely works on Vista, with Emacs 23.2.1.

它绝对适用于使用 Emacs 23.2.1 的 Vista。

回答by gavenkoa

I enjoy to anwer of larsreed, but complite code ready to use:

我喜欢 larsreed 的答案,但可以使用完整的代码:

(require 'server)
(when (and (>= emacs-major-version 23)
           (equal window-system 'w32))
  (defun server-ensure-safe-dir (dir) "Noop" t)) ; Suppress error "directory
                                                 ; ~/.emacs.d/server is unsafe"
                                                 ; on windows.
(server-start)

I discass this issue in my blog article http://brain-break.blogspot.com/2009/08/when-moving-from-gnu-emacs-22.html

我在我的博客文章http://brain-break.blogspot.com/2009/08/when-moving-from-gnu-emacs-22.html 中讨论了这个问题

Also note that in 2009-09-19 fixed bug #4197 about server-ensure-safe-dir so in incoming Emacs 23.2 this workaround is not needed.

另请注意,在 2009-09-19 中修复了关于 server-ensure-safe-dir 的错误 #4197,因此在传入的 Emacs 23.2 中不需要此解决方法。

Under recently released Emacs 23.2 I have such warning:

在最近发布的 Emacs 23.2 下,我有这样的警告:

Warning (server): Using ~/.emacs.d/serverto store Emacs-server authentication files. Directories on FAT32 filesystems are NOT secure against tampering. See variable server-auth-dirfor details.

警告(服务器):~/.emacs.d/server用于存储 Emacs-server 身份验证文件。FAT32 文件系统上的目录无法防止篡改。有关server-auth-dir详细信息,请参阅变量。

To fix this as say warning you can point server-auth-dir to NTFS partition (%APPDATA%usually located Windows %SYSTEMDRIVE%and user usually format system drive as NTFS partition):

要解决此警告,您可以将 server-auth-dir 指向 NTFS 分区(%APPDATA%通常位于 Windows%SYSTEMDRIVE%并且用户通常将系统驱动器格式化为 NTFS 分区):

(require 'server)
(when (and (eq window-system 'w32) (file-exists-p (getenv "APPDATA")))
  (setq server-auth-dir (concat (getenv "APPDATA") "/.emacs.d/server"))
  (make-directory server-auth-dir)  )
(server-start)

回答by brlcad

This is a known Emacs bug on Windows. A workaround is to comment out this line in server-ensure-safe-dir in server.el the you'll want to byte recompile after the change:

这是 Windows 上已知的 Emacs 错误。一种解决方法是在 server.el 中的 server-ensure-safe-dir 中注释掉这一行,您需要在更改后进行字节重新编译:

;; FIXME: Busted on Windows. 
;; (eql (nth 2 attrs) (user-uid)) 

回答by lre

To avoid hacking in the lisp directory, you can just add the following to your .emacs:

为了避免在 lisp 目录中遭到黑客攻击,您只需将以下内容添加到您的 .emacs 中:

(require 'server) (and (>= emacs-major-version 23) (defun server-ensure-safe-dir (dir) "Noop" t))

(require 'server) (and (>= emacs-major-version 23) (defun server-ensure-safe-dir (dir) "Noop" t))

回答by Andreas Spindler

Additionally you do not want the server to be started in batch-mode. In my .emacsI therefore use

此外,您不希望以批处理模式启动服务器。因此,在我的.emacs 中,我使用

(defconst --batch-mode 
  (or noninteractive (member "--batch-mode" command-line-args))
  "True when running in batch-mode (--batch-mode command-line switch set).")

and then

进而

(unless --batch-mode
  (require 'server)
  (when (and (= emacs-major-version 23)
         (= emacs-minor-version 1)
         (equal window-system 'w32))
    ;; Suppress error "directory ~/.emacs.d/server is unsafe" on Windows.
    (defun server-ensure-safe-dir (dir) "Noop" t))
  (server-start))

Still the server feature is capricious: server-startthrows when the %HOME%/.emacs.d/serverdirectory does not exist. In succession Emacs won't start up again! The obvious solution is to create the missing directory and try again; I found the solution somewhere on the net but really can't remember where. The following code runs successfully for years now on several of my Windows machines:

服务器功能仍然反复无常:server-start%HOME%/.emacs.d/server目录不存在时抛出。连续 Emacs 将无法再次启动!显而易见的解决方案是创建丢失的目录并重试;我在网上的某个地方找到了解决方案,但真的不记得在哪里。以下代码在我的几台 Windows 机器上成功运行了多年:

(unless --batch-mode
  (require 'server)
  (when (and (= emacs-major-version 23)
         (= emacs-minor-version 1)
         (equal window-system 'w32))
    ;; Suppress error "directory ~/.emacs.d/server is unsafe" on Windows.
    (defun server-ensure-safe-dir (dir) "Noop" t))
  (condition-case nil
      (server-start)
    (error
     (let* ((server-dir (if server-use-tcp server-auth-dir server-socket-dir)))
       (when (and server-use-tcp
          (not (file-accessible-directory-p server-dir)))
     (display-warning
      'server (format "Creating %S" server-dir) :warning)
     (make-directory server-dir t)
     (server-start))))
    )
  )

This code also works when running Emacs from a stick.

此代码在从棒上运行 Emacs 时也有效。

Hope this helps.

希望这可以帮助。

回答by KTa

Did not work for me in Windows 7.

在 Windows 7 中对我不起作用。

I instead read the comments in server-ensure-safe-dir and proceeded with taking the ownership for %APPDATA% forlder and subfolders. They were owned by local Administrators, not by me.

我改为阅读 server-ensure-safe-dir 中的注释,并继续取得 %APPDATA% 文件夹和子文件夹的所有权。它们归本地管理员所有,而不是我所有。

That helped!

那有帮助!

回答by lbo

Very helpful answer from gavenkoa. I'm having this problem on Emacs 24.1, Windows 2003.

来自 Givenkoa 的非常有帮助的回答。我在 Emacs 24.1、Windows 2003 上遇到了这个问题。

Unfortunately, overriding server-ensure-safe-dir to become a noop, as suggested in your first snippet, didn't work for me in all situations. Specifically, it did not work when applied before (server-start) had executed at least once, because the initial executionwould also create the directory, if it doesn't exist. With the noop version, the directory would not be created at all.

不幸的是,正如您在第一个片段中所建议的那样,覆盖 server-ensure-safe-dir 成为一个 noop,在所有情况下都不适合我。具体来说,在 (server-start) 至少执行一次之前应用它时它不起作用,因为初始执​​行也会创建目录,如果它不存在。使用 noop 版本,根本不会创建目录。

The workaround that worked for me in the sense that it eliminated the error message, while still creating the directory properly, was the following code, put before (server-start) in my Emacs initialization file. It puts an advice around server-ensure-safe-dir to ignore any errors raised from there. Doesn't solve the root cause of the problem, but good enough for me.

对我有用的解决方法是消除错误消息,同时仍然正确创建目录,是以下代码,放在我的 Emacs 初始化文件中的 (server-start) 之前。它围绕 server-ensure-safe-dir 提出建议,以忽略从那里引发的任何错误。不能解决问题的根本原因,但对我来说已经足够了。

(defadvice server-ensure-safe-dir (around
                                   my-around-server-ensure-safe-dir
                                   activate)
  "Ignores any errors raised from server-ensure-safe-dir"
  (ignore-errors ad-do-it))

回答by Jesse Peng

Below step works for me: 1. Execute code below as .reg file. Emacs win version will treat any values in registry as Env Var.

下面的步骤对我有用: 1. 将下面的代码作为 .reg 文件执行。Emacs win 版本会将注册表中的任何值视为 Env Var。

[HKEY_LOCAL_MACHINE\SOFTWARE\GNU\Emacs]
"HOME"="C:/<your_emacs_home>"
"EMACS_SERVER_FILE"="C:/<your_emacs_home>/server/main_server"
"ALTERNATE_EDITOR"="C:/<your_emacs_loc>/bin/runemacs.exe"
  1. Add code below to your .emacs/init.el. The key here should be "server-auth-dir".
  1. 将下面的代码添加到您的 .emacs/init.el。这里的关键应该是“server-auth-dir”。
(require 'server)
(setq server-auth-dir "~/server")  ;;Server file location
(setq server-name "main_server")   ;;Server mutex file name
(server-start)

By steps above server mode works for me correctly and perfect.

通过以上步骤,服务器模式对我来说正确而完美。

回答by Sam Hasler

If it's the server folder ownership issue that RealityMonster identified, then you can run this at the windows command prompt to fix it:

如果是 RealityMonster 识别出的服务器文件夹所有权问题,那么您可以在 Windows 命令提示符下运行它来修复它:

takeown /f %USERPROFILE%\.emacs.d\server /r /d y

回答by David M. Karr

In case this occasionally hits people, my workstation just went through a "domain migration", which added another permission to every file on the box, then I started getting this error. After I added the expression to dummy out "server-ensure-safe-dir" this stopped failing.

万一这偶尔会影响人们,我的工作站刚刚经历了“域迁移”,这为盒子上的每个文件添加了另一个权限,然后我开始收到此错误。在我将表达式添加到虚拟的“server-ensure-safe-dir”之后,这停止了失败。

(If you're wondering, the migration will be in 2-3 steps. The first one adds the permission for me in the target domain, then I get moved to the target domain, then they might (I'm not sure about this) remove the permission for the old domain. It's a big company, and many users, so they're doing it in separate steps.)

(如果您想知道,迁移将分 2-3 个步骤。第一个步骤是在目标域中为我添加权限,然后我移动到目标域,然后他们可能会(我不确定这一点) ) 删除旧域的权限。这是一家大公司,用户众多,因此他们分步进行。)