From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Christopher Schmidt Newsgroups: gmane.emacs.help Subject: Re: Byte Compile Question Date: Fri, 27 Jul 2012 16:12:17 +0100 (BST) Message-ID: <87a9ylck6r@ch.ristopher.com> References: <3D93829C-05BC-4BF3-94D2-716E8443DE9A@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: dough.gmane.org 1343401955 3347 80.91.229.3 (27 Jul 2012 15:12:35 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 27 Jul 2012 15:12:35 +0000 (UTC) Cc: Perry Smith To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Jul 27 17:12:35 2012 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 1SumDS-0002xU-SZ for geh-help-gnu-emacs@m.gmane.org; Fri, 27 Jul 2012 17:12:35 +0200 Original-Received: from localhost ([::1]:53790 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SumDS-0002JP-5j for geh-help-gnu-emacs@m.gmane.org; Fri, 27 Jul 2012 11:12:34 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:43911) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SumDI-0002J7-It for help-gnu-emacs@gnu.org; Fri, 27 Jul 2012 11:12:30 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SumDE-0002Z2-6Q for help-gnu-emacs@gnu.org; Fri, 27 Jul 2012 11:12:24 -0400 Original-Received: from ristopher.com ([146.185.21.93]:45675 helo=saturn.ch.ristopher.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SumDD-0002Vx-RU for help-gnu-emacs@gnu.org; Fri, 27 Jul 2012 11:12:20 -0400 Original-Received: by saturn.ch.ristopher.com (Postfix, from userid 0) id B51C220BC7; Fri, 27 Jul 2012 16:12:17 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=ch.ristopher.com; s=mail; t=1343401937; bh=92rjgyZukmZB40LttJ2ebXSnpZd68xmmPu6MgAYBKZE=; h=From:To:Cc:Subject:In-Reply-To:References:Message-ID:MIME-Version: Content-Type:Date; b=aiY0F6du9aIbwrFRLArjKo1uG3zf68wqqeAwqONVwN13PGRAYT9pfykMm4C+c2lcx 8SmEuj9h+0F0webZzHLSNz34WfgrVUhu5kEOXVkTeTF/j663wm0JG1kL50KZvWOJxK 3ZKDhjMbP+Gc7RRRnHim6qP8YtdOXz8cICAjU6jY= In-Reply-To: <3D93829C-05BC-4BF3-94D2-716E8443DE9A@gmail.com> (Perry Smith's message of "Fri, 27 Jul 2012 09:44:19 -0500") Mail-Followup-To: help-gnu-emacs@gnu.org, Perry Smith X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Received-From: 146.185.21.93 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:86109 Archived-At: --=-=-= Content-Type: text/plain Perry Smith writes: > I have the belief that byte compiling only helps with loading files > and that once they are loaded, the code will execute at the same > speed. > > Is that correct? No. Check (info "(elisp)Byte Compilation"). > Byte compiling all my personal files is a bit awkward for a couple of > reasons. I considering not doing it any more but wanted to know all > the tradeoffs Give it a try. Your code executes faster and the compiler warnings are useful in most cases. You can implement automatic byte compilation by customising load-source-file-function. Here is my auto-compile implementation. --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=auto-compile.el Content-Transfer-Encoding: quoted-printable (defconst my-auto-compile-cache-directory "~/.emacs.d/.gen/byte-code-cache") (when (file-exists-p (expand-file-name "delete" my-auto-compile-cache-directo= ry)) (dolist (file (directory-files my-auto-compile-cache-directory nil "^[^.]= ")) (delete-file (expand-file-name file my-auto-compile-cache-directory)))) (make-directory my-auto-compile-cache-directory t) (defvar my-auto-compile-disable nil) (defvar my-auto-compile-original-load-source-file-function load-source-file-function) (defvar my-auto-compile-inner-load-files nil) (defvar my-auto-compile-inner nil) ;; 06/2012: sometimes this form is not properly executed (defun my-advice-byte-compile-log-file () (defun byte-compile-log-file () (with-current-buffer (get-buffer-create byte-compile-log-buffer) ;; there is no other obvious place to create the buffer and set the m= ode (compilation-mode)))) (my-advice-byte-compile-log-file) (defun my-auto-compile-disable () (or my-auto-compile-disable (not (equal emacs-version "24.1.1")))) (defun my-auto-compile-file (fullname file &optional noerror nomessage no-l= oad) (let* ((byte-file) (action (cond ((or (my-auto-compile-disable) (not (string-match-p (concat "^~/\\(\\.emacs\\.d/elisp\\|" "tracked/projects\\)/") (abbreviate-file-name fullname)))) nil) ((progn (setq byte-file (expand-file-name (concat (file-name-sans-extension (file-name-nondirectory fullname)) "-" (substring (sha1 fullname) 0 2) ".elc") my-auto-compile-cache-directory)) (not (or (not (file-exists-p byte-file)) (file-newer-than-file-p file byte-file)))) t) (my-auto-compile-inner (add-to-list 'my-auto-compile-inner-load-files fullname) nil) (t (require 'bytecomp) (my-advice-byte-compile-log-file) (let ((byte-compile-dest-file-function (lambda (_) byte-file)) (my-auto-compile-inner t)) (when (byte-compile-file file (not no-load)) (unless (eq system-type 'windows-nt) (let ((link (replace-regexp-in-string "c$" "" byte-file))) (unless (file-exists-p link) (start-process "symlink" nil "ln" "--symbolic" fullname (expand-file-name link))))) 'nothing)))))) (cond ((or no-load (eq action 'nothing)) t) (action (load byte-file noerror nomessage t)) (t (funcall my-auto-compile-original-load-source-file-function fullname file noerror nomessage))))) (defun my-load-source-file-function (fullname file &optional noerror nomess= age) (let ((result (my-auto-compile-file fullname file noerror nomessage))) (unless my-auto-compile-inner (while my-auto-compile-inner-load-files (let ((file (pop my-auto-compile-inner-load-files))) (my-auto-compile-file file file nil nil t)))) result)) (setq load-source-file-function 'my-load-source-file-function) --=-=-= Content-Type: text/plain Christopher --=-=-=--