代码之家  ›  专栏  ›  技术社区  ›  Adam_G

修改.emacs时Emacs启动错误

  •  1
  • Adam_G  · 技术社区  · 6 年前

    我刚接触Emacs。我正在尝试为python设置它,使用 this guide . 它建议的第一步是将以下内容添加到 init.el :

    ;; 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 看起来像:

    (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
    

    但是,这会引发错误:

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

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

    当我把上面的代码放在一个单独的 初始EL 文件,它不会引发错误,但也不会更改启动屏幕或主题。有人能指出我做错了什么吗?

    1 回复  |  直到 6 年前
        1
  •  2
  •   rsm Vsevolod Dyomkin    6 年前

    better

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

    (package-refresh-contents)
    

    ~/.emacs ~/.emacs.d/init.el .emacs init.el