* bug#50704: Feature request: Add ensure-list in cl-lib
@ 2021-09-20 19:43 Clément Pit-Claudel
2021-09-20 21:05 ` Lars Ingebrigtsen
0 siblings, 1 reply; 5+ messages in thread
From: Clément Pit-Claudel @ 2021-09-20 19:43 UTC (permalink / raw)
To: 50704
Hi all,
There are 40+ instances of the following code pattern in Emacs' code base, and many more in packages:
(if (listp x) x (list x))
It's easy to find single-line instances of it using the regexp [(]if [(]listp .*[(]list .
This pattern is called "ensure-list" in CL:
(defun ensure-list (thing)
"Returns THING as a list.
If THING is already a list (as per listp) it is returned,
otherwise a one element list containing THING is returned."
(if (listp thing)
thing
(list thing)))
I would like to add a similar function in Emacs, since it comes up so often. Is that an acceptable change?
If so:
- Which cl-*.el file should it go into, and where in that file?
- Should it be a defun or a define-inline?
- And once it is introduced, should the 40-some instances that could use it be updated, or left as-is?
- Finally, where should it be documented?
Cheers,
Clément.
^ permalink raw reply [flat|nested] 5+ messages in thread
* bug#50704: Feature request: Add ensure-list in cl-lib
2021-09-20 19:43 bug#50704: Feature request: Add ensure-list in cl-lib Clément Pit-Claudel
@ 2021-09-20 21:05 ` Lars Ingebrigtsen
2021-09-21 15:29 ` Stefan Kangas
0 siblings, 1 reply; 5+ messages in thread
From: Lars Ingebrigtsen @ 2021-09-20 21:05 UTC (permalink / raw)
To: Clément Pit-Claudel; +Cc: 50704
Clément Pit-Claudel <cpitclaudel@gmail.com> writes:
> I would like to add a similar function in Emacs, since it comes up so often. Is that an acceptable change?
>
> If so:
> - Which cl-*.el file should it go into, and where in that file?
I don't think it has to be in cl at all -- we can just call it
`ensure-list'.
> - Should it be a defun or a define-inline?
> - And once it is introduced, should the 40-some instances that could use it be updated, or left as-is?
> - Finally, where should it be documented?
defun, depends, and in the list section. :-)
--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no
^ permalink raw reply [flat|nested] 5+ messages in thread
* bug#50704: Feature request: Add ensure-list in cl-lib
2021-09-20 21:05 ` Lars Ingebrigtsen
@ 2021-09-21 15:29 ` Stefan Kangas
2021-09-21 18:31 ` Lars Ingebrigtsen
0 siblings, 1 reply; 5+ messages in thread
From: Stefan Kangas @ 2021-09-21 15:29 UTC (permalink / raw)
To: Lars Ingebrigtsen; +Cc: 50704, Clément Pit-Claudel
Lars Ingebrigtsen <larsi@gnus.org> writes:
> I don't think it has to be in cl at all -- we can just call it
> `ensure-list'.
+1
>> - And once it is introduced, should the 40-some instances that could use it be updated, or left as-is?
To expand on what Lars said, they can (IMO should) be updated unless
they need to be compatible with old versions of Emacs.
(I would add a comment to the other instances along the lines of "change
to `ensure-list' once Emacs 27.1 compatibility is dropped".)
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-09-21 18:43 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-09-20 19:43 bug#50704: Feature request: Add ensure-list in cl-lib Clément Pit-Claudel
2021-09-20 21:05 ` Lars Ingebrigtsen
2021-09-21 15:29 ` Stefan Kangas
2021-09-21 18:31 ` Lars Ingebrigtsen
2021-09-21 18:43 ` Clément Pit-Claudel
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.