From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Karl Fogel Newsgroups: gmane.emacs.devel Subject: [PATCH] Improve sorting in the bookmark list buffer. Date: Wed, 20 Apr 2022 13:09:26 -0500 Message-ID: <87zgkfbp9l.fsf_-_@red-bean.com> References: <875yovm1m6.fsf@elite.giraud> <87v8wvkk64.fsf@red-bean.com> <83v8wuj3v0.fsf@gnu.org> <87tucewgu7.fsf@red-bean.com> <83lexqi3z9.fsf@gnu.org> <87tuceuo4b.fsf@red-bean.com> <83czj2hrdv.fsf@gnu.org> <87a6e5lui6.fsf@elite.giraud> <837d99j10x.fsf@gnu.org> <874k4dlpeg.fsf@elite.giraud> <834k4divrt.fsf@gnu.org> <87wnh9k43g.fsf@elite.giraud> <83v8wth5lh.fsf@gnu.org> <87h78afndq.fsf@red-bean.com> <87zgm25d9o.fsf@elite.giraud> Reply-To: Karl Fogel Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="9783"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: Manuel Giraud To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Apr 20 20:52:41 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nhFRQ-0002Kt-QN for ged-emacs-devel@m.gmane-mx.org; Wed, 20 Apr 2022 20:52:41 +0200 Original-Received: from localhost ([::1]:34004 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nhFRP-0000gt-4V for ged-emacs-devel@m.gmane-mx.org; Wed, 20 Apr 2022 14:52:39 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:54558) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nhEli-00043G-Ol for emacs-devel@gnu.org; Wed, 20 Apr 2022 14:09:34 -0400 Original-Received: from sanpietro.red-bean.com ([45.79.25.59]:39762) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nhElg-0001dO-BE for emacs-devel@gnu.org; Wed, 20 Apr 2022 14:09:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=red-bean.com; s=202005newsp; h=Content-Type:MIME-Version:Message-ID: In-Reply-To:Date:Reply-To:References:Subject:Cc:To:From:Sender: Content-Transfer-Encoding:Content-ID:Content-Description; bh=/y9dHhmZHVVjkJ+qx+wT68jKp0xQVhuDEnNWkIAG+o8=; t=1650478170; x=1651687770; b=SPtbtkpzz6btqEfS8NX41Yhf+W0hCxhOCis7MrAEKeoiv1w2bSfAQXcX0PU7kvO9SD3AJQYtkJL yoGRUZNH7AMWsOCNYSsuQuYPr0WN2canOBd9noKKMEoJc1v0hyqRTIgeDhX5ixOD2L3J02HNK/V5s HJtzcq75awP5HzHA7NlhfL7Q9kKxMw42fMu2m8lov53hLyDRPaMqyQKzGpSpCrm8f8b/Uzs//D5bT 01srNLrQm0u3u0dlg43ygVGTv6RtN4uqjJsCp+95MXoslDGfxeaajy2M5hRPyeLk4NsQ0Gxj2Djs3 yxQMOUjMwZL5lbyrHxilPWHlgergV729wMeg==; Original-Received: from 99-112-125-163.lightspeed.cicril.sbcglobal.net ([99.112.125.163]:36448 helo=floss) by sanpietro.red-bean.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nhEla-00FtMZ-S3; Wed, 20 Apr 2022 18:09:27 +0000 In-Reply-To: <87zgm25d9o.fsf@elite.giraud> (Manuel Giraud's message of "Mon, 07 Mar 2022 10:21:23 +0100") Received-SPF: pass client-ip=45.79.25.59; envelope-from=kfogel@red-bean.com; helo=sanpietro.red-bean.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:288722 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable On 07 Mar 2022, Manuel Giraud wrote: >There is one minor thing left: the tabulated-list bar (I don't=20 >how it is >called) keep the old information =C2=AB sorted by bookmark name =C2=BB whe= n=20 >I have >revert to `bookmark-sort-flag' as nil. I looked more closely at the situation and came up with the=20 attached patch. The new behavior is a little complex, but I think=20 it's the right thing for most users: If `bookmark-sort-flag' is non-nil, which is the default, then the=20 bookmark list [1] will be sorted lexically (case-insensitively,=20 and in locale-dependent collation order). If `bookmark-sort-flag' is nil, then the list starts out sorted by=20 bookmark creation order, *but* clicking on the sort-control toggle=20 for the Bookmark Name column will sort the list lexically (and=20 toggling it changes the direction of that lexical sort each time).=20 However, you can use "g" (`revert-buffer') to refresh and thus go=20 right back to creation-order sort. Also, if you change the value=20 of `bookmark-sort-flag' and regenerate the buffer, via `g' or=20 otherwise, the sort will change accordingly, as one would expect. Note that there is no option to reverse the direction of creation=20 order sort: when sorting by creation order, it's always most=20 recent bookmark on top to least recent at bottom. I didn't see=20 any clear need for the reverse direction, and having the column=20 sort toggle behave in a familiar (lexical) way seemed much more=20 important. Review / feedback welcome. This is based against current 'master'=20 branch (commit 25308a95f8869c), but once it's been through review=20 I'll ask Eli which branch it should go on (or Eli if you want to=20 just say now that's fine too). Best regards, -Karl [1] That is, the buffer generated by `bookmark-bmenu-list'. --=-=-= Content-Type: text/plain Content-Disposition: attachment; filename=0001-Improve-sorting-in-the-bookmark-list-buffer.patch >From dd203d5bd936c1771e068a14f4d24a3921be4396 Mon Sep 17 00:00:00 2001 From: Karl Fogel Date: Wed, 20 Apr 2022 12:46:26 -0500 Subject: [PATCH] Improve sorting in the bookmark list buffer - Ensure that the bookmark bmenu buffer sorts when it should. - Sort case-insensitively and by locale-dependent collation order. - Rename "Bookmark" column to "Bookmark Name". - Coordinate that column's sort toggle and `bookmark-sort-flag'. - Document the new behavior. * lisp/bookmark.el (bookmark-bmenu--name-predicate, bookmark-bmenu--type-predicate, bookmark-bmenu--file-predicate): Use `string-collate-lessp' with IGNORE-CASE argument, instead of plain `string<'. (bookmark-bmenu--revert): Sort based on `bookmark-sort-flag'. (bookmark-bmenu-mode): Document the new behavior. Rename the "Bookmark" column to "Bookmark Name" for clarity & documentabilty. --- lisp/bookmark.el | 53 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 7 deletions(-) diff --git lisp/bookmark.el lisp/bookmark.el index 31876c83a2..6c46268a34 100644 --- lisp/bookmark.el +++ lisp/bookmark.el @@ -1824,7 +1824,29 @@ bookmark-bmenu--revert (list location))]) entries))) (tabulated-list-init-header) - (setq tabulated-list-entries (reverse entries))) + ;; The value of `bookmark-sort-flag' might have changed since the + ;; last time the buffer contents were generated, so re-check it. + (if bookmark-sort-flag + (progn + (setq tabulated-list-sort-key '("Bookmark Name" . nil)) + (setq tabulated-list-entries entries)) + (setq tabulated-list-sort-key nil) + ;; And since we're not sorting by bookmark name, show bookmarks + ;; according to order of creation, with the most recently + ;; created bookmarks at the top and the least recently created + ;; at the bottom. + ;; + ;; Note that clicking the column sort toggle for the bookmark + ;; name column will invoke the `tabulated-list-mode' sort, which + ;; uses `bookmark-bmenu--name-predicate' to sort lexically by + ;; bookmark name instead of by (reverse) creation order. + ;; Clicking the toggle again will reverse the lexical sort, but + ;; the sort will still be lexical not creation-order. However, + ;; if the user reverts the buffer, then the above check of + ;; `bookmark-sort-flag' will happen again and the buffer will + ;; go back to a creation-order sort. This is all expected + ;; behavior, as documented in `bookmark-bmenu-mode'. + (setq tabulated-list-entries (reverse entries)))) (tabulated-list-print t)) ;;;###autoload @@ -1868,6 +1890,18 @@ bookmark-bmenu-mode Each line describes one of the bookmarks in Emacs. Letters do not insert themselves; instead, they are commands. Bookmark names preceded by a \"*\" have annotations. + +If `bookmark-sort-flag' is non-nil, then sort the list by +bookmark name (case-insensitively, in collation order); the +direction of that sort can be reversed by using the column sort +toggle for the bookmark name column. + +If `bookmark-sort-flag' is nil, then sort the list by bookmark +creation order, with most recently created bookmarks on top. +However, the column sort toggle will still activate (and +thereafter toggle the direction of) lexical sorting by bookmark name. +At any time you may use \\[revert-buffer] to go back to sorting by creation order. + \\ \\[bookmark-bmenu-mark] -- mark bookmark to be displayed. \\[bookmark-bmenu-mark-all] -- mark all listed bookmarks to be displayed. @@ -1900,20 +1934,23 @@ bookmark-bmenu-mode in another buffer. \\[bookmark-bmenu-show-all-annotations] -- show the annotations of all bookmarks in another buffer. \\[bookmark-bmenu-edit-annotation] -- edit the annotation for the current bookmark. -\\[bookmark-bmenu-search] -- incrementally search for bookmarks." +\\[bookmark-bmenu-search] -- incrementally search for bookmarks. +\\[revert-buffer] -- refresh the buffer, and thus refresh the sort order (useful + if `bookmark-sort-flag' is nil)." (setq truncate-lines t) (setq buffer-read-only t) ;; FIXME: The header could also display the current default bookmark file ;; according to `bookmark-bookmarks-timestamp'. (setq tabulated-list-format `[("" 1) ;; Space to add "*" for bookmark with annotation - ("Bookmark" ,bookmark-bmenu-file-column bookmark-bmenu--name-predicate) + ("Bookmark Name" + ,bookmark-bmenu-file-column bookmark-bmenu--name-predicate) ("Type" 8 bookmark-bmenu--type-predicate) ,@(if bookmark-bmenu-toggle-filenames '(("File" 0 bookmark-bmenu--file-predicate)))]) (setq tabulated-list-padding bookmark-bmenu-marks-width) (when bookmark-sort-flag - (setq tabulated-list-sort-key '("Bookmark" . nil))) + (setq tabulated-list-sort-key '("Bookmark Name" . nil))) (add-hook 'tabulated-list-revert-hook #'bookmark-bmenu--revert nil t)' (setq revert-buffer-function 'bookmark-bmenu--revert) (tabulated-list-init-header)) @@ -1922,17 +1959,19 @@ bookmark-bmenu-mode (defun bookmark-bmenu--name-predicate (a b) "Predicate to sort \"*Bookmark List*\" buffer by the name column. This is used for `tabulated-list-format' in `bookmark-bmenu-mode'." - (string< (caar a) (caar b))) + (string-collate-lessp (caar a) (caar b) nil t)) (defun bookmark-bmenu--type-predicate (a b) "Predicate to sort \"*Bookmark List*\" buffer by the type column. This is used for `tabulated-list-format' in `bookmark-bmenu-mode'." - (string< (elt (cadr a) 2) (elt (cadr b) 2))) + (string-collate-lessp (elt (cadr a) 2) (elt (cadr b) 2) nil t)) (defun bookmark-bmenu--file-predicate (a b) "Predicate to sort \"*Bookmark List*\" buffer by the file column. This is used for `tabulated-list-format' in `bookmark-bmenu-mode'." - (string< (bookmark-location (car a)) (bookmark-location (car b)))) + (string-collate-lessp (bookmark-location (car a)) + (bookmark-location (car b)) + nil t)) (defun bookmark-bmenu-toggle-filenames (&optional show) -- 2.35.1 --=-=-=--