1
votes

When edit .emacs.el in emacs, I have run Alt + X eval-buffer command. My os is windows. And when I restart emacs it display following warning:

Warning (initialization): An error occurred while loading `.../.emacs.el':

error: Non-hex digit used for Unicode escape

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.

.emacs.el is:

;;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) ))

How I can resolve it?

4

4 Answers

5
votes

The problem is these lines:

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

The \U introduces a unicode escape ... and has to be followed by hex digits.

What you actually appear to want is a literal backslash character, so you need to escape it; i.e.

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

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

UPDATE

However, this appears to lead to another problem. A better solution would be to do what @Stefan suggests. Use "/" instead of "\" as the pathname separator. (It should work even on Windows ...)

1
votes

Error is caused by D:\Unix-Tmp, \U introduces unicode escape as Stephen stated.

But when I change to :

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

It will throw another:

Loading d:/git_root_tfs/WorkStation/Unix-Home/.recentf...done Cleaning up the recentf list...done (0 removed) For information about GNU Emacs and the GNU system, type C-h C-a. make-auto-save-file-name: Invalid use of `\' in replacement text

At last I change the path to D:\Tmp-Unix and it works.

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

Total .eamcs.el is

;;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) ))
1
votes

Always use forward slashes rather than backward slashes for file names in Emacs. Windows usually prefers backward slashes, but other than in a few rare exceptions, Windows actually accepts forward slashes just as well.

0
votes

Emacs in Windows treats forward slashes (/) as backslashes (\). When you are specifying any type of path, you should always use forward slashes. Emacs will interpret them correctly. This allows you to control the escape sequence use to times where that is the intended effect.

C:/Users/username/AppData/Roaming/.emacs is a perfectly valid path/filename in Emacs.