help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Speeding up Emacs load time


From: Bob Proulx
Subject: Re: Speeding up Emacs load time
Date: Fri, 28 Jun 2013 13:53:04 -0600
User-agent: Mutt/1.5.21 (2010-09-15)

Hongxu Chen wrote:
> Hey Bob, would you mind sharing your .emacs settings(pastebin/gist/github or
> something like that)?

I don't know how useful it will be to other people.  The .emacs
customization file is by definition to customize it for personal
tastes.  My tastes are going to be different from yours.  But okay.  I
am probably doing twenty things sub-optimally so don't take it
verbatim.

The biggest thing for me was to throw away a lot of lint that had been
collecting for years.  Much of my file contained vestiges that were no
longer needed.  I cleaned brutally and removing as much as possible.
If I didn't use it then I removed it.  That reduced the file to
something much smaller and faster and yet I still have all of the
functionality that I need and use.  If you need a lot of customization
then your load time will be slower.  My question would then be to ask
if you really do need all of the customization?  Clean brutally!

The next biggest thing was to avoid loading or requiring any other
file at load time.  Avoid stat(2)'ing any other file at load time.
(For example file-directory-p stats the file.)  File operations are
slow.  If $HOME is on NFS then file operations are *very* slow.  Make
all of those do "lazy loading" where they only load if the code is
going to be used.  In my case I wrapped them in eval-after-load calls
so that they did not trigger at emacs start but only when I triggered
the associated buffer mode.  YMMV and all of that.  In the end I
removed most of those customizations that I had carried from years ago
and my .emacs is now quite small.

Usually when I share my .emacs someone posts that I should use fboundp
instead of keying off of emacs-major-version.  No I shouldn't.  I want
to leave the trail behind as documentation as to when emacs took its
dark turns and emacs-major-version is self-documenting while fboundp
is not.  Remember that the .emacs is a personal customization file and
this is to my personal taste.  YMMV.

Bob


(message "[reading file ~/.emacs]")     ; -*-emacs-lisp-*-

(if (>= emacs-major-version 20)
    (menu-bar-mode -1))

(if (>= emacs-major-version 21)
    (if window-system
        (tool-bar-mode -1)))

(if (>= emacs-major-version 22)
    (progn
      (setq inhibit-startup-screen t)
      (setq write-region-inhibit-fsync t)
      ;; Have *Buffer List* use old-style header.
      (setq Buffer-menu-use-header-line nil)
      ;; Disable dark blue on dark background in minibuffer.
      (set-face-foreground 'minibuffer-prompt nil)))

(if (>= emacs-major-version 23)
    (progn
      (setq transient-mark-mode nil)
      (setq line-move-visual nil)
      (setq search-whitespace-regexp nil)
      (setq split-width-threshold nil)
      (setq kill-buffer-query-functions nil)))

(if (>= emacs-major-version 24)
    (progn
      ;; C-s changed in 24.  But I use the previous behavior.
      (define-key isearch-mode-map (kbd "C-y") 'isearch-yank-line)))

(if window-system
    (setq mouse-yank-at-point t))

(autoload 'highlight-80+-mode "highlight-80+"
  "Highlight the portions of lines longer than 80 characters." t)

;; Disable nasty highlighting in electric-buffer-mode.
;; We use eval-after-load to make this happen after ebuf-menu is loaded
;; as that's where the "bad" definition of electric-buffer-mode is located.
(eval-after-load "ebuff-menu" '(defun electric-buffer-update-highlight ()))

(eval-after-load 'shell
  '(add-hook 'comint-exec-hook
             (lambda ()
               (setq comint-scroll-show-maximum-output nil)
               ;; Stop the annoying question about exiting with shell
               ;; processes still running.
               (set-process-query-on-exit-flag (get-process "shell") nil))))

(add-hook 'text-mode-hook
          (lambda ()
            (abbrev-mode 1)
            (auto-fill-mode 1)))

(add-hook 'c-mode-hook
          (lambda ()
            ;; Set '_' to be part of word for dynamic abbreviation
            ;; expansion and for word movement.
            (modify-syntax-entry ?_ "w" c-mode-syntax-table)))

(eval-after-load 'ruby-mode
  (and (file-directory-p (expand-file-name "~/emacs/rinari"))
       (add-to-list 'load-path "~/emacs/rinari")
       (autoload 'rinari-web-server "rinari" "Rinari" t)
       (add-hook 'ruby-mode
                 (lambda ()
                   (require 'rinari)))))

(setq w3m-use-cookies t)               ; off by default, but mostly required
(add-hook 'w3m-mode-hook
          (lambda ()
            ;; I like the cursor keys to behave normally, not jumping
            ;; from link to link.
            (local-set-key '[up] 'previous-line)
            (local-set-key '[down] 'next-line)))

;; Turn off emacs file~ backups.
(setq make-backup-files nil)

(setq sh-indent-comment t)
(setq executable-prefix "#!")
(setq sh-basic-offset 2)        ; originally 4, set my preference
(setq apache-indent-level '8)   ; originally 4, match upstream
(setq Man-notify-method 'pushy)

(global-set-key [home] 'beginning-of-buffer) ; orig beginning-of-buffer, now 
move-end-of-line
(global-set-key [S-home] 'end-of-buffer)
(global-set-key [end] 'end-of-buffer) ; orig end-of-buffer, now 
move-beginning-of-line
(global-set-key [S-end] 'beginning-of-buffer)

(global-set-key "\C-x\C-b" 'electric-buffer-list) ; originally list-buffers
(global-set-key "\M-r" 'replace-regexp) ; orig 'move-to-window-line
(global-set-key "\M-\C-r" 'query-replace-regexp) ; originally undefined, now 
isearch-backward-regexp
(global-set-key "\C-l" 'recenter) ; originally recenter, now recent-top-bottom
(global-set-key "\C-z" 'scroll-down)    ; originally suspend-frame

(put 'dired-find-alternate-file 'disabled nil)
(put 'narrow-to-region 'disabled nil)
(put 'downcase-region 'disabled nil)

(setq confirm-kill-emacs 'yes-or-no-p)

(setq auto-mode-alist    ; Note: RE matches full pathname, so
      (append            ; '^' matches / in /dir/dir/filename
       '(
         ("^\\(/var\\)?/tmp/mutt" . text-mode)
         )
       auto-mode-alist))

(display-time)

(message "done")



reply via email to

[Prev in Thread] Current Thread [Next in Thread]