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

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

Re: Order of precedence for .el and .elc during load or require


From: Chris McMahan
Subject: Re: Order of precedence for .el and .elc during load or require
Date: Fri, 01 Jun 2007 09:23:30 -0400
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.990 (windows-nt)

One workaround I use is to have emacs offer to byte compile any .el
files on saving them.

;;;======================================================================
;;; byte compile the current buffer on saving it
;;;======================================================================
(defvar mode-specific-after-save-buffer-hooks nil
  "Alist (MAJOR-MODE . HOOK) of after-save-buffer hooks
specific to major modes.")

(defun run-mode-specific-after-save-buffer-hooks ()
  "Run hooks in `mode-specific-after-save-buffer-hooks' that match the
current buffer's major mode.  To be put in `after-save-buffer-hooks'."
  (let ((hooks mode-specific-after-save-buffer-hooks))
    (while hooks
      (let ((hook (car hooks)))
    (if (eq (car hook) major-mode)
        (funcall (cdr hook))))
      (setq hooks (cdr hooks)))))

(defun ask-to-byte-compile ()
  "Ask the user whether to byte-compile the current buffer
if its name ends in `.el' and the `.elc' file also exists."
  (let ((name (buffer-file-name)))
    (and name
     (string-match "\\.el$" name)
     (file-exists-p (concat name "c"))
     (if (y-or-n-p (format "Byte-compile %s? " name))
         (byte-compile-file name)
       (message "")))))

(setq mode-specific-after-save-buffer-hooks
      '((emacs-lisp-mode . ask-to-byte-compile)
        (lisp-mode . ask-to-byte-compile)))

(setq after-save-hook '(run-mode-specific-after-save-buffer-hooks))

;;;======================================================================



Nordlöw <address@hidden> writes:

> High there again, Emacs power-users.
>
> When I develop my Emacs I find it annoying that Emacs chooses the
> compiled version (.elc) over the non-compiled version (.el) even if
> the non-compiled version is newer than the compiled one.
>
> Is there a way to change this behaviour, or are there any fundamental
> drawback with my idea?
>
> A good compromise would perhaps be to warn during load of, for
> example, foo.elc when foo.el is newer (on the file-system).
>
> /Nordlöw
>

-- 
     (.   .)
  =ooO=(_)=Ooo=====================================
  Chris McMahan | address@hidden
  =================================================


reply via email to

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