emacs 启动后无法读取文件

emacs 启动后无法读取文件

我刚开始在 Windows 7 中使用 emacs,它非常不稳定。它似乎无法立即读取或写入文件。当我尝试使用 Cx Cf 执行此操作并在启动后几秒写入路径时,迷你缓冲区会给我类似

wrong type argument: stringp, (\, temporary-file-directory)

但如果我等待几分钟或继续尝试,最终我会加载文件。

到底是怎么回事?!

编辑:

这是我的 init.el 文件,emacs 似乎没有它也能运行良好

;; ***My load path***
(cd "x:/PyStuff/")
(setenv "PYTHONPATH" "c:/Python27")
(add-to-list 'load-path "c:/Users/dmvianna/.emacs.d")

;; ***server stuff***
  (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))))
    )

;; ***Miscellaneous inits***
(setq backup-directory-alist
'((".*" . ,temporary-file-directory)))
(setq auto-save-file-name-transforms
'((".*" ,temporary-file-directory t)))
(setq delete-by-moving-to-trash t)
(setq inhibit-startup-screen t)
(put 'upcase-region 'disabled nil)
(put 'downcase-region 'disabled nil)

;;****Python stuff****
(require 'python-mode)
(add-to-list 'auto-mode-alist '("\\.py\\'" . python-mode))
;; *Python mode fixes*
(defun python-reinstate-current-directory ()
  "When running Python, add the current directory ('') to the head of sys.path.
For reasons unexplained, run-python passes arguments to the
interpreter that explicitly remove '' from sys.path. This means
that, for example, using 'python-send-buffer' in a buffer
visiting a module's code will fail to find other modules in the
same directory.

Adding this function to 'inferior-python-mode-hook' reinstates
the current directory in Python's search path."
  (python-send-string "sys.path[0:0] = ['']"))

(add-hook 'inferior-python-mode-hook 'python-reinstate-current-directory)
;;*End Python mode fixes*


(require 'lambda-mode)
(add-hook 'python-mode-hook #'lambda-mode 1)
(require 'ipython)
(require 'anything) (require 'anything-ipython)
  (when (require 'anything-show-completion nil t)
     (use-anything-show-completion 'anything-ipython-complete
                                   '(length initial-pattern)))
 (add-hook 'python-mode-hook #'(lambda ()
                                 (define-key py-mode-map (kbd "M-<tab>") 'anything-ipython-complete)))
 (add-hook 'ipython-shell-hook #'(lambda ()
                                 (define-key py-mode-map (kbd "M-<tab>") 'anything-ipython-complete)))

(require 'comint)
  (define-key comint-mode-map (kbd "M-") 'comint-next-input)
  (define-key comint-mode-map (kbd "M-") 'comint-previous-input)
  (define-key comint-mode-map [down] 'comint-next-matching-input-from-input)
  (define-key comint-mode-map [up] 'comint-previous-matching-input-from-input)

(require 'python-pep8)
(require 'python-pylint)
(add-hook 'before-save-hook 'delete-trailing-whitespace)
(provide 'emacs-init)

答案1

在这段代码中:

(setq backup-directory-alist
'((".*" . ,temporary-file-directory)))
(setq auto-save-file-name-transforms
'((".*" ,temporary-file-directory t)))

您需要'用反引号替换 s,如下所示:

(setq backup-directory-alist
`((".*" . ,temporary-file-directory)))
(setq auto-save-file-name-transforms
`((".*" ,temporary-file-directory t)))

'x意思是(quote x)-x不求值就返回。使用反引号可以选择性求值列表元素。在这种情况下,这本质上意味着不将其视为temporary-file-directory文字。


“但如果我等待几分钟或继续尝试,最终我就能加载文件。”

最有可能的情况是,您最终设法加载文件而不触发自动保存(从而避免了错误,因为没有对损坏的backup-directory-alist和进行操作auto-save-file-name-transforms)。我不完全确定什么情况会导致触发自动保存。

相关内容