unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@posteo.net>
To: emacs-devel@gnu.org
Cc: Max Nikulin <manikulin@gmail.com>
Subject: [FR] Provide a way to activate packages automatically for side effect
Date: Wed, 01 May 2024 10:20:09 +0000	[thread overview]
Message-ID: <87zft9esva.fsf@localhost> (raw)

Hello,

The very first suggestion in D.1 Emacs Lisp Coding Conventions is to
avoid side effects when loading a library:

   • Simply loading a package should not change Emacs's editing
     behavior.  Include a command or commands to enable and disable the
     feature, or to invoke it.

The request not to change editing experience is reasonable, but it is
sometimes hard to draw a line when side effects of the loading should be
separated into an explicit command/function users have to run/add to the
config.

For example, when a package defines a new major mode, it is common to
modify `auto-mode-alist' by merely having such package installed.
This is technically a change in Emacs's editing behavior.

Another example is when a package adds new features to an existing
functionality, like ert.el where mere (require 'ert) changes
fontification in emacs-lisp-mode buffers:
(add-hook 'emacs-lisp-mode-hook #'ert--activate-font-lock-keywords)

If one follows "Lisp Coding Conventions" explicitly, the above examples
can be seen as breaking the conventions.
On the other hand, it is very clear that autoloading a major mode is
justified because otherwise why would user install the relevant package?

Similar argument can be made for changing the fontification rules in
ert.el - if ert library is loaded _by the user_, it is very clear that
the erc.el features, including fontification, are going to be useful.

The situation is not so clear when a library is autoloaded by the means
of building completion list (`help-enable-completion-autoload') - side
effects in such case may be surprising to the user who merely wanted to
read some obscure docstring.

May it be possible to introduce an alternative way to load
packages/libraries other than `require' with an intention to be used as
a part of user config?

What I have in mind is something like
(enable-package 'name) that will (1) load the package without side
effects; (2) "enable" the package, producing useful side effects
intended for interactive use.

Further, (use-package name) can be modified to automatically run
(enable-package 'name); and package.el can be modified to mark packages
installed explicitly (via M-x package-install or other interactive
means) to be automatically "enabled" after loading (add (eval-after-load
'name (enable-package 'name).

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>



             reply	other threads:[~2024-05-01 10:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-01 10:20 Ihor Radchenko [this message]
2024-05-01 14:41 ` [External] : [FR] Provide a way to activate packages automatically for side effect Drew Adams
2024-05-01 16:11   ` Ihor Radchenko
2024-05-01 19:07     ` Drew Adams

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.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87zft9esva.fsf@localhost \
    --to=yantar92@posteo.net \
    --cc=emacs-devel@gnu.org \
    --cc=manikulin@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.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).