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

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

Re: How to halt a loading file


From: Pascal Bourguignon
Subject: Re: How to halt a loading file
Date: Sat, 29 Mar 2008 17:25:52 +0100
User-agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/22.1.50 (gnu/linux)

Kevin Rodgers <kevin.d.rodgers@gmail.com> writes:

> orium wrote:
>> Hi, everybody.
>> I am not a lisp coder, so this may have a obvious answer.
>> I need to halt .emacs in its execution:
>> (defun compile-emacs-config-file ()
>>   "Compiles ~/.emacs"
>>   (if (file-newer-than-file-p "~/.emacs" "~/.emacs.elc")
>>       (progn
>>      (setq byte-compile-warnings nil)
>>      (byte-compile-file "~/.emacs" t) ; Compile and load
>>      (setq byte-compile-warnings t)
>>      ;HALT - I need the loading of this file to halt and don't execute
>> anything else of this file
>>      )))
>> (compile-emacs-config-file)
>
> (error "~/.emacs compiled, load terminated")

Indeed, an error is a good way to break out of loading the current
file, but this is probably not what the OP wants.

I would suggest:

(defun compile-emacs-config-file ()
  "Compiles ~/.emacs
Returns: true if we did the compilation."
  (if (file-newer-than-file-p "~/.emacs" "~/.emacs.elc")
      (let ((byte-compile-warnings nil))
        (unwind-protect
             (progn (byte-compile-file "~/.emacs" t)
                    t)
          nil))
      nil))

(if (compile-emacs-config-file)
    (load "~/.emacs") ;; actually loads ~/.emacs.elc
    (progn

      ;; The rest of this file goes here.
      
      ))

You'll have to put all the contents of ~/.emacs in the else branch of
that if.


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

COMPONENT EQUIVALENCY NOTICE: The subatomic particles (electrons,
protons, etc.) comprising this product are exactly the same in every
measurable respect as those used in the products of other
manufacturers, and no claim to the contrary may legitimately be
expressed or implied.


reply via email to

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