From: "João Pedro de Amorim Paula" <jpedrodeamorim@gmail.com>
To: Tim Cross <theophilusx@gmail.com>, emacs-orgmode@gnu.org
Subject: Re: Suggestion: convert dispatchers to use transient
Date: Sat, 05 Feb 2022 17:18:47 -0300 [thread overview]
Message-ID: <87iltt6p94.fsf@gmail.com> (raw)
In-Reply-To: <87wnibr5hq.fsf@gmail.com>
On 04 February 2022 08:30, Tim Cross <theophilusx@gmail.com> wrote:
> I'm assuming it is, but I have to admit I'm still not 100% clear on
> how Emacs handles the situation where you use a library that is both
> built-in and available in ELPA. Does Emacs use the latest version
> available or does it use the built-in version until you explicitly
> select the ELPA versions?
Welp, I happened to ponder the same question after trying to implement a
function to install packages that are not installed already (I'm not
using any helper configuration such as use-package, which would already
handle this). From what I gathered empirically, it appears that if
something is built-in, Emacs' package.el won't try to install -- it
checks with package-installed-p on any call to package-install, which
checks if the package is built-in with package-built-in-p as a fallback
on cond --, but you can force installation from the archives by passing
a package description object (defined as package-desc on package.el)
instead of a symbol
(let ((pkg-desc (assq 'org package-archive-contents)))
(package-install pkg-desc))
and Emacs seems to be loading the newest version when it is a dependency
of something else. Though I'm not really sure, as most of the packages I
have from ELPA have the same version as the ones built-in on Emacs
28.0.91. I'll try and install Emacs 27 to check this out.
In the mean time, I guess this would be a good opportunity to share a
couple of functions I have with the purpose of installing packages.
(defun pkg-description (package)
"Return the description for PACKAGE.
If PACKAGE is installed, the will be present on `package-alist',
otherwise look for it in `package-archive-contents'."
(or (cadr (assoc package package-alist))
(cadr (assoc package package-archive-contents))))
(defun pkg-ensure-archive (package)
"Install PACKAGE from the archives, if not already installed."
(when-let ((pkg-desc (pkg-description package)))
(unless (package-installed-p pkg-desc)
(package-install-from-archive pkg-desc))))
(defun require-package (package &optional force)
"Ensure that PACKAGE is installed.
If FORCE is non-nil, force installation regardless if PACKAGE is
built-in or not.
First, use `package-installed-p' to check if PACKAGE was
installed via the Emacs package manager, otherwise, try to
`require' PACKAGE; this ensures that we don't require PACKAGE if
it was installed using the package manager. If both of those
fail, run `package-refresh-contents' and install PACKAGE."
(unless (and (not force)
(or (package-installed-p package)
(require package nil 'no-error)))
(unless (assoc package package-archive-contents)
(package-refresh-contents))
(if force
(pkg-ensure-archive package)
(package-install package))))
On the last one, the main function that I use, if FORCE is non-nil it
will download and install the package from the archives even if it is
built-in.
Best regards,
--
João Pedro de Amorim Paula
IT undergraduate at Universidade Federal do Rio Grande do Norte (UFRN)
next prev parent reply other threads:[~2022-02-05 20:27 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-02 11:59 Suggestion: convert dispatchers to use transient Hugo Heagren
2022-02-03 8:54 ` Tom Gillespie
2022-02-03 10:07 ` Tim Cross
2022-02-03 17:51 ` Jim Porter
2022-02-03 21:30 ` Tim Cross
2022-02-04 1:13 ` Jim Porter
2022-02-04 5:37 ` Christopher M. Miles
2022-02-05 20:18 ` João Pedro de Amorim Paula [this message]
2022-02-06 1:49 ` Samuel Wales
2022-02-06 3:28 ` João Pedro de Amorim Paula
2022-02-07 15:37 ` Anders Johansson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87iltt6p94.fsf@gmail.com \
--to=jpedrodeamorim@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=theophilusx@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.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).