1
votes

My emacs takes a few seconds to start up every time, which is slower than I'd expect. During that time, it says "contacting host: " marmalade-repo and melpa.

Is my current config a reasonable one? Is there a way I can speed it up, while still being able to install packages when I need them?

;; 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)))
1
Type M-x describe-function RET package-refresh-contents RET and make a conscious decision whether you really need to have that happening every time you start Emacs. If you need it, well, then live with the wait time. If you don't need it, then remove both references. Remove the first occurrence (when (not package-archive-contents) (package-refresh-contents)) and remove the second occurrence further on down (package-refresh-contents). And, unless your packages have a tendency to vaporize into thin air on a daily basis, then remove the package-install stuff beginning with mapc.lawlist
@lawlist Super. Even just commenting out the add-to-list instances speeds it way up. Thanks!Hatshepsut
@Hatshepsut: If you're referring to the add-to-list calls for package-archives, then of course that will speed things up -- at the expense of not including those package archives, so probably not what you want. See stackoverflow.com/a/14838150/245173.jpkotta

1 Answers

2
votes

Recently, loading packages from MELPA has been really slow, I'm not so sure why. What you can do to get around this (or at least make sure it only happens once) is to run Emacs in daemon mode, and then connect to it whenever you want to edit a file. It means that the cost of loading is only incurred once. It's as simple as running emacs --daemon at startup. Then you connect via emacsclient.