emacs 启动速度慢

问题描述 投票:0回答:2

我的 emacs 每次启动都需要几秒钟,这比我预期的要慢。在此期间,它显示“正在联系主机:”marmalade-repo 和 melpa。

我当前的配置合理吗?有没有办法可以加快速度,同时仍然能够在需要时安装软件包?

;; init.el --- Emacs configuration

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

(require 'package)

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

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

(defvar myPackages
  '(better-defaults
    paredit
    idle-highlight-mode
    ido-ubiquitous
    find-file-in-project
    smex
    scpaste
    ein
    elpy
    flycheck
    material-theme
    py-autopep8))
(package-refresh-contents)

(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

;; PYTHON CONFIGURATION
;; --------------------------------------

(elpy-enable)
(elpy-use-ipython)

;; use flycheck not flymake with elpy
(when (require 'flycheck nil t)
  (setq elpy-modules (delq 'elpy-module-flymake elpy-modules))
  (add-hook 'elpy-mode-hook 'flycheck-mode))

;; enable autopep8 formatting on save
(require 'py-autopep8)
(add-hook 'elpy-mode-hook 'py-autopep8-enable-on-save)

;; enable electric pair minor mode
(defun electric-pair ()
  "If at end of line, insert character pair without surrounding spaces.
    Otherwise, just insert the typed character."
  (interactive)
  (if (eolp) (let (parens-require-spaces) (insert-pair)) (self-insert-command 1)))
(add-hook 'python-mode-hook
          (lambda ()
            (define-key python-mode-map "\"" 'electric-pair)
            (define-key python-mode-map "\'" 'electric-pair)
            (define-key python-mode-map "(" 'electric-pair)
            (define-key python-mode-map "[" 'electric-pair)
            (define-key python-mode-map "{" 'electric-pair)))


;; Send line from code buffer
;; http://stackoverflow.com/questions/27777133/change-the-emacs-send-code-to-interpreter-c-c-c-r-command-in-ipython-mode/30774439#30774439
(defun my-python-line ()
(interactive)
(save-excursion
  (setq the_script_buffer (format (buffer-name)))
  (end-of-line)
  (kill-region (point) (progn (back-to-indentation) (point)))
  (if  (get-buffer  "*Python*")
  (message "")
  (run-python "ipython" nil nil))
  ;; (setq the_py_buffer (format "*Python[%s]*" (buffer-file-name)))
  (setq the_py_buffer "*Python*")
  (switch-to-buffer-other-window  the_py_buffer)
  (goto-char (buffer-end 1))
  (yank)
  (comint-send-input)
  (switch-to-buffer-other-window the_script_buffer)
  (yank))
  (end-of-line)
  (next-line)
  )
(add-hook 'python-mode-hook
    (lambda ()
  (define-key python-mode-map "\C-cn" 'my-python-line)))
emacs
2个回答
2
投票

最近,从 MELPA 加载包非常慢,我不太清楚为什么。为了解决这个问题(或者至少确保它只发生一次),您可以做的是在守护程序模式下运行 Emacs,然后在您想要编辑文件时连接到它。这意味着装载成本仅产生一次。就像在启动时运行

emacs --daemon
一样简单。然后您通过
emacsclient
连接。


0
投票

很抱歉恢复了一个死帖子,但因为这是搜索“melpa 需要永远加载”时出现的第一个内容。

永远需要的部分是

(package-refresh-contents)
。由于我认为没有必要每天做更多的事情,因此我制作了以下代码片段来解决这个问题:

(defun read-file (filename)
  "Return the contents of FILENAME"
  (if (file-exists-p filename)
      (with-temp-buffer
    (insert-file-contents filename)
    (buffer-string))
    ""))

(progn
  (require 'package)
  (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
  ;; Comment/uncomment this line to enable MELPA Stable if desired.  See `package-archive-priorities`
  ;; and `package-pinned-packages`. Most users will not need or want to do this.
  ;;(add-to-list 'package-archives '("melpa-stable" . "https://stable.melpa.org/packages/") t)
  (package-initialize)
  (let* ((filename (expand-file-name "package_time" user-emacs-directory))
     (today (format-time-string "%Y-%m-%d"))
     (now (date-to-time today))
     (then (date-to-time (read-file filename))))
    (if (time-less-p then now)
    (progn
      (write-region today nil filename nil 'quiet)
      (package-refresh-contents))
      nil)))
© www.soinside.com 2019 - 2024. All rights reserved.