unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#20178: 24.3; Two feature requests for tabulated-list.el
@ 2015-03-23 10:57 Eli Barzilay
  2015-03-23 13:28 ` Stefan Monnier
  2020-10-19  0:26 ` Stefan Kangas
  0 siblings, 2 replies; 9+ messages in thread
From: Eli Barzilay @ 2015-03-23 10:57 UTC (permalink / raw)
  To: 20178


1. Truncating labels is done ATM with

       (truncate-string-to-width label width nil nil t)

   It would be nice if there was an option to choose the `ellipsis'
   argument.  (The code already deals with unicode, so IMO it makes
   sense to use "…" with an alternative of "-" in
   `tabulated-list-glyphless-char-display'.)

2. When I use `electric-buffer-list', if I happen to click on a column
   header it sorts the buffer according to that header, and it even
   makes that choice persistent.  That's nice, I guess, but there
   should be some way to go back to the default original order -- and
   maybe I'm missing something obvious, but I don't see any good way
   to do that.  (If I hit it by mistake, the only way I found to go
   back to the default is to quit the electric buffer, then use
   `list-buffers' to get it in plain mode, then kill it so that it
   gets recreated next time.)

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#20178: 24.3; Two feature requests for tabulated-list.el
  2015-03-23 10:57 bug#20178: 24.3; Two feature requests for tabulated-list.el Eli Barzilay
@ 2015-03-23 13:28 ` Stefan Monnier
  2015-03-23 14:12   ` Eli Barzilay
  2020-10-19  0:26 ` Stefan Kangas
  1 sibling, 1 reply; 9+ messages in thread
From: Stefan Monnier @ 2015-03-23 13:28 UTC (permalink / raw)
  To: Eli Barzilay; +Cc: 20178

> 1. Truncating labels is done ATM with

>        (truncate-string-to-width label width nil nil t)

>    It would be nice if there was an option to choose the `ellipsis'
>    argument.  (The code already deals with unicode, so IMO it makes
>    sense to use "…" with an alternative of "-" in
>    `tabulated-list-glyphless-char-display'.)

(setq truncate-string-ellipsis "…")


        Stefan





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#20178: 24.3; Two feature requests for tabulated-list.el
  2015-03-23 13:28 ` Stefan Monnier
@ 2015-03-23 14:12   ` Eli Barzilay
  2015-03-23 19:32     ` Stefan Monnier
  0 siblings, 1 reply; 9+ messages in thread
From: Eli Barzilay @ 2015-03-23 14:12 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: 20178

Oh, good...  Any estimates for the release of v25?

And I'm assuming that there's some way to change the subject of this bug
to reflect the second point -- or is it better to re-submit?


And semi-related, ebuff is full of problems around not turning itself
off when you switch outside -- enough that it makes me suspect that the
code is either not actively maintained or very active so things changed.
If this is incorrect, should I submit another bug?

On Mon, Mar 23, 2015 at 9:28 AM, Stefan Monnier
<monnier@iro.umontreal.ca> wrote:
>> 1. Truncating labels is done ATM with
>
>>        (truncate-string-to-width label width nil nil t)
>
>>    It would be nice if there was an option to choose the `ellipsis'
>>    argument.  (The code already deals with unicode, so IMO it makes
>>    sense to use "…" with an alternative of "-" in
>>    `tabulated-list-glyphless-char-display'.)
>
> (setq truncate-string-ellipsis "…")
>
>
>         Stefan



-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#20178: 24.3; Two feature requests for tabulated-list.el
  2015-03-23 14:12   ` Eli Barzilay
@ 2015-03-23 19:32     ` Stefan Monnier
  0 siblings, 0 replies; 9+ messages in thread
From: Stefan Monnier @ 2015-03-23 19:32 UTC (permalink / raw)
  To: Eli Barzilay; +Cc: 20178

> Oh, good...  Any estimates for the release of v25?

Some time before 2025.

> And semi-related, ebuff is full of problems around not turning itself
> off when you switch outside -- enough that it makes me suspect that the
> code is either not actively maintained or very active so things changed.
> If this is incorrect, should I submit another bug?

Not actively maintained is much closer to reality, IIUC,


        Stefan





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#20178: 24.3; Two feature requests for tabulated-list.el
  2015-03-23 10:57 bug#20178: 24.3; Two feature requests for tabulated-list.el Eli Barzilay
  2015-03-23 13:28 ` Stefan Monnier
@ 2020-10-19  0:26 ` Stefan Kangas
  2020-10-19  5:51   ` Eli Barzilay
  1 sibling, 1 reply; 9+ messages in thread
From: Stefan Kangas @ 2020-10-19  0:26 UTC (permalink / raw)
  To: Eli Barzilay; +Cc: 20178

Eli Barzilay <eli@barzilay.org> writes:

> 2. When I use `electric-buffer-list', if I happen to click on a column
>    header it sorts the buffer according to that header, and it even
>    makes that choice persistent.  That's nice, I guess, but there
>    should be some way to go back to the default original order -- and
>    maybe I'm missing something obvious, but I don't see any good way
>    to do that.  (If I hit it by mistake, the only way I found to go
>    back to the default is to quit the electric buffer, then use
>    `list-buffers' to get it in plain mode, then kill it so that it
>    gets recreated next time.)

Indeed.  So the default is to sort by whatever order `buffer-list'
happens to return them in.  Which can of course be useful.  But there is
no easy way to return to this sort order.

I'm not sure how easy this is to fix, but:

What is the expected behavior here?  Does it make sense to make `C-u S'
go back to the default sort order?  Or should perhaps a right click at
the relevant column header reset it?

(Note that `electric-buffer-list' is the same as `list-buffers' for our
purposes here.)





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#20178: 24.3; Two feature requests for tabulated-list.el
  2020-10-19  0:26 ` Stefan Kangas
@ 2020-10-19  5:51   ` Eli Barzilay
  2020-10-20  0:43     ` Stefan Kangas
  0 siblings, 1 reply; 9+ messages in thread
From: Eli Barzilay @ 2020-10-19  5:51 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: 20178

On Sun, Oct 18, 2020 at 8:26 PM Stefan Kangas <stefan@marxist.se> wrote:
>
> Eli Barzilay <eli@barzilay.org> writes:
>
> > 2. When I use `electric-buffer-list', if I happen to click on a column
> >    header it sorts the buffer according to that header, and it even
> >    makes that choice persistent.  That's nice, I guess, but there
> >    should be some way to go back to the default original order -- and
> >    maybe I'm missing something obvious, but I don't see any good way
> >    to do that.  (If I hit it by mistake, the only way I found to go
> >    back to the default is to quit the electric buffer, then use
> >    `list-buffers' to get it in plain mode, then kill it so that it
> >    gets recreated next time.)
>
> Indeed.  So the default is to sort by whatever order `buffer-list'
> happens to return them in.  Which can of course be useful.  But there is
> no easy way to return to this sort order.
>
> I'm not sure how easy this is to fix, but:

(TBH, I don't even remember the context -- I was maybe looking for a
replacement for `bs.el`.)


> What is the expected behavior here?  Does it make sense to make `C-u S'
> go back to the default sort order?  Or should perhaps a right click at
> the relevant column header reset it?

FWIW, I'd expect a click to go from nothing to ascending to descending
back to nothing.

> (Note that `electric-buffer-list' is the same as `list-buffers' for our
> purposes here.)

(Just tried `electric-buffer-list` again, it is broken in an amusing
way for me, where a click leads to some infinite loop that keeps the
window top following the mouse...)

-- 
                   ((x=>x(x))(x=>x(x)))                  Eli Barzilay:
                   http://barzilay.org/                  Maze is Life!





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#20178: 24.3; Two feature requests for tabulated-list.el
  2020-10-19  5:51   ` Eli Barzilay
@ 2020-10-20  0:43     ` Stefan Kangas
  2022-01-24 16:24       ` Lars Ingebrigtsen
  0 siblings, 1 reply; 9+ messages in thread
From: Stefan Kangas @ 2020-10-20  0:43 UTC (permalink / raw)
  To: Eli Barzilay; +Cc: 20178

[-- Attachment #1: Type: text/plain, Size: 1022 bytes --]

Eli Barzilay <eli@barzilay.org> writes:

>> What is the expected behavior here?  Does it make sense to make `C-u S'
>> go back to the default sort order?  Or should perhaps a right click at
>> the relevant column header reset it?
>
> FWIW, I'd expect a click to go from nothing to ascending to descending
> back to nothing.

Right.  But this would only be useful in certain buffers, so I'd suggest
this behavior to be optional.

The attached patch should do it.  Comments welcome.

(And as I'm about to send this, I realize that we would probably want
the same behavior also for the `tabulated-list-sort' command?  Either
for consecutive invocations or for the prefix argument.)

>> (Note that `electric-buffer-list' is the same as `list-buffers' for our
>> purposes here.)
>
> (Just tried `electric-buffer-list` again, it is broken in an amusing
> way for me, where a click leads to some infinite loop that keeps the
> window top following the mouse...)

Sounds like you have stumbled into a bug that should be reported?

[-- Attachment #2: 0001-Reset-sort-order-on-third-click-in-tabulated-list-mo.patch --]
[-- Type: text/x-diff, Size: 5535 bytes --]

From e5645e28bc49a6f9d8b3e98afcd300e050fb20e6 Mon Sep 17 00:00:00 2001
From: Stefan Kangas <stefan@marxist.se>
Date: Tue, 20 Oct 2020 02:15:51 +0200
Subject: [PATCH] Reset sort order on third click in tabulated-list-mode

* lisp/emacs-lisp/tabulated-list.el
(tabulated-list--sort-by-column-name): Optionally support resetting
the sort order on the third click on the same column
header.  (Bug#20178)
(tabulated-list-third-click-resets-sort): New buffer local variable to
control above new optional behavior.
(tabulated-list-print): Don't set tabulated-list-entries.  This is
necessary if we are to reset the sort order on the third click.
* doc/lispref/modes.texi (Tabulated List Mode): Document new variable.
* etc/NEWS: Announce it.

* lisp/buff-menu.el (Buffer-menu-mode): Set the variable
tabulated-list-third-click-resets-sort to a non-nil value.
---
 doc/lispref/modes.texi            |  7 +++++++
 etc/NEWS                          | 14 ++++++++++++++
 lisp/buff-menu.el                 |  1 +
 lisp/emacs-lisp/tabulated-list.el | 26 ++++++++++++++++++--------
 4 files changed, 40 insertions(+), 8 deletions(-)

diff --git a/doc/lispref/modes.texi b/doc/lispref/modes.texi
index 022eda0bec..d8a4367851 100644
--- a/doc/lispref/modes.texi
+++ b/doc/lispref/modes.texi
@@ -1150,6 +1150,13 @@ Tabulated List Mode
 to invert the sort order.
 @end defvar
 
+@defvar tabulated-list-third-click-resets-sort
+When this variable is non-nil, the third click on a column header will
+reset all sorting and return to the unsorted order for
+@code{tabulated-list-entries}.  The default behavior is to simply
+toggle between sorting in ascending and descending order.
+@end defvar
+
 @defun tabulated-list-init-header
 This function computes and sets @code{header-line-format} for the
 Tabulated List buffer (@pxref{Header Lines}), and assigns a keymap to
diff --git a/etc/NEWS b/etc/NEWS
index c571fa95d1..4402bdfdb4 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1420,6 +1420,20 @@ could have saved enough typing by using an abbrev, a hint will be
 displayed in the echo area, mentioning the abbrev that could have been
 used instead.
 
+** Tabulated List mode
+
++++
+*** Optionally support resetting sort order by clicking column header.
+Tabulated List mode now optionally supports resetting the sort order
+on the third click on a column header.  This is controlled by the new
+variable 'tabulated-list-third-click-resets-sort' that can be set by
+users, or in major modes by Emacs Lisp package authors that wish to
+enable this behavior.
+
+This new behavior is now enabled in Buffer Menu mode, used by commands
+'M-x list-buffers' and 'M-x electric-buffer-list', which now allows a
+user to return to the unsorted buffer order.
+
 \f
 * New Modes and Packages in Emacs 28.1
 
diff --git a/lisp/buff-menu.el b/lisp/buff-menu.el
index d06ba28787..938573683b 100644
--- a/lisp/buff-menu.el
+++ b/lisp/buff-menu.el
@@ -271,6 +271,7 @@ Buffer-menu-mode
 \\[Buffer-menu-bury]    Bury the buffer listed on this line."
   (set (make-local-variable 'buffer-stale-function)
        (lambda (&optional _noconfirm) 'fast))
+  (setq tabulated-list-third-click-resets-sort t)
   (add-hook 'tabulated-list-revert-hook 'list-buffers--refresh nil t))
 
 (defun buffer-menu (&optional arg)
diff --git a/lisp/emacs-lisp/tabulated-list.el b/lisp/emacs-lisp/tabulated-list.el
index b13f609f88..33038885f2 100644
--- a/lisp/emacs-lisp/tabulated-list.el
+++ b/lisp/emacs-lisp/tabulated-list.el
@@ -156,6 +156,12 @@ tabulated-list-sort-key
 non-nil, means to invert the resulting sort.")
 (put 'tabulated-list-sort-key 'permanent-local t)
 
+(defvar-local tabulated-list-third-click-resets-sort nil
+  "If non-nil, a third click on a column header resets the sort order.
+The default nil value means to just reverse the sort order when
+the same column header is clicked more than once.")
+(put 'tabulated-list-third-click-resets-sort 'permanent-local t)
+
 (defsubst tabulated-list-get-id (&optional pos)
   "Return the entry ID of the Tabulated List entry at POS.
 The value is an ID object from `tabulated-list-entries', or nil.
@@ -432,9 +438,7 @@ tabulated-list-print
                      (vertical-motion (buffer-size)))))))
     ;; Sort the entries, if necessary.
     (when sorter
-      (setq entries (sort entries sorter)))
-    (unless (functionp tabulated-list-entries)
-      (setq tabulated-list-entries entries))
+      (setq entries (sort (copy-sequence entries) sorter)))
     ;; Without a sorter, we have no way to just update.
     (when (and update (not sorter))
       (setq update nil))
@@ -662,11 +666,17 @@ tabulated-list-sort
 
 (defun tabulated-list--sort-by-column-name (name)
   (when (and name (derived-mode-p 'tabulated-list-mode))
-    ;; Flip the sort order on a second click.
-    (if (equal name (car tabulated-list-sort-key))
-	(setcdr tabulated-list-sort-key
-		(not (cdr tabulated-list-sort-key)))
-      (setq tabulated-list-sort-key (cons name nil)))
+    (cond
+     ;; Reset the order on a third click.
+     ((and tabulated-list-third-click-resets-sort
+           (equal (cons name t) tabulated-list-sort-key))
+      (setq tabulated-list-sort-key nil))
+     ;; Flip the sort order on a second click.
+     ((equal name (car tabulated-list-sort-key))
+      (setcdr tabulated-list-sort-key
+              (not (cdr tabulated-list-sort-key))))
+     ;; First click just sort by name.
+     ((setq tabulated-list-sort-key (cons name nil))))
     (tabulated-list-init-header)
     (tabulated-list-print t)))
 
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* bug#20178: 24.3; Two feature requests for tabulated-list.el
  2020-10-20  0:43     ` Stefan Kangas
@ 2022-01-24 16:24       ` Lars Ingebrigtsen
  2022-02-22 13:55         ` Lars Ingebrigtsen
  0 siblings, 1 reply; 9+ messages in thread
From: Lars Ingebrigtsen @ 2022-01-24 16:24 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: Eli Barzilay, 20178

Stefan Kangas <stefan@marxist.se> writes:

> (And as I'm about to send this, I realize that we would probably want
> the same behavior also for the `tabulated-list-sort' command?  Either
> for consecutive invocations or for the prefix argument.)

This was fixed in Emacs 28 -- `C-u - S' reverts back to the original
sort.

I've now added the `S' command to `electric-buffer-list', too.

> (tabulated-list-third-click-resets-sort): New buffer local variable to
> control above new optional behavior.

I'm not sure this would be used much -- does other things that sort
based on clicking the headers work this way?  But I don't oppose adding
it if it's something that'd be used.

Any opinions?

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#20178: 24.3; Two feature requests for tabulated-list.el
  2022-01-24 16:24       ` Lars Ingebrigtsen
@ 2022-02-22 13:55         ` Lars Ingebrigtsen
  0 siblings, 0 replies; 9+ messages in thread
From: Lars Ingebrigtsen @ 2022-02-22 13:55 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: Eli Barzilay, 20178

Lars Ingebrigtsen <larsi@gnus.org> writes:

>> (tabulated-list-third-click-resets-sort): New buffer local variable to
>> control above new optional behavior.
>
> I'm not sure this would be used much -- does other things that sort
> based on clicking the headers work this way?  But I don't oppose adding
> it if it's something that'd be used.
>
> Any opinions?

Nobody had an opinion here, and I my feeling is that this is something
that wouldn't be used a lot, so I'm closing this bug report.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-02-22 13:55 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-23 10:57 bug#20178: 24.3; Two feature requests for tabulated-list.el Eli Barzilay
2015-03-23 13:28 ` Stefan Monnier
2015-03-23 14:12   ` Eli Barzilay
2015-03-23 19:32     ` Stefan Monnier
2020-10-19  0:26 ` Stefan Kangas
2020-10-19  5:51   ` Eli Barzilay
2020-10-20  0:43     ` Stefan Kangas
2022-01-24 16:24       ` Lars Ingebrigtsen
2022-02-22 13:55         ` Lars Ingebrigtsen

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).