首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >修改.emacs时emacs启动错误

修改.emacs时emacs启动错误
EN

Stack Overflow用户
提问于 2018-07-07 15:41:02
回答 1查看 1K关注 0票数 1

我对电子邮件很陌生。我正在尝试使用本指南为Python设置它。它建议的第一步之一是向init.el添加以下内容

代码语言:javascript
复制
;; init.el --- Emacs configuration

;; INSTALL PACKAGES
;; --------------------------------------

(require 'package)

(add-to-list 'package-archives
       '("melpa" . "http://melpa.org/packages/") t)

(package-initialize)
(when (not package-archive-contents)
  (package-refresh-contents))

(defvar myPackages
  '(better-defaults
    material-theme))

(mapc #'(lambda (package)
    (unless (package-installed-p package)
      (package-install package)))
      myPackages)

;; BASIC CUSTOMIZATION
;; --------------------------------------

(setq inhibit-startup-message t) ;; hide the startup message
(load-theme 'material t) ;; load material theme
(global-linum-mode t) ;; enable line numbers globally

;; init.el ends here

因为我有一个.emacs文件,所以我尝试将它附加到这个文件中。之后,我的.emacs看起来像:

代码语言:javascript
复制
(require 'package)
(setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/")
                         ("marmalade" . "http://marmalade-repo.org/packages/")
                         ("melpa" . "http://melpa.milkbox.net/packages/")))
(package-initialize)
(when (not package-archive-contents) (package-refresh-contents))

(let ((default-directory "~/.emacs.d/elpa/"))
    (normal-top-level-add-to-load-path '("."))
    (normal-top-level-add-subdirs-to-load-path))
(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.
 )
(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.
 )

;; init.el --- Emacs configuration

;; INSTALL PACKAGES
;; --------------------------------------



(add-to-list 'package-archives
       '("melpa" . "http://melpa.org/packages/") t)

(package-initialize)
(when (not package-archive-contents)
  (package-refresh-contents))

(defvar myPackages
  '(better-defaults
    material-theme))

(mapc #'(lambda (package)
    (unless (package-installed-p package)
      (package-install package)))
      myPackages)

;; BASIC CUSTOMIZATION
;; --------------------------------------

(setq inhibit-startup-message t) ;; hide the startup message
(load-theme 'material t) ;; load material theme
(global-linum-mode t) ;; enable line numbers globally

;; init.el ends here

但是,这会引发错误:

代码语言:javascript
复制
Warning (initialization): An error occurred while loading ‘/Users/adamg/.emacs’:

File error: http://melpa.org/packages/better-defaults-20160601.1219.el, Not found

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 --debug-init返回:

代码语言:javascript
复制
Debugger entered--Lisp error: (file-error "http://melpa.org/packages/better-defaults-20160601.1219.el" "Not found")
  signal(file-error ("http://melpa.org/packages/better-defaults-20160601.1219.el" "Not found"))
  package-install-from-archive(#s(package-desc :name better-defaults :version (20160601 1219) :summary "Fixing weird quirks and poor defaults" :reqs nil :kind single :archive "melpa" :dir nil :extras ((:url . "https://github.com/technomancy/better-defaults") (:keywords "convenience")) :signed nil))
  mapc(package-install-from-archive (#s(package-desc :name better-defaults :version (20160601 1219) :summary "Fixing weird quirks and poor defaults" :reqs nil :kind single :archive "melpa" :dir nil :extras ((:url . "https://github.com/technomancy/better-defaults") (:keywords "convenience")) :signed nil)))
  package-download-transaction((#s(package-desc :name better-defaults :version (20160601 1219) :summary "Fixing weird quirks and poor defaults" :reqs nil :kind single :archive "melpa" :dir nil :extras ((:url . "https://github.com/technomancy/better-defaults") (:keywords "convenience")) :signed nil)))
  package-install(better-defaults)
  (if (package-installed-p package) nil (package-install package))
  (lambda (package) (if (package-installed-p package) nil (package-install package)))(better-defaults)
  mapc((lambda (package) (if (package-installed-p package) nil (package-install package))) (better-defaults material-theme))
  eval-buffer(#<buffer  *load*> nil "/Users/adamg/.emacs" nil t)  ; Reading at buffer position 1437
  load-with-code-conversion("/Users/adamg/.emacs" "/Users/adamg/.emacs" t t)
  load("~/.emacs" t t)
  #f(compiled-function () #<bytecode 0x400d3941>)()
  command-line()
  normal-top-level()

当我将上面的代码放在单独的init.el文件中时,它不会抛出错误,但它也不会更改启动屏幕或主题。有人能告诉我我做错了什么吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-07-07 16:49:55

您的包存储库内容(本地缓存)已经过时,Emacs正在尝试下载旧的、不再存在的better包版本。

据我所见,这部分的问题是:

代码语言:javascript
复制
(when (not package-archive-contents)
  (package-refresh-contents))

基本上,只有在没有任何信息的情况下才刷新存储库中的包内容(因此只有一次)。在我看来,让它一直更新是很好的,即使Emacs还需要几秒钟才能启动。

Recomendation -删除包刷新的条件,将这两行更改为简单:

代码语言:javascript
复制
(package-refresh-contents)

噢,简单地讲一下配置文件- Emacs尝试从~/.emacs~/.emacs.d/init.el文件加载配置-按这个顺序而只从其中一个文件加载配置。因此,如果您有.emacs文件,init.el将被忽略。这就是为什么您对init.el的更改没有抛出任何错误- Emacs忽略了该文件,只使用了.emacs

(顺便说一句。Emacs还记得使用了哪个文件,因此当您使用Emacs内置工具自定义配置时,更改会转到正确的文件)。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51224634

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档