use-package icon indicating copy to clipboard operation
use-package copied to clipboard

:ensure only if the package is not in load-path

Open yisraeldov opened this issue 6 years ago • 3 comments

There maybe a way to do this already but. I use the global

  (setq use-package-always-ensure t)

But I have some packages that I have forked and cloned and manually added to my load-path.

     (let ((libpaths (directory-files
		      (concat user-emacs-directory (convert-standard-filename "lib/")) t
		      directory-files-no-dot-files-regexp))
	   libpath)
       (dolist (libpath libpaths)
	 (if (file-directory-p libpath)
	     (push libpath load-path)
	     )))

Is there a way to have use-package only try to install the package if it isn't found in the load path ? Most of my packages are from package.el , but the ones that are not it should be able to pick them up and not try to install. It seems that if I manually set :load-path it doesn't do ensure, but I don't want to do that every time.

yisraeldov avatar Jun 17 '19 06:06 yisraeldov

Yeah, I came up with a solution for this exact scenario, before I switched over to straight.el as my package manager.

The way I did was by setting default handlers to both :load-path and :ensure keywords in use-package-defaults:

(eval-and-compile
  (defun local-package-load-path (name)
    (concat user-emacs-directory (format "lib/%s" (symbol-name name)))))

(setf (alist-get :load-path use-package-defaults)
      '((list (local-package-load-path name))
        (file-directory-p (local-package-load-path name))))

(setf (alist-get :ensure use-package-defaults)
      '(t (and (not (locate-library (symbol-name name)))
               (not (file-directory-p (local-package-load-path name))))))

Essentially it boils down to if a library is found in .emacs.d/lib/<package-name>, use that load path to load the package, otherwise :ensure it. You can always override this handling on a per-package level too. No need to set use-package-always-ensure to t either.

waymondo avatar Jun 17 '19 14:06 waymondo

Thanks. How is straight.el I was thinking about switching as well.

On Mon, Jun 17, 2019 at 5:36 PM justin talbott [email protected] wrote:

Yeah, I came up with a solution for this exact scenario, before I switched over to straight.el https://github.com/raxod502/straight.el as my package manager.

The way I did was by setting default handlers to both :load-path and :ensure keywords in use-package-defaults:

(eval-and-compile (defun local-package-load-path (name) (concat user-emacs-directory (format "lib/%s" (symbol-name name)))))

(setf (alist-get :load-path use-package-defaults) '((list (local-package-load-path name)) (file-directory-p (local-package-load-path name))))

(setf (alist-get :ensure use-package-defaults) '(t (and (not (locate-library (symbol-name name))) (not (file-directory-p (local-package-load-path name))))))

Essentially it boils down to if a library is found in .emacs.d/lib/, use that load path to load the package, otherwise :ensure it. You can always override this handling on a per-package level too. No need to set use-package-always-ensure to t either.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jwiegley/use-package/issues/776?email_source=notifications&email_token=AABBX26PMXQCCOLS22QZDX3P26ONPA5CNFSM4HYTTOCKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODX3L2UQ#issuecomment-502709586, or mute the thread https://github.com/notifications/unsubscribe-auth/AABBX23A3FFQQF5L6QXBVH3P26ONPANCNFSM4HYTTOCA .

yisraeldov avatar Jun 17 '19 14:06 yisraeldov

It's been great for me. I really like how it allows you to install packages directly from git sources, which removed my personal need for the config I shared above. It integrates well with use-package too.

waymondo avatar Jun 17 '19 16:06 waymondo