unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Manuel Giraud <manuel@ledu-giraud.fr>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: Drew Adams <drew.adams@oracle.com>,  emacs-devel <emacs-devel@gnu.org>
Subject: Re: [External] : [emacs bookmark.el] Sorting by last set
Date: Wed, 25 May 2022 15:18:04 +0200	[thread overview]
Message-ID: <87k0a93g4z.fsf@elite.giraud> (raw)
In-Reply-To: <87o7zngcgf.fsf@gnus.org> (Lars Ingebrigtsen's message of "Tue, 24 May 2022 17:46:56 +0200")

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

Lars Ingebrigtsen <larsi@gnus.org> writes:

[...]

> I think sorting by last set sounds like a nice feature -- patches
> welcome.

Here is a patch that does just that.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-sort-bookmark-alist-in-last-modified-order-by-defaul.patch --]
[-- Type: text/x-patch, Size: 5455 bytes --]

From 85834e973413b4ab050923d1dca4f0b4341d9b04 Mon Sep 17 00:00:00 2001
From: Manuel Giraud <manuel@ledu-giraud.fr>
Date: Wed, 25 May 2022 15:13:17 +0200
Subject: [PATCH] sort `bookmark-alist' in last modified order by default.

---
 lisp/bookmark.el | 53 +++++++++++++++++++++++-------------------------
 1 file changed, 25 insertions(+), 28 deletions(-)

diff --git a/lisp/bookmark.el b/lisp/bookmark.el
index c604395dd7..b56ad4fa67 100644
--- a/lisp/bookmark.el
+++ b/lisp/bookmark.el
@@ -251,8 +251,8 @@ bookmark-alist
  (BOOKMARK-NAME . PARAM-ALIST)
 
 or the deprecated form (BOOKMARK-NAME PARAM-ALIST).  The alist is
-ordered from most recently created bookmark at the front to least
-recently created bookmark at the end.
+ordered from most recently modified bookmark at the front to
+least recently modified bookmark at the end.
 
 BOOKMARK-NAME is the name you gave to the bookmark when creating it.
 
@@ -574,22 +574,18 @@ bookmark-store
   (bookmark-maybe-load-default-file)
   (let ((stripped-name (copy-sequence name)))
     (set-text-properties 0 (length stripped-name) nil stripped-name)
-    (if (and (not no-overwrite)
-             (bookmark-get-bookmark stripped-name 'noerror))
-        ;; Already existing bookmark under that name and
-        ;; no prefix arg means just overwrite old bookmark.
-        (let ((bm (bookmark-get-bookmark stripped-name)))
-          ;; First clean up if previously location was fontified.
-          (when bookmark-set-fringe-mark
-            (bookmark--remove-fringe-mark bm))
-          ;; Modify using the new (NAME . ALIST) format.
-          (setcdr bm alist))
-
-      ;; Otherwise just put it onto the front of the list.  Either the
-      ;; bookmark doesn't exist already, or there is no prefix arg.
-      ;; In either case, we want the new bookmark on the front of the
-      ;; list, since the list is kept in reverse order of creation.
-      (push (cons stripped-name alist) bookmark-alist))
+
+    ;; Already existing bookmark under that name and no prefix arg
+    ;; means just overwrite old bookmark.  First remove it.
+    (let ((bm (bookmark-get-bookmark stripped-name 'noerror)))
+      (when (and (not no-overwrite) bm)
+        ;; First clean up if previously location was fontified.
+        (when bookmark-set-fringe-mark
+          (bookmark--remove-fringe-mark bm))
+        (setq bookmark-alist (delq bm bookmark-alist))))
+
+    ;; Put the new (or overwritten) bookmark onto the front of the list.
+    (push (cons stripped-name alist) bookmark-alist)
 
     ;; Added by db
     (setq bookmark-current-bookmark stripped-name)
@@ -1144,7 +1140,7 @@ bookmark-maybe-sort-alist
   "Return `bookmark-alist' for display.
 If `bookmark-sort-flag' is non-nil, then return a sorted copy of the alist.
 Otherwise, just return `bookmark-alist', which by default is ordered
-from most recently created to least recently created bookmark."
+from most recently modified to least recently modified bookmark."
   (if bookmark-sort-flag
       (sort (copy-alist bookmark-alist)
             (lambda (x y) (string-lessp (car x) (car y))))
@@ -1831,19 +1827,19 @@ bookmark-bmenu--revert
           (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
+      ;; according to order of modification, 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.
+      ;; bookmark name instead of by (reverse) modification 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
+      ;; the sort will still be lexical not modification-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 modification-order sort.  This is all expected
       ;; behavior, as documented in `bookmark-bmenu-mode'.
       (setq tabulated-list-entries (reverse entries)))
     ;; Generate the header only after `tabulated-list-sort-key' is
@@ -1901,10 +1897,11 @@ bookmark-bmenu-mode
 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.
+modification order, with most recently modified 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.
+thereafter toggle the direction of) lexical sorting by bookmark
+name.  At any time you may use \\[revert-buffer] to go back to
+sorting by modification order.
 
 \\<bookmark-bmenu-mode-map>
 \\[bookmark-bmenu-mark] -- mark bookmark to be displayed.
-- 
2.36.0


[-- Attachment #3: Type: text/plain, Size: 18 bytes --]

-- 
Manuel Giraud

  parent reply	other threads:[~2022-05-25 13:18 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-24 11:34 [emacs bookmark.el] Sorting by last set Manuel Giraud
2022-05-24 14:41 ` [External] : " Drew Adams
2022-05-24 15:32   ` Manuel Giraud
2022-05-24 15:46     ` Lars Ingebrigtsen
2022-05-25  2:25       ` Karl Fogel
2022-05-25  5:05         ` Drew Adams
2022-05-25  8:04           ` Manuel Giraud
2022-05-25 14:01             ` Drew Adams
2022-05-25 13:18       ` Manuel Giraud [this message]
2022-05-25 14:01         ` Drew Adams
2022-05-25 15:25           ` Manuel Giraud
2022-05-25 20:17             ` Drew Adams
2022-05-26 19:41               ` Manuel Giraud
2022-05-26  4:09             ` Karl Fogel
2022-05-26 10:58               ` Lars Ingebrigtsen
2022-05-26 16:42                 ` Manuel Giraud
2022-05-26 16:59                   ` Stefan Monnier
2022-05-26 20:09                     ` Manuel Giraud
2022-05-27 10:34                       ` Lars Ingebrigtsen
2022-05-27 13:11                         ` Manuel Giraud
2022-05-27 13:20                           ` Lars Ingebrigtsen
2022-05-27 13:39                             ` Manuel Giraud
2022-05-28 10:34                               ` Lars Ingebrigtsen
2022-05-30 14:59                                 ` Manuel Giraud
2022-05-31 18:36                                   ` Lars Ingebrigtsen
2022-06-01  6:16                                     ` Juri Linkov
2022-06-01  8:04                                       ` Manuel Giraud
2022-06-01 12:18                                         ` Lars Ingebrigtsen
2022-06-01 12:38                                           ` Manuel Giraud
2022-06-01 12:08                                       ` Stefan Monnier
2022-06-01 14:24                                       ` Drew Adams
2022-06-01 13:45                                     ` Manuel Giraud
2022-06-01 15:32                                       ` Lars Ingebrigtsen
2022-06-01 15:56                                         ` Manuel Giraud
2022-06-01 15:58                                           ` Lars Ingebrigtsen
2022-06-04  5:33                                     ` Karl Fogel
2022-05-24 16:03     ` Stefan Monnier
  -- strict thread matches above, loose matches on Subject: below --
2022-06-04  6:07 Karl Fogel
2022-06-04 14:36 ` Stefan Monnier
2022-06-04 16:25 ` Drew Adams
2022-06-05 16:16 ` Manuel Giraud
2022-06-05 17:33   ` Drew Adams
2022-06-05 20:53     ` Manuel Giraud
2022-06-05 21:12       ` Stefan Monnier
2022-06-06  0:39         ` Drew Adams
2022-06-07 15:55           ` Manuel Giraud
2022-06-08 11:51             ` Lars Ingebrigtsen
2022-06-06  0:39       ` Drew Adams
2022-06-05 17:53   ` Stefan Monnier
2022-06-07 19:49   ` Karl Fogel
2022-06-08  1:14     ` Drew Adams
2022-06-08  7:57       ` Manuel Giraud
2022-06-08 14:23         ` Drew Adams
2022-06-14 15:34         ` Manuel Giraud
2022-06-14 16:36           ` Drew Adams
2022-06-15 12:08           ` Lars Ingebrigtsen
2022-06-15 12:32             ` Manuel Giraud
2022-08-18 18:19           ` Karl Fogel
2022-08-31 11:39             ` Manuel Giraud
2022-09-01  1:45               ` Karl Fogel
2022-09-01  2:08                 ` Emanuel Berg

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=87k0a93g4z.fsf@elite.giraud \
    --to=manuel@ledu-giraud.fr \
    --cc=drew.adams@oracle.com \
    --cc=emacs-devel@gnu.org \
    --cc=larsi@gnus.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).