【问题标题】:Emacs Warning An error occurred while loading `.../.emacs.el':Emacs 警告加载“.../.emacs.el”时出错:
【发布时间】:2014-07-10 03:02:05
【问题描述】:

在 emacs 中编辑 .emacs.el 时,我运行了 Alt + X eval-buffer 命令。 我的操作系统是windows。 当我重新启动 emacs 时,它会显示以下警告:

警告(初始化):加载时出错 `.../.emacs.el':

错误:用于 Unicode 转义的非十六进制数字

为确保正常运行,您应该调查并删除 初始化文件中的错误原因。使用以下命令启动 Emacs `--debug-init' 选项来查看完整的错误回溯。

.emacs.el 是:

;;Open all fine in one running instance
;;Ref:http://www.johndcook.com/blog/2010/07/28/miscellaneous-emacs-adventures/
;;(server-start)

;;TEST
(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 `(ansi-color-names-vector ["#242424" "#e5786d" "#95e454" "#cae682" "#8ac6f2" "#333366" "#ccaa8f" "#f6f3e8"])
 `(custom-enabled-themes (quote (wheatgrass))))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )

;;Set auto save backup location, failed with following warning
(setq backup-directory-alist
    `((".*" . ,"D:\Unix-Tmp")))
(setq auto-save-file-name-transforms
    `((".*" ,"D:\Unix-Tmp" t)))

(require 'recentf)
(recentf-mode 1)

(setq inhibit-startup-screen t)

(put 'upcase-region 'disabled nil)
(put 'downcase-region 'disabled nil)

;;Aspell install failed
;;(setq-default ispell-program-name "C:/bin/Aspell/bin/aspell.exe")
;;(setq text-mode-hook '(lambda() (flyspell-mode t) ))

我该如何解决?

【问题讨论】:

    标签: unix emacs elisp


    【解决方案1】:

    问题在于以下几行:

    (setq backup-directory-alist
        `((".*" . ,"D:\Unix-Tmp")))
    (setq auto-save-file-name-transforms
        `((".*" ,"D:\Unix-Tmp" t)))
    

    \U 引入了 unicode 转义 ... 并且必须后跟十六进制数字。

    您实际上想要的是文字反斜杠字符,因此您需要对其进行转义;即

    (setq backup-directory-alist
        `((".*" . ,"D:\\Unix-Tmp")))
    (setq auto-save-file-name-transforms
        `((".*" ,"D:\\Unix-Tmp" t)))
    

    参考:http://www.gnu.org/software/emacs/manual/html_node/elisp/Basic-Char-Syntax.html#Basic-Char-Syntax

    更新

    但是,这似乎会导致另一个问题。一个更好的解决方案是按照@Stefan 的建议去做。使用“/”而不是“\”作为路径名分隔符。 (它应该甚至在 Windows 上也能工作......)

    【讨论】:

    • 谢谢斯蒂芬。我试过你的解决方案。但它会引发以下错误:Loading d:/git_root_tfs/WorkStation/Unix-Home/.recentf...done 清理最近的列表...完成(0 已删除)有关 GNU Emacs 和 GNU 系统的信息,请键入 C-h C-a . make-auto-save-file-name: 在替换文本中无效使用 `\'
    • 我已将路径更改为 D:\Tmp-Unix。有用。非常感谢
    【解决方案2】:

    错误是由 D:\Unix-Tmp 引起的,正如 Stephen 所说,\U 引入了 unicode 转义。

    但是当我改为:

    (setq backup-directory-alist
        `((".*" . ,"D:\\Unix-Tmp")))
    (setq auto-save-file-name-transforms
        `((".*" ,"D:\\Unix-Tmp" t)))
    

    它会抛出另一个:

    正在加载 d:/git_root_tfs/WorkStation/Unix-Home/.recentf...完成清理 up the recentf list...done (0 删除) 关于 GNU Emacs 的信息 和 GNU 系统,键入 C-h C-a。制作自动保存文件名:无效 在替换文本中使用“\”

    最后我把路径改成 D:\Tmp-Unix 就可以了。

    (setq backup-directory-alist
        `((".*" . ,"D:\Tmp-Unix")))
    (setq auto-save-file-name-transforms
        `((".*" ,"D:\Tmp-Unix" t)))
    

    .eamcs.el 总数为

    ;;Open all fine in one running instance
    ;;Ref:http://www.johndcook.com/blog/2010/07/28/miscellaneous-emacs-adventures/
    ;;(server-start)
    
    ;;TEST
    (custom-set-variables
     ;; custom-set-variables was added by Custom.
     ;; If you edit it by hand, you could mess it up, so be careful.
     ;; Your init file should contain only one such instance.
     ;; If there is more than one, they won't work right.
     `(ansi-color-names-vector ["#242424" "#e5786d" "#95e454" "#cae682" "#8ac6f2" "#333366" "#ccaa8f" "#f6f3e8"])
     `(custom-enabled-themes (quote (wheatgrass))))
    (custom-set-faces
     ;; custom-set-faces was added by Custom.
     ;; If you edit it by hand, you could mess it up, so be careful.
     ;; Your init file should contain only one such instance.
     ;; If there is more than one, they won't work right.
     )
    
    ;;Set auto save backup location, failed with following warning
    (setq backup-directory-alist
        `((".*" . ,"D:\Tmp-Unix")))
    (setq auto-save-file-name-transforms
        `((".*" ,"D:\Tmp-Unix" t)))
    
    (require 'recentf)
    (recentf-mode 1)
    
    (setq inhibit-startup-screen t)
    
    (put 'upcase-region 'disabled nil)
    (put 'downcase-region 'disabled nil)
    
    ;;Aspell install failed
    ;;(setq-default ispell-program-name "C:/bin/Aspell/bin/aspell.exe")
    ;;(setq text-mode-hook '(lambda() (flyspell-mode t) ))
    

    【讨论】:

      【解决方案3】:

      在 Emacs 中,始终使用 forward 斜杠而不是 backward 斜杠作为文件名。 Windows 通常更喜欢反斜杠,但除了极少数例外,Windows 实际上也接受正斜杠。

      【讨论】:

        【解决方案4】:

        Windows 中的 Emacs 将正斜杠 (/) 视为反斜杠 (\)。当您指定任何类型的路径时,您应该始终使用正斜杠。 Emacs 会正确解释它们。这使您可以控制转义序列使用到预期效果的时间。

        C:/Users/username/AppData/Roaming/.emacs 在 Emacs 中是完全有效的路径/文件名。

        【讨论】:

          猜你喜欢
          • 2022-10-24
          • 2015-06-11
          • 1970-01-01
          • 2016-08-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多