unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#940: Is there a way to quit loading of ~/.emacs please?
@ 2008-09-09  6:50 Yiyi Hu
  2008-09-09 13:52 ` Juanma Barranquero
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Yiyi Hu @ 2008-09-09  6:50 UTC (permalink / raw)
  To: emacs-pretest-bug

Hi, all. For now, I got a problem on how to do this.

Here is the sample ~/.emacs

(defun byte-compile-file-if-newer (src)
  (let ((result (concat src ".elc")))
    (when (file-newer-than-file-p src result)
      (byte-compile-file src)
      (load-file result))))

(byte-compile-file-if-newer "~/.emacs")

(custom-set-variables
  ;; custom-set-variables was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(auto-compression-mode t)
 '(column-number-mode t)
 '(cperl-indent-level 4)
 '(delete-selection-mode t)
 '(display-battery-mode t)
 '(display-time-24hr-format t)
 '(display-time-day-and-date t)
 '(display-time-mode t)
 '(encoded-kbd-mode t)
 '(gnus-nntp-server "news.readfreenews.net")
 '(indent-tabs-mode nil)
 '(inferior-lisp-program "sbcl")
 '(inhibit-eol-conversion t)
 '(inhibit-startup-screen t)
 '(initial-scratch-message nil)
 '(menu-bar-mode nil)
 '(mouse-avoidance-mode (quote exile) nil (avoid)))

Is there a way to quit the loading after we compile the ~/.emacs and
load the ~/.emacs.elc file?

Ok, please don't bother talking about It's worthy or not for compiling
~/.emacs, I am talking a feature which *should* be supported by elisp
IMHO.

Yes, we can have a big condition around the rest of the ~/.emacs, But
that's not good practise. And If I do this, It will also confuse
things in M-x customize-group.

It's a bit like 'if' statements in emacs, 'if' is enough, but 'when'
and 'cond' statements is still there for supporting programming more
practically.

Also, I've ever done considering split ~/.emacs. To me, It's not a
good journey. There will be other problem when manage multiple start
up file.

I've tried add (return) to ~/.emacs, But there will be error as It's
not in a defun.

So, other possibility to quit the load of lib? Or enhance elisp by
adding a new 'keyword' or 'statement' to do this kind of job.

I also tried with (signal 'error nil) and (keyboard-quit), This worked
when you invoke emacs without any args. But when there is no
~/.emacs.elc file, and you invoke emacs with args, The passing args
won't be process by emacs.

I am using the newest emacs-cvs BTW.

Thanks.






^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#940: Is there a way to quit loading of ~/.emacs please?
  2008-09-09  6:50 bug#940: Is there a way to quit loading of ~/.emacs please? Yiyi Hu
@ 2008-09-09 13:52 ` Juanma Barranquero
  2008-09-09 14:19 ` Lennart Borgman (gmail)
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Juanma Barranquero @ 2008-09-09 13:52 UTC (permalink / raw)
  To: Yiyi Hu, 940

On Tue, Sep 9, 2008 at 08:50, Yiyi Hu <yiyihu@gmail.com> wrote:
> Is there a way to quit the loading after we compile the ~/.emacs and
> load the ~/.emacs.elc file?

If you can modify site-start.el, you can use something similar to this
code, which compiles the init source file only when the .elc exists
and is stale, or compiled with a newer Emacs (which could easily cause
trouble).

;; site-start.el
;;
(catch 'init-file
  (dolist (source-file '("~/.emacs.el" "~/.emacs" ;; ~/.emacs.elc
                         "~/_emacs.el" "~/_emacs" ;; ~/_emacs.elc (if
on Windows)
                         "~/.emacs.d/init.el"))   ;; ~/.emacs.d/init.elc
    (when (file-exists-p source-file)
      (require 'bytecomp)
      (let ((byte-file (byte-compile-dest-file source-file)))
        (unless (file-exists-p byte-file) (throw 'init-file nil))
        (when (or (time-less-p (nth 5 (file-attributes byte-file))
                               (nth 5 (file-attributes source-file)))
                  (with-temp-buffer
                    (insert-file-contents-literally byte-file nil 0 5)
                    (and (looking-at ";ELC")
                         (> (char-after 5) emacs-major-version))))
          (let* ((split-width-threshold nil) ;; 23.1+
                 (window (display-buffer (get-buffer-create "*Compile-Log*"))))
            (fit-window-to-buffer window)
            (set-window-dedicated-p window t)
            (unwind-protect
                 (or (byte-compile-file source-file)
                     (y-or-n-p-with-timeout
                      (format "Error bytecompiling %s; do you want to
load it? " source-file)
                      10 nil)
                     (setq init-file-user nil))
              (fit-window-to-buffer window)))))

 Juanma






^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#940: Is there a way to quit loading of ~/.emacs please?
  2008-09-09  6:50 bug#940: Is there a way to quit loading of ~/.emacs please? Yiyi Hu
  2008-09-09 13:52 ` Juanma Barranquero
@ 2008-09-09 14:19 ` Lennart Borgman (gmail)
  2008-09-09 18:24   ` Yiyi Hu
  2008-09-09 14:52 ` Stefan Monnier
  2011-10-04 19:31 ` Glenn Morris
  3 siblings, 1 reply; 9+ messages in thread
From: Lennart Borgman (gmail) @ 2008-09-09 14:19 UTC (permalink / raw)
  To: Yiyi Hu, 940

Yiyi Hu wrote:
> (byte-compile-file-if-newer "~/.emacs")
...
> Is there a way to quit the loading after we compile the ~/.emacs and
> load the ~/.emacs.elc file?
> 
> Ok, please don't bother talking about It's worthy or not for compiling
> ~/.emacs, I am talking a feature which *should* be supported by elisp
> IMHO.


There are many ways to do similar things and it is a bit hard to
understand what you really want. I can't imagine that it is the
behaviour you specified that you really want, or?

A simple way to do something similar is of course just to split .emacs.






^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#940: Is there a way to quit loading of ~/.emacs please?
  2008-09-09  6:50 bug#940: Is there a way to quit loading of ~/.emacs please? Yiyi Hu
  2008-09-09 13:52 ` Juanma Barranquero
  2008-09-09 14:19 ` Lennart Borgman (gmail)
@ 2008-09-09 14:52 ` Stefan Monnier
  2011-10-04 19:31 ` Glenn Morris
  3 siblings, 0 replies; 9+ messages in thread
From: Stefan Monnier @ 2008-09-09 14:52 UTC (permalink / raw)
  To: Yiyi Hu; +Cc: emacs-pretest-bug, 940

> Is there a way to quit the loading after we compile the ~/.emacs and
> load the ~/.emacs.elc file?

Of course:

 (defun byte-compile-file-if-newer (src)
   (let ((result (concat src ".elc")))
     (when (file-newer-than-file-p src result)
       (byte-compile-file src)
       (load-file result)
       t)))

 (unless (byte-compile-file-if-newer "~/.emacs")
   ... the rest of your .emacs...
   )


-- Stefan






^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#940: Is there a way to quit loading of ~/.emacs please?
  2008-09-09 14:19 ` Lennart Borgman (gmail)
@ 2008-09-09 18:24   ` Yiyi Hu
  2008-09-09 22:10     ` Lennart Borgman (gmail)
       [not found]     ` <18631.27735.100063.263157@kahikatea.snap.net.nz>
  0 siblings, 2 replies; 9+ messages in thread
From: Yiyi Hu @ 2008-09-09 18:24 UTC (permalink / raw)
  To: Lennart Borgman (gmail); +Cc: 940

This is not a bug, Just a feature request for elisp language.
Ok, thanks for your replies, I'll explain this is *great* detail.

What I want to do is simple:
When emacs starts, It checks if ~/.emacs is newer than ~/.emacs.elc,
if it does, then it recompiles the ~/.emacs, and load ~/.emacs.elc on
the fly. But skip the rest of ~/.emacs, The reason why I want this
will be explained.
Here the story begins:

If I do something like:
 (if (byte-compile-file-if-newer "~/.emacs") (load-file "~/.emacs.elc"))
Here is a situation depends on wether ~/.emacs.elc exists.
If ~/.emacs.elc exists and ever being compiled with a line (defalias
'perl-mode 'cperl-mode), and we remove
(defalias 'perl-mode 'cperl-mode) in ~/.emacs, then, cperl-mode will
still be in effect for the first time we start emacs use the new
~/.emacs, we have to restart emacs again or manually byte-compile the
~/.emacs. The reason which causes this is, the side effect created in
old ~/.emacs.elc will still in effect.

Why not use 'unless' statement version?
 (unless (byte-compile-file-if-newer "~/.emacs")
remaining lisp code ...)
Because, This will confuse M-x customize-* series functions.
Eg, when you put (customize-set-variables ....) things within (unless
(byte-compile-file-if-newer "~/.emacs") )
When you do M-x customzie-variable <RET> again, It will crate another
list which is like (customize-set-variables ...) outside of the file
level (unless () ...) statement. If you think It's ok, Please check
the example above. (customize-set-variables ..) will take effect and
last a session.

Why not splitting ~/.emacs?
I did this, and It's not a happy journey. Eg, when change something, I
have to think wether I should put here or there, or within ~/.emacs.
At last, I choose using one ~/.emacs, Also, even if we split ~/.emacs,
we still need to recompiling ~/.emacs after we do customize-variable.
That's why I think the problem still exists.

I ever used (signal 'quit nil) to skiping loading the rest of
~/.emacs, It works fine except the time when we invoke emacs with file
name args. (signal 'quit nil) will cancel loading of files we
specified in args.

In fact, This is not a bug, Just a elisp language feature request.
Hope if we can have a function named (leave-load t) which we can
manually control when to stop loading the lisp source file.

How this function is used is as below:

 (if (byte-compile-file-if-newer "~/.emacs")
     (load-file "~/.emacs")
     (leave-load t))

Then, the ~/.emacs.elc will always be populated, and processed. To me,
this is almost the _perfect_ version for auto byte-compile and loading
for ~/.emacs. :-)

And this language feature IMO, is useful for people who want to
control the library loading process.
If you have any questions, don't hesitate, I've been thinking on how
to make ~/.emacs auto re-compiling procedure perfect for 3 days.

Thanks for reading.  ;-)






^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#940: Is there a way to quit loading of ~/.emacs please?
  2008-09-09 18:24   ` Yiyi Hu
@ 2008-09-09 22:10     ` Lennart Borgman (gmail)
  2008-09-09 23:45       ` Yiyi Hu
       [not found]     ` <18631.27735.100063.263157@kahikatea.snap.net.nz>
  1 sibling, 1 reply; 9+ messages in thread
From: Lennart Borgman (gmail) @ 2008-09-09 22:10 UTC (permalink / raw)
  To: Yiyi Hu; +Cc: 940

Yiyi Hu wrote:
> Why not use 'unless' statement version?
>  (unless (byte-compile-file-if-newer "~/.emacs")
> remaining lisp code ...)
> Because, This will confuse M-x customize-* series functions.

Just set custom-file to store customizations in another file.

> Why not splitting ~/.emacs?
> I did this, and It's not a happy journey. Eg, when change something, I
> have to think wether I should put here or there, or within ~/.emacs.

Not if you just put everything there.

But the main question is: Why do you want to compile absolutely
everything? I feel there must be some misunderstanding somewhere. How
much time to you win?

How many times do you start Emacs? I think most users just start Emacs
one they boot their computer.






^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#940: Is there a way to quit loading of ~/.emacs please?
  2008-09-09 22:10     ` Lennart Borgman (gmail)
@ 2008-09-09 23:45       ` Yiyi Hu
  0 siblings, 0 replies; 9+ messages in thread
From: Yiyi Hu @ 2008-09-09 23:45 UTC (permalink / raw)
  To: Lennart Borgman (gmail); +Cc: 940

The reason I request this feature is just trying to make elisp and
emacs more flexible.
With this or without this feature won't hurt emacs' perfections in my mind.
What I want is, if we can make best get better.

Compile ~/.emacs won't take much time, even I do byte-compile-file
within emacs, and bind it to a key doesn't spend much. It doesn't hurt
either when press this key every time I want to compile ~/.emacs. But
this is not the perfect sollution, The perfect sollution should be,
let computer do what we want.

You still have to specify custom-file within ~/.emacs and split
~/.emacs, don't you?
For ~/.emacs, I ever have really big ~/.emacs.d, because of copying
every interesting into ~/.emacs.d, and load it within ~/.emacs, As
time goes, It grew beyond my control, I can find what I want to change
easily. So, I choose to use only one ~/.emacs for better
maintainablity, and let ~/.emacs to compile itself on demand.

You didn't misunderstand anything, You just don't understand why
people sometimes will like to stick in polar direction. :-)

On Wed, Sep 10, 2008 at 6:10 AM, Lennart Borgman (gmail)
<lennart.borgman@gmail.com> wrote:
> Yiyi Hu wrote:
>> Why not use 'unless' statement version?
>>  (unless (byte-compile-file-if-newer "~/.emacs")
>> remaining lisp code ...)
>> Because, This will confuse M-x customize-* series functions.
>
> Just set custom-file to store customizations in another file.
>
>> Why not splitting ~/.emacs?
>> I did this, and It's not a happy journey. Eg, when change something, I
>> have to think wether I should put here or there, or within ~/.emacs.
>
> Not if you just put everything there.
>
> But the main question is: Why do you want to compile absolutely
> everything? I feel there must be some misunderstanding somewhere. How
> much time to you win?
>
> How many times do you start Emacs? I think most users just start Emacs
> one they boot their computer.
>






^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#940: Is there a way to quit loading of ~/.emacs please?
       [not found]     ` <18631.27735.100063.263157@kahikatea.snap.net.nz>
@ 2008-09-10  7:53       ` Yiyi Hu
  0 siblings, 0 replies; 9+ messages in thread
From: Yiyi Hu @ 2008-09-10  7:53 UTC (permalink / raw)
  To: Nick Roberts; +Cc: 940

Oh, sorry, I followed emacswiki and it says using M-x report-emacs-bug
<RET> is enough.
I'll write there.

thanks.

On Wed, Sep 10, 2008 at 2:42 PM, Nick Roberts <nickrob@snap.net.nz> wrote:
> Yiyi Hu writes:
>  > This is not a bug, Just a feature request for elisp language.
>  > Ok, thanks for your replies, I'll explain this is *great* detail.
>
> In that case could you use help-gnu-emacs instead of making a bug report
> which creates an unnecaessary audit trail.
>
> --
> Nick                                           http://www.inet.net.nz/~nickrob
>






^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#940: Is there a way to quit loading of ~/.emacs please?
  2008-09-09  6:50 bug#940: Is there a way to quit loading of ~/.emacs please? Yiyi Hu
                   ` (2 preceding siblings ...)
  2008-09-09 14:52 ` Stefan Monnier
@ 2011-10-04 19:31 ` Glenn Morris
  3 siblings, 0 replies; 9+ messages in thread
From: Glenn Morris @ 2011-10-04 19:31 UTC (permalink / raw)
  To: Yiyi Hu; +Cc: 940

tags 940 wontfix
close 940
stop

"Yiyi Hu" wrote:

> Is there a way to quit the loading after we compile the ~/.emacs and
> load the ~/.emacs.elc file?

I understand what you are asking for (it's not just "load ~/.emacs.elc
if newer", which is bug#2577), but I don't see a need for such a
feature.





^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2011-10-04 19:31 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-09  6:50 bug#940: Is there a way to quit loading of ~/.emacs please? Yiyi Hu
2008-09-09 13:52 ` Juanma Barranquero
2008-09-09 14:19 ` Lennart Borgman (gmail)
2008-09-09 18:24   ` Yiyi Hu
2008-09-09 22:10     ` Lennart Borgman (gmail)
2008-09-09 23:45       ` Yiyi Hu
     [not found]     ` <18631.27735.100063.263157@kahikatea.snap.net.nz>
2008-09-10  7:53       ` Yiyi Hu
2008-09-09 14:52 ` Stefan Monnier
2011-10-04 19:31 ` Glenn Morris

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).