unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Philip Kaludercic <philipk@posteo.net>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: Richard Stallman <rms@gnu.org>, emacs-devel@gnu.org
Subject: Re: Proposal: Forwards-Compatibility Library for Emacs
Date: Wed, 22 Sep 2021 09:54:12 +0000	[thread overview]
Message-ID: <8735pxq6kb.fsf@posteo.net> (raw)
In-Reply-To: <87pmt1wor5.fsf@gnus.org> (Lars Ingebrigtsen's message of "Wed, 22 Sep 2021 00:24:46 +0200")

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Richard Stallman <rms@gnu.org> writes:
>
>>   > The idea is to allow developers who don't want to break backwards
>>   > compatibility to use newer functionality that wasn't provided in older
>>   > versions of Emacs. This version tries to implement as much as possible
>>   > from Emacs 24.2 onwards.
>>
>> Would you please state concretely what this package would do?

Functionality-wise: The package uses custom macros to define
"compatibility functions". A compatibility function implements at least
a subset of the behaviour the "real function" would provide, if it were
defined in whatever release of Emacs.

The macros it provides are:

- compat-defun

  Defines a compatibility function that is only aliased to the "real"
  symbol, if this is unbound and the specified version is greater than
  the current version. Example:

        (compat-defun always (&rest _arguments)
          "Do nothing and return t.
        This function accepts any number of ARGUMENTS, but ignores them.
        Also see `ignore'."
          :version "28.1"
          t)

  On Emacs 28.1 an newer, this just expands to `nil', because the plist
  after the documentation sting specifies that this function was defined
  in Emacs 28.1. Other attributes can be given such as part of what
  library this function was defined, so that it is wrapped in an
  eval-after-load body, preventing the developer from using the
  function, without loading the right library beforehand.
  
  Otherwise it defines

        (defun compat--always (&rest _)
          "[Compatibility function for `always', defined in Emacs 28.1]

        Do nothing and return t.
        This function accepts any number of ARGUMENTS, but ignores them.
        Also see `ignore'."
          t)

  followed by

        (unless (fboundp 'always)
          (defalias 'always #'compat-always))

- compat-macro

  Analogous to compat-defun, just for macros.

- compat-advise

  Defines an advice function that is then applied to wrap (ie. :around)
  the actual function. Example:

        (compat-advise sort (seq predicate)
          "Handle SEQ of type vector."
          :version "25.1"
          (cond
           ((listp seq)
            (funcall oldfun seq predicate))
           ((vectorp seq)
            (let ((cseq (sort (append seq nil) predicate)))
              (dotimes (i (length cseq))
                (setf (aref seq i) (nth i cseq)))
              (apply #'vector cseq)))
           ((signal 'wrong-type-argument 'list-or-vector-p))))

   Again, it defines a compat--sort function with the same body as
   compat-advise, and an additional argument "oldfun".

- compat-defvar

  Defines a variable, constant, buffer-local or permanent-local
  variable, again using a version attribute and boundp to check if it
  should do so.

I plan to add at least compat-defface, for defining faces that older
versions of Emacs didn't provide.

> The library defines versions of newer functions if Emacs doesn't already
> have them.  For instance, Emacs 28 has a new function
> 'buffer-local-boundp'.  Philip's library would provide a definition of
> functions like that for use in ELPA code that's written for newer Emacs
> versions, so that they can be used in older Emacs versions without
> introducing compatibility shims like `foo-package-buffer-local-boundp'.
>
> This also allows us to put (more) core packages into GNU ELPA without
> any code changes.

I am not sure if no-code-changes are always possible, but that would be
the best-case scenario.

>>   > By its very nature it is an intrusive package, as it defines functions,
>>   > macros and advice outside of the "namespace", but I don't see any way
>>   > around that if transparent compatibility is to be provided (anything
>>   > else would just replicate dash, s, f, ...).
>>
>> I have a plan to put those names into optional namespaces (using
>> symbol renaming) so that the entry points of those packages will
>> be visible only from packages that require specific libraries.
>
> Philip shouldn't have mentioned s and dash and the rest -- his proposal
> has absolutely nothing to do with those, but it seems like many people
> have lashed onto that part, somehow.

The reason I mentioned these libraries at all, is that for more than a
few package developers, I have noticed that they use these libraries for
the sake of convenience *and* backwards compatibility. As these
libraries are updated externally, they provide more easily usable
functionality that wasn't given in say Emacs 24.x. If they are
interested in convince and less repetitive programming, as I am sure
many are, they would have to choose between raising the minimal version
required to use their package or to add these external libraries.

My point in mentioning these was not to give a direct comparison, but
just to say that if compat.el didn't use transparent compatibility, it
would just become another utility function library -- just instead of
using a Clojure style of programming, it would stick to the more
traditional Elisp conventions.

-- 
	Philip Kaludercic



  reply	other threads:[~2021-09-22  9:54 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-20 23:35 Proposal: Forwards-Compatibility Library for Emacs Philip Kaludercic
2021-09-21  0:30 ` Adam Porter
2021-09-21  4:10 ` Lars Ingebrigtsen
2021-09-21  8:28   ` Philip Kaludercic
2021-09-21 12:31 ` Stefan Monnier
2021-09-21 12:40   ` Eli Zaretskii
2021-09-21 12:50     ` Stefan Kangas
2021-09-21 13:38       ` Arthur Miller
2021-09-21 13:49       ` João Távora
2021-09-21 13:00     ` Philip Kaludercic
2021-09-21 13:12       ` Eli Zaretskii
2021-09-21 13:28         ` Philip Kaludercic
2021-09-21 13:24     ` João Távora
2021-09-21 13:29       ` Philip Kaludercic
2021-09-21 13:50         ` João Távora
2021-09-21 14:59     ` Lars Ingebrigtsen
2021-09-21 12:58   ` Philip Kaludercic
2021-09-21 13:37     ` Arthur Miller
2021-09-21 13:54       ` Philip Kaludercic
2021-09-21 14:18         ` Arthur Miller
2021-09-21 15:02   ` Lars Ingebrigtsen
2021-09-21 15:40     ` João Távora
2021-09-21 16:10       ` Philip Kaludercic
2021-09-21 16:22         ` João Távora
2021-09-21 17:22       ` Lars Ingebrigtsen
2021-09-21 17:29         ` João Távora
2021-09-21 19:24     ` Stefan Monnier
2021-09-21 21:06       ` Philip Kaludercic
2021-09-21 21:50         ` Stefan Monnier
2021-09-22  6:48           ` Philip Kaludercic
2021-09-22 17:53             ` Stefan Monnier
2021-09-22 18:54               ` Philip Kaludercic
2021-09-22 19:15                 ` Stefan Monnier
2021-09-21 21:57       ` Lars Ingebrigtsen
2021-09-21 22:08         ` João Távora
2021-09-21 22:16           ` Lars Ingebrigtsen
2021-09-21 22:24             ` João Távora
2021-09-21 22:25               ` Lars Ingebrigtsen
2021-09-21 22:34                 ` João Távora
2021-09-22  6:53           ` Philip Kaludercic
2021-09-22  7:12             ` João Távora
2021-09-22  7:14         ` Arthur Miller
2021-09-21 13:05 ` Philip Kaludercic
2021-09-21 13:27 ` Arthur Miller
2021-09-21 13:45   ` Philip Kaludercic
2021-09-21 14:05     ` Arthur Miller
2021-09-21 22:17 ` Richard Stallman
2021-09-21 22:24   ` Lars Ingebrigtsen
2021-09-22  9:54     ` Philip Kaludercic [this message]
2021-10-04 23:00 ` [ELPA] Add compat.el Philip Kaludercic
2021-10-07  7:03   ` Old (static) builds of Emacs Philip Kaludercic
2021-10-07  7:48     ` Michael Albinus
2021-10-07  7:56       ` Philip Kaludercic
2021-10-07 12:49     ` Stefan Monnier
2021-10-07 20:29       ` Philip Kaludercic
2021-10-07 21:21         ` Stefan Monnier
2021-11-30 21:21     ` Philip Kaludercic
2021-12-01 13:15       ` Stefan Monnier
2021-10-07 20:49   ` [ELPA] Add compat.el Philip Kaludercic
2021-10-08  5:56     ` Eli Zaretskii
2021-10-08  9:59       ` Philip Kaludercic
2021-10-08 11:10         ` Eli Zaretskii
2021-10-08 11:35           ` Philip Kaludercic
2021-10-08  7:45     ` Mattias Engdegård
2021-10-08 10:00       ` Philip Kaludercic
2021-10-15 19:08   ` Philip Kaludercic

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=8735pxq6kb.fsf@posteo.net \
    --to=philipk@posteo.net \
    --cc=emacs-devel@gnu.org \
    --cc=larsi@gnus.org \
    --cc=rms@gnu.org \
    /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).