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

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

Re: using use-package


From: Sebastien Vauban
Subject: Re: using use-package
Date: Tue, 11 Aug 2015 11:20:11 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (windows-nt)

address@hidden (Phillip Lord) writes:
> Stefan Monnier <address@hidden> writes:
>> Or to take another example from https://github.com/jwiegley/use-package:
>>
>>    (use-package foo
>>      :init
>>      (setq foo-variable t)
>>      :config
>>      (foo-mode 1))
>>
>> For any properly written foo-mode, the above can be replaced with
>>
>>      (setq foo-variable t)
>>      (foo-mode 1)
>>
>> and it should work just as well.
>
> No, you are missing (several) points of use-package. First (and
> trivially) the use-package statement groups everything syntactically.
> So, it's more like:
>
> (progn
>   (setq foo-variable t)
>   (foo-mode 1))
>
> This is nicer because it groups all the configuration together, so you
> can move, comment, delete or eval it all together. Of course, `progn'
> achieves the same thing.
>
> However, `use-package' also gives you configurable feedback on load
> times. So if (require 'foo) takes a long time, use-package tells you,
> and tells you how long it takes.
>
> In your example,
>
> (foo-mode 1)
>
> will force an autoload. With use-package, also I can do
>
> (use-package foo
>   :defer t
>   ;;;etc
>   )
>
> which will achieve the same.

Just wanted to share how I do *some* of the above points in my config
file. Here an example for `diff-hl', which indicates changes in the
fringe:

--8<---------------cut here---------------start------------->8---
  (with-eval-after-load "diff-hl-autoloads"
  
    (idle-require 'diff-hl))

  (with-eval-after-load "diff-hl"

    (global-diff-hl-mode)

    (define-key diff-hl-mode-map (kbd "C-x v >") 'diff-hl-next-hunk)
    (define-key diff-hl-mode-map (kbd "C-x v <") 'diff-hl-previous-hunk))
--8<---------------cut here---------------end--------------->8---

This is somehow trying to achieve (part of) the same goals as
`use-package', but with standard Emacs (more or less, as `idle-require'
is not in core).

You see:

- Differed load via the idle-require' package (otherwise, I just write
  "require")

- Nice grouping of all customizations at the same place,

To disable it, I'll edit the code and add "-XXX" in the first
`with-eval-after-load':

--8<---------------cut here---------------start------------->8---
  (with-eval-after-load "diff-hl-autoloads-XXX" ; Diff-hl won't be req'ed

    (idle-require 'diff-hl))
--8<---------------cut here---------------end--------------->8---

Of course, I miss, for example, the real execution time of that block,
once executed/loaded (and you can't advice a macro such as
`with-eval-after-load', right, to add timings?).

And I do have all ELPA paths in `load-path' unlike John (IIUC), though
I don't understand yet how it works (differently) with `use-package'.

Interested by comments...

Best regards,
  Seb

-- 
Sebastien Vauban


reply via email to

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