unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* How to delay loading of packages (when eval-after-load does not apply)?
@ 2012-08-15 19:22 Sebastien Vauban
  2012-08-15 19:43 ` How to delay loading of packages (when eval-after-load does notapply)? Drew Adams
       [not found] ` <mailman.7059.1345059803.855.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 10+ messages in thread
From: Sebastien Vauban @ 2012-08-15 19:22 UTC (permalink / raw)
  To: help-gnu-emacs-mXXj517/zsQ

Hello,

In the sake of trying to load my .emacs in less than 20-25 seconds (the
current situation), I'm trying to optimize when things must be loaded.

For example, to save time, I want the fuzzy package to be loaded when it will
be needed for the first time.

The only way I found was:

#+begin_src emacs-lisp
   ;; fuzzy matching utilities (a must-have)
   (when (locate-library "fuzzy")
     (eval-after-load "isearch"
       '(progn
          (require 'fuzzy)
          (turn-on-fuzzy-isearch))))
#+end_src

... but, as isearch must be loaded internally (where?) at startup, my
eval-after-load is useless in fact: fuzzy is loaded as well at startup time.

How could I say: load fuzzy when I will make a search for the first time?

Best regards,
  Seb

-- 
Sebastien Vauban


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

* RE: How to delay loading of packages (when eval-after-load does notapply)?
  2012-08-15 19:22 How to delay loading of packages (when eval-after-load does not apply)? Sebastien Vauban
@ 2012-08-15 19:43 ` Drew Adams
       [not found] ` <mailman.7059.1345059803.855.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 10+ messages in thread
From: Drew Adams @ 2012-08-15 19:43 UTC (permalink / raw)
  To: 'Sebastien Vauban', help-gnu-emacs

> How could I say: load fuzzy when I will make a search for the 
> first time?

Try `isearch-mode-hook' with `require'.




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

* Re: How to delay loading of packages (when eval-after-load does notapply)?
       [not found] ` <mailman.7059.1345059803.855.help-gnu-emacs@gnu.org>
@ 2012-08-17 10:07   ` Sebastien Vauban
  2012-08-17 10:31     ` Raffaele Ricciardi
  0 siblings, 1 reply; 10+ messages in thread
From: Sebastien Vauban @ 2012-08-17 10:07 UTC (permalink / raw)
  To: help-gnu-emacs-mXXj517/zsQ

Hi Drew,

"Drew Adams" wrote:
>> How could I say: load fuzzy when I will make a search for the 
>> first time?
>
> Try `isearch-mode-hook' with `require'.

Did you mean this?

--8<---------------cut here---------------start------------->8---
  ;; fuzzy matching utilities (a must-have)
  (add-hook 'isearch-mode-hook
            #'(lambda ()
                (require 'fuzzy)))

  (eval-after-load "fuzzy"
    (turn-on-fuzzy-isearch))
--8<---------------cut here---------------end--------------->8---

I did the above, restarted Emacs and got:

  Symbol's function definition is void: turn-on-fuzzy-isearch

I don't understand why my `eval-after-load' is executed directly...

Am I missing something?

Best regards,
  Seb

PS- BTW, is there a better choice to be made between

--8<---------------cut here---------------start------------->8---
  (add-hook 'isearch-mode-hook
            #'(lambda () ...
--8<---------------cut here---------------end--------------->8---

and

--8<---------------cut here---------------start------------->8---
  (add-hook 'isearch-mode-hook
            (lambda () ...
--8<---------------cut here---------------end--------------->8---

?

-- 
Sebastien Vauban


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

* Re: How to delay loading of packages (when eval-after-load does notapply)?
  2012-08-17 10:07   ` Sebastien Vauban
@ 2012-08-17 10:31     ` Raffaele Ricciardi
  2012-08-17 12:11       ` Sebastien Vauban
  0 siblings, 1 reply; 10+ messages in thread
From: Raffaele Ricciardi @ 2012-08-17 10:31 UTC (permalink / raw)
  To: help-gnu-emacs

On 08/17/2012 11:07 AM, Sebastien Vauban wrote:
 > Hi Drew,
 >
 > "Drew Adams" wrote:
 >>> How could I say: load fuzzy when I will make a search for the
 >>> first time?
 >>
 >> Try `isearch-mode-hook' with `require'.
 >
 > Did you mean this?
 >
 > --8<---------------cut here---------------start------------->8---
 >    ;; fuzzy matching utilities (a must-have)
 >    (add-hook 'isearch-mode-hook
 >              #'(lambda ()
 >                  (require 'fuzzy)))
 >
 >    (eval-after-load "fuzzy"
 >      (turn-on-fuzzy-isearch))
 > --8<---------------cut here---------------end--------------->8---
 >
 > I did the above, restarted Emacs and got:
 >
 >    Symbol's function definition is void: turn-on-fuzzy-isearch
 >
 > I don't understand why my `eval-after-load' is executed directly...
 >
 > Am I missing something?

You have to quote the form you are passing to `eval-after-load', like this:

(eval-after-load "fuzzy"
   '(turn-on-fuzzy-isearch))

Otherwise, yes, the form is evaluated on the spot.  This one bit me a 
couple of
times as well ;-)

Also, "fuzzy" means eval the following form after the library "fuzzy" 
has been
loaded, whilst 'fuzzy means eval the following code after the feature 
'fuzzy has
been provided.  I always go for the latter first, because then I'm able to
rename a library according to its version.  I would only backpedal if the
library provided its feature on top of the file as some third-party 
libraries do
- AFAIK this was a workaround for older Emacsen - and I couldn't fix 
that, but
the latter has never happened.

 >
 > Best regards,
 >    Seb
 >
 > PS- BTW, is there a better choice to be made between
 >
 > --8<---------------cut here---------------start------------->8---
 >    (add-hook 'isearch-mode-hook
 >              #'(lambda () ...
 > --8<---------------cut here---------------end--------------->8---
 >
 > and
 >
 > --8<---------------cut here---------------start------------->8---
 >    (add-hook 'isearch-mode-hook
 >              (lambda () ...
 > --8<---------------cut here---------------end--------------->8---
 >
 > ?
 >

AFAIK, they mean the same thing.  I always use the latter, for I think 
`lambda'
is verbose enough already ;-)



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

* Re: How to delay loading of packages (when eval-after-load does notapply)?
  2012-08-17 10:31     ` Raffaele Ricciardi
@ 2012-08-17 12:11       ` Sebastien Vauban
  2012-08-17 12:20         ` Raffaele Ricciardi
  0 siblings, 1 reply; 10+ messages in thread
From: Sebastien Vauban @ 2012-08-17 12:11 UTC (permalink / raw)
  To: help-gnu-emacs-mXXj517/zsQ

Hi Raffaele and Drew,

Raffaele Ricciardi wrote:
> On 08/17/2012 11:07 AM, Sebastien Vauban wrote:
>> "Drew Adams" wrote:
>>>> How could I say: load fuzzy when I will make a search for the
>>>> first time?
>>>
>>> Try `isearch-mode-hook' with `require'.
>>
>> I got:
>>
>>    Symbol's function definition is void: turn-on-fuzzy-isearch
>>
>> I don't understand why my `eval-after-load' is executed directly...
>
> You have to quote the form you are passing to `eval-after-load', like this:
>
> (eval-after-load "fuzzy"
>   '(turn-on-fuzzy-isearch))
>
> Otherwise, yes, the form is evaluated on the spot.

Excellent. That did the trick... Thanks a lot!

> Also, "fuzzy" means eval the following form after the library "fuzzy" has
> been loaded, whilst 'fuzzy means eval the following code after the feature
> 'fuzzy has been provided. I always go for the latter first, because then I'm
> able to rename a library according to its version. I would only backpedal if
> the library provided its feature on top of the file as some third-party
> libraries do - AFAIK this was a workaround for older Emacsen - and I couldn't
> fix that, but the latter has never happened.

Thanks for the comments...

Now, wanting to apply the same mechanism for other slow parts of my .emacs
file, I'm stuck with this one[1]:

--8<---------------cut here---------------start------------->8---
   ;; add the ability to copy or cut the current line without marking it
   ;; (no active region) -- idea stolen from SlickEdit
   (defadvice kill-ring-save (before slickcopy activate compile)
     "When called interactively with no active region, copy the current
   line instead."
     (interactive
      (if mark-active (list (region-beginning) (region-end))
        (message "Copied the current line")
        (list (line-beginning-position)
              (line-beginning-position 2)))))

   (defadvice kill-region (before slickcut activate compile)
     "When called interactively with no active region, kill the current
   line instead."
     (interactive
      (if mark-active (list (region-beginning) (region-end))
        (list (line-beginning-position)
              (line-beginning-position 2)))))
--8<---------------cut here---------------end--------------->8---

How could I say: apply the following when I will press `C-w' or `M-w' for the
first time?

I search for hooks in `simple.el', but only found

- activate-mark-hook
- deactivate-mark-hook

which are not exactly what I need.

Any idea?

Best regards,
  Seb

--
Sebastien Vauban

[1] As already reported here (see
http://lists.gnu.org/archive/html/help-gnu-emacs/2012-08/msg00092.html), that
chunk of code takes around 2 seconds to execute, at Emacs startup time.


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

* Re: How to delay loading of packages (when eval-after-load does notapply)?
  2012-08-17 12:11       ` Sebastien Vauban
@ 2012-08-17 12:20         ` Raffaele Ricciardi
  2012-08-17 18:33           ` Sebastien Vauban
  0 siblings, 1 reply; 10+ messages in thread
From: Raffaele Ricciardi @ 2012-08-17 12:20 UTC (permalink / raw)
  To: help-gnu-emacs

On 08/17/2012 01:11 PM, Sebastien Vauban wrote:
 > Now, wanting to apply the same mechanism for other slow parts of my 
.emacs
 > file, I'm stuck with this one[1]:
 >
 > --8<---------------cut here---------------start------------->8---
 >     ;; add the ability to copy or cut the current line without marking it
 >     ;; (no active region) -- idea stolen from SlickEdit
 >     (defadvice kill-ring-save (before slickcopy activate compile)
 >       "When called interactively with no active region, copy the current
 >     line instead."
 >       (interactive
 >        (if mark-active (list (region-beginning) (region-end))
 >          (message "Copied the current line")
 >          (list (line-beginning-position)
 >                (line-beginning-position 2)))))
 >
 >     (defadvice kill-region (before slickcut activate compile)
 >       "When called interactively with no active region, kill the current
 >     line instead."
 >       (interactive
 >        (if mark-active (list (region-beginning) (region-end))
 >          (list (line-beginning-position)
 >                (line-beginning-position 2)))))
 > --8<---------------cut here---------------end--------------->8---
 >

See http://www.emacswiki.org/emacs/WholeLineOrRegion

Note the use of `use-region-p' instead of 'mark-active'.


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

* Re: How to delay loading of packages (when eval-after-load does notapply)?
  2012-08-17 12:20         ` Raffaele Ricciardi
@ 2012-08-17 18:33           ` Sebastien Vauban
  2012-08-20 12:40             ` Sebastien Vauban
  0 siblings, 1 reply; 10+ messages in thread
From: Sebastien Vauban @ 2012-08-17 18:33 UTC (permalink / raw)
  To: help-gnu-emacs-mXXj517/zsQ

Hi Raffaele,

Raffaele Ricciardi wrote:
> On 08/17/2012 01:11 PM, Sebastien Vauban wrote:
>> Now, wanting to apply the same mechanism for other slow parts of my .emacs
>> file, I'm stuck with this one[1]:
>>
>> --8<---------------cut here---------------start------------->8---
>>     ;; add the ability to copy or cut the current line without marking it
>>     ;; (no active region) -- idea stolen from SlickEdit
>>     (defadvice kill-ring-save (before slickcopy activate compile)
>>       "When called interactively with no active region, copy the current
>>     line instead."
>>       (interactive
>>        (if mark-active (list (region-beginning) (region-end))
>>          (message "Copied the current line")
>>          (list (line-beginning-position)
>>                (line-beginning-position 2)))))
>>
>>     (defadvice kill-region (before slickcut activate compile)
>>       "When called interactively with no active region, kill the current
>>     line instead."
>>       (interactive
>>        (if mark-active (list (region-beginning) (region-end))
>>          (list (line-beginning-position)
>>                (line-beginning-position 2)))))
>> --8<---------------cut here---------------end--------------->8---
>
> See http://www.emacswiki.org/emacs/WholeLineOrRegion
>
> Note the use of `use-region-p' instead of 'mark-active'.

I don't understand all the subtleties, except that it uses a function directly
defined in `simple.el', but it does a great job: no noticeable delay!

Thanks a lot.

Best regards,
Seb

-- 
Sebastien Vauban


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

* Re: How to delay loading of packages (when eval-after-load does notapply)?
  2012-08-17 18:33           ` Sebastien Vauban
@ 2012-08-20 12:40             ` Sebastien Vauban
  2012-08-20 13:39               ` Raffaele Ricciardi
  0 siblings, 1 reply; 10+ messages in thread
From: Sebastien Vauban @ 2012-08-20 12:40 UTC (permalink / raw)
  To: help-gnu-emacs-mXXj517/zsQ

Hi Raffaele,

"Sebastien Vauban" wrote:
> Raffaele Ricciardi wrote:
>> On 08/17/2012 01:11 PM, Sebastien Vauban wrote:
>>> Now, wanting to apply the same mechanism for other slow parts of my .emacs
>>> file, I'm stuck with this one[1]:
>>>
>>> --8<---------------cut here---------------start------------->8---
>>>     ;; add the ability to copy or cut the current line without marking it
>>>     ;; (no active region) -- idea stolen from SlickEdit
>>>     (defadvice kill-ring-save (before slickcopy activate compile)
>>>       "When called interactively with no active region, copy the current
>>>     line instead."
>>>       (interactive
>>>        (if mark-active (list (region-beginning) (region-end))
>>>          (message "Copied the current line")
>>>          (list (line-beginning-position)
>>>                (line-beginning-position 2)))))
>>>
>>>     (defadvice kill-region (before slickcut activate compile)
>>>       "When called interactively with no active region, kill the current
>>>     line instead."
>>>       (interactive
>>>        (if mark-active (list (region-beginning) (region-end))
>>>          (list (line-beginning-position)
>>>                (line-beginning-position 2)))))
>>> --8<---------------cut here---------------end--------------->8---
>>
>> See http://www.emacswiki.org/emacs/WholeLineOrRegion
>>
>> Note the use of `use-region-p' instead of 'mark-active'.
>
> I don't understand all the subtleties, except that it uses a function directly
> defined in `simple.el', but it does a great job: no noticeable delay!

After using it for a couple of "workable" hours, I must say that the code
found on EmacsWiki does not work as good (at least from my point of view) as
the code above.

Two (minor) problems found:

- With the above code, when killing multiple subsequent lines, they are merged
  as one entry in the kill ring.

  With the code from EW, they stay separate entries.

- With the above code, I can paste the "copied line" wherever I want,
  including in the middle of a line:

    Some *sentence                (* = position of point)

  becomes:

    Some YANKED TEXT*sentence

  With the code from EW, the yanked text is inserted above the current line,
  as if point was at the beginning of line when I'm yanking.

    Some *sentence                (* = position of point)

  becomes:

    YANKED TEXT
    *Some sentence

  BTW, point's position is changed after yanking.

Do you observe that as well?

Best regards,
  Seb

-- 
Sebastien Vauban


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

* Re: How to delay loading of packages (when eval-after-load does notapply)?
  2012-08-20 12:40             ` Sebastien Vauban
@ 2012-08-20 13:39               ` Raffaele Ricciardi
  2012-08-20 15:24                 ` Sebastien Vauban
  0 siblings, 1 reply; 10+ messages in thread
From: Raffaele Ricciardi @ 2012-08-20 13:39 UTC (permalink / raw)
  To: help-gnu-emacs

(global-set-key (kbd "C-w")
On 20/08/12 13:40, Sebastien Vauban wrote:
 > Hi Raffaele,
 >
 > "Sebastien Vauban" wrote:
 >> Raffaele Ricciardi wrote:
 >>> On 08/17/2012 01:11 PM, Sebastien Vauban wrote:
 >>>> Now, wanting to apply the same mechanism for other slow parts of 
my .emacs
 >>>> file, I'm stuck with this one[1]:
 >>>>
 >>>> --8<---------------cut here---------------start------------->8---
 >>>>      ;; add the ability to copy or cut the current line without 
marking it
 >>>>      ;; (no active region) -- idea stolen from SlickEdit
 >>>>      (defadvice kill-ring-save (before slickcopy activate compile)
 >>>>        "When called interactively with no active region, copy the 
current
 >>>>      line instead."
 >>>>        (interactive
 >>>>         (if mark-active (list (region-beginning) (region-end))
 >>>>           (message "Copied the current line")
 >>>>           (list (line-beginning-position)
 >>>>                 (line-beginning-position 2)))))
 >>>>
 >>>>      (defadvice kill-region (before slickcut activate compile)
 >>>>        "When called interactively with no active region, kill the 
current
 >>>>      line instead."
 >>>>        (interactive
 >>>>         (if mark-active (list (region-beginning) (region-end))
 >>>>           (list (line-beginning-position)
 >>>>                 (line-beginning-position 2)))))
 >>>> --8<---------------cut here---------------end--------------->8---
 >>>
 >>> See http://www.emacswiki.org/emacs/WholeLineOrRegion
 >>>
 >>> Note the use of `use-region-p' instead of 'mark-active'.
 >>
 >> I don't understand all the subtleties, except that it uses a 
function directly
 >> defined in `simple.el', but it does a great job: no noticeable delay!
 >
 > After using it for a couple of "workable" hours, I must say that the code
 > found on EmacsWiki does not work as good (at least from my point of 
view) as
 > the code above.
 >
 > Two (minor) problems found:
 >
 > - With the above code, when killing multiple subsequent lines, they 
are merged
 >    as one entry in the kill ring.
 >
 >    With the code from EW, they stay separate entries.
 >
 > - With the above code, I can paste the "copied line" wherever I want,
 >    including in the middle of a line:
 >
 >      Some *sentence                (* = position of point)
 >
 >    becomes:
 >
 >      Some YANKED TEXT*sentence
 >
 >    With the code from EW, the yanked text is inserted above the 
current line,
 >    as if point was at the beginning of line when I'm yanking.
 >
 >      Some *sentence                (* = position of point)
 >
 >    becomes:
 >
 >      YANKED TEXT
 >      *Some sentence
 >
 >    BTW, point's position is changed after yanking.
 >
 > Do you observe that as well?

I don't use those commands.  I knew about that EmacsWiki page, so I told 
you.

Well, go back to your original functions, then, after replacing 
`mark-active' with
`use-region-p'.

However, using advices is overkill for what you are trying to 
accomplish.  Since
you are looking for an improved version of existing commands, the cleanest
approach is to wrap such commands as new commands and then replace the 
existing
key bindings, like this:

(defun rr-region-or-line (&optional ^verbose)
   "Return region, or current line instead if no region is active."
   (if (use-region-p)
       (list (region-beginning) (region-end))
       (when ^verbose
         (message "Copied the current line"))
       (list (line-beginning-position)
             (line-beginning-position 2))))

(defun rr-kill-ring-save (^start ^end)
   "When called interactively with no active region, copy the current
       line instead."
   (interactive (rr-region-or-line t))
   (kill-ring-save ^start ^end))

(defun rr-kill-region (^start ^end)
   "When called interactively with no active region, kill the current
       line instead."
   (interactive (rr-region-or-line))
   (kill-region ^start ^end))


Cheers.


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

* Re: How to delay loading of packages (when eval-after-load does notapply)?
  2012-08-20 13:39               ` Raffaele Ricciardi
@ 2012-08-20 15:24                 ` Sebastien Vauban
  0 siblings, 0 replies; 10+ messages in thread
From: Sebastien Vauban @ 2012-08-20 15:24 UTC (permalink / raw)
  To: help-gnu-emacs-mXXj517/zsQ

Hi Raffaele,

Raffaele Ricciardi wrote:
> On 20/08/12 13:40, Sebastien Vauban wrote:
>> "Sebastien Vauban" wrote:
>>> Raffaele Ricciardi wrote:
>>>> On 08/17/2012 01:11 PM, Sebastien Vauban wrote:
>>>>> Now, wanting to apply the same mechanism for other slow parts of 
>>>>> my .emacs file, I'm stuck with this one[1]:
>>>>>
>>>>> --8<---------------cut here---------------start------------->8---
>>>>>      ;; add the ability to copy or cut the current line without 
>>>>>      ;; marking it (no active region) -- idea stolen from SlickEdit
>>>>>      (defadvice kill-ring-save (before slickcopy activate compile)
>>>>>        "When called interactively with no active region, copy the 
>>>>> current line instead."
>>>>>        (interactive
>>>>>         (if mark-active (list (region-beginning) (region-end))
>>>>>           (message "Copied the current line")
>>>>>           (list (line-beginning-position)
>>>>>                 (line-beginning-position 2)))))
>>>>>
>>>>>      (defadvice kill-region (before slickcut activate compile)
>>>>>        "When called interactively with no active region, kill the 
>>>>> current line instead."
>>>>>        (interactive
>>>>>         (if mark-active (list (region-beginning) (region-end))
>>>>>           (list (line-beginning-position)
>>>>>                 (line-beginning-position 2)))))
>>>>> --8<---------------cut here---------------end--------------->8---
>>>>
>>>> See http://www.emacswiki.org/emacs/WholeLineOrRegion
>>>>
>>>> Note the use of `use-region-p' instead of 'mark-active'.
>>
>> After using it for a couple of "workable" hours, I must say that the code
>> found on EmacsWiki does not work as good (at least from my point of 
>> view) as the code above.
>>
>> Two (minor) problems found:
>>
>> - With the above code, when killing multiple subsequent lines, they 
>>   are merged as one entry in the kill ring.
>>
>> - With the above code, I can paste the "copied line" wherever I want,
>>   including in the middle of a line:
>
> I don't use those commands.  I knew about that EmacsWiki page, so I told you.

OK. Thanks for helping, anyway.

> Well, go back to your original functions, then, after replacing `mark-active'
> with `use-region-p'.

That does work well, functionally, but then I'm back with around 2 seconds of
load time. So, there must be something else there which causes the load of
many, many packages.

> However, using advices is overkill for what you are trying to accomplish.
> Since you are looking for an improved version of existing commands, the
> cleanest approach is to wrap such commands as new commands and then replace
> the existing key bindings

Why are you saying that defadvice is overkill?  Not performant?  Not advised?

What about redefining the functions without the defadvice?

Best regards,
  Seb

-- 
Sebastien Vauban


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

end of thread, other threads:[~2012-08-20 15:24 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-15 19:22 How to delay loading of packages (when eval-after-load does not apply)? Sebastien Vauban
2012-08-15 19:43 ` How to delay loading of packages (when eval-after-load does notapply)? Drew Adams
     [not found] ` <mailman.7059.1345059803.855.help-gnu-emacs@gnu.org>
2012-08-17 10:07   ` Sebastien Vauban
2012-08-17 10:31     ` Raffaele Ricciardi
2012-08-17 12:11       ` Sebastien Vauban
2012-08-17 12:20         ` Raffaele Ricciardi
2012-08-17 18:33           ` Sebastien Vauban
2012-08-20 12:40             ` Sebastien Vauban
2012-08-20 13:39               ` Raffaele Ricciardi
2012-08-20 15:24                 ` Sebastien Vauban

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).