emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Extend tabulated-list-mode to support marks


From: Yuri Khan
Subject: Extend tabulated-list-mode to support marks
Date: Sat, 25 Jul 2020 02:00:30 +0700

On Fri, 24 Jul 2020 at 22:05, Stefan Monnier <monnier@iro.umontreal.ca> wrote:

> > and (2) if maybe tabulated-list-mode would benefit from a generic
> > implementation of multiple marking, unmarking, marking-for-deletion,
> > and command application.
>
> Maybe "for deletion" is too application-specific (some uses of
> `tabulated-list-mode` can't "delete" or at least not conveniently enough
> that it's a common use case), but a definite +1 for the rest.

My point is that there are many instances of a generic scenario:
Display a list of items; enable the user to perform operations on a
single item at point or to mark multiple items and operate on them as
a subset. Currently, each mode derived from ‘tabulated-list-mode’ has
to reimplement marking, unmarking, mark preservation over refresh,
iterating over marked items, and fallback to the item at point when no
marks are set. One high-visible derived mode hijacks the “unmark all”
key for “mark upgradable packages”. I think they would benefit from a
common implementation and the unification of the UI stemming from
that.


One possibility would be for a derived mode to set some buffer-local
variables to inform ‘tabulated-list-mode’ which marks it supports.
E.g.:

* Set ‘tabulated-list-delete-function’ to a non-nil function that will
delete the item at point or signal an error. Then the command bound to
‘D’ will invoke that function and remove its visual representation
from the buffer; ‘d’ will mark the item at point for deletion; ‘x’
will go through all the items marked for deletion and actually delete
and remove them; ‘u’ will unmark the item at point; and ‘U’ will
unmark all items.

* Set ‘tabulated-list-marks’ to a string of characters. If that string
contains ‘>’, ‘m’ will mark the item at point with ‘>’. Other marks
listed in the string can be set by the derived mode binding a key to a
function that will call (tabulated-list-set-mark CHAR). ‘u’ and ‘U’
will unmark the item at point or all items, respectively. A helper
function, (tabulated-list-map CHAR FUNC), will execute FUNC on each
item marked CHAR or on the item at point if no items are marked,
optionally removing the item or unmarking it depending on FUNC’s
return value; this can be invoked in any commands bound in the derived
mode keymap.


I might implement something if this general direction is deemed
desirable. Details can be discussed.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]