From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Bob Proulx Newsgroups: gmane.emacs.help Subject: Re: Speeding up Emacs load time Date: Fri, 28 Jun 2013 13:53:04 -0600 Message-ID: <20130628195304.GB30921@hysteria.proulx.com> References: <20130628032009.GA31464@hysteria.proulx.com> <877ghevm7r.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1372449200 9881 80.91.229.3 (28 Jun 2013 19:53:20 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 28 Jun 2013 19:53:20 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Jun 28 21:53:21 2013 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UsejQ-0005Im-7y for geh-help-gnu-emacs@m.gmane.org; Fri, 28 Jun 2013 21:53:20 +0200 Original-Received: from localhost ([::1]:39262 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UsejP-0000rL-VE for geh-help-gnu-emacs@m.gmane.org; Fri, 28 Jun 2013 15:53:19 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:59703) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UsejE-0000rE-33 for help-gnu-emacs@gnu.org; Fri, 28 Jun 2013 15:53:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UsejC-0006OV-13 for help-gnu-emacs@gnu.org; Fri, 28 Jun 2013 15:53:08 -0400 Original-Received: from joseki.proulx.com ([216.17.153.58]:36865) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UsejB-0006OJ-LY for help-gnu-emacs@gnu.org; Fri, 28 Jun 2013 15:53:05 -0400 Original-Received: from hysteria.proulx.com (hysteria.proulx.com [192.168.230.119]) by joseki.proulx.com (Postfix) with ESMTP id 7EFC7211DC for ; Fri, 28 Jun 2013 13:53:04 -0600 (MDT) Original-Received: by hysteria.proulx.com (Postfix, from userid 1000) id 4BCEC2DCE9; Fri, 28 Jun 2013 13:53:04 -0600 (MDT) Mail-Followup-To: help-gnu-emacs@gnu.org Content-Disposition: inline In-Reply-To: <877ghevm7r.fsf@gmail.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 216.17.153.58 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:91828 Archived-At: 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")