From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Manuel Giraud Newsgroups: gmane.emacs.devel Subject: Re: [External] : [emacs bookmark.el] Sorting by last set Date: Wed, 25 May 2022 15:18:04 +0200 Message-ID: <87k0a93g4z.fsf@elite.giraud> References: <877d6b88pz.fsf@elite.giraud> <875ylv6j58.fsf@elite.giraud> <87o7zngcgf.fsf@gnus.org> 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="14103"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (berkeley-unix) Cc: Drew Adams , emacs-devel To: Lars Ingebrigtsen Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed May 25 15:24:45 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 1ntr0G-0003Ss-T9 for ged-emacs-devel@m.gmane-mx.org; Wed, 25 May 2022 15:24:45 +0200 Original-Received: from localhost ([::1]:39662 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ntr0F-0002I4-G2 for ged-emacs-devel@m.gmane-mx.org; Wed, 25 May 2022 09:24:43 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:51356) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntqtw-0006uo-68 for emacs-devel@gnu.org; Wed, 25 May 2022 09:18:12 -0400 Original-Received: from ledu-giraud.fr ([51.159.28.247]:8861) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ntqtt-0007cB-Pv for emacs-devel@gnu.org; Wed, 25 May 2022 09:18:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=rsa; bh=MP3zJRhkyUSgZhM8 YyUWvNxsnJm7/xE+t5n5mB530JU=; h=in-reply-to:date:references:subject: cc:to:from; d=ledu-giraud.fr; b=0AO8lbIsO9D+cVju0lsRQynjXcJ2elx+PhiFAG aNwxo3zIpjUXiXgwk73ncHUbkdysRFTbxft8NCrqHer0sJmDrsxmrwguh3md1RuZM/+fLi h/do4H17r6J+eGfxKUiLA3UnbK8wbNwAr5Xeka+Beoyz0DFelYXw/KC5MFkOyjpMWQbZfS gsOrQ8/a4ND80fFYWlI5XCanOk0fLi08NoIyyMUIyAWlaALzaGb/zfkANAX5GEfN3ovYAv aZMI3kL/RsNciPn3CBO7TpOJiq7kJdQupZRbcet7MYH6V2yfEuefP5i3G77Kcv6MzANfNg Sw8Ll/lNecDjUBH34YLnw45A== Original-Received: from elite.giraud ( [10.1.1.1]) by ledu-giraud.fr (OpenSMTPD) with ESMTPSA id 68e32fd6 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Wed, 25 May 2022 15:18:06 +0200 (CEST) In-Reply-To: <87o7zngcgf.fsf@gnus.org> (Lars Ingebrigtsen's message of "Tue, 24 May 2022 17:46:56 +0200") Received-SPF: pass client-ip=51.159.28.247; envelope-from=manuel@ledu-giraud.fr; helo=ledu-giraud.fr 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:290248 Archived-At: --=-=-= Content-Type: text/plain Lars Ingebrigtsen writes: [...] > I think sorting by last set sounds like a nice feature -- patches > welcome. Here is a patch that does just that. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-sort-bookmark-alist-in-last-modified-order-by-defaul.patch >From 85834e973413b4ab050923d1dca4f0b4341d9b04 Mon Sep 17 00:00:00 2001 From: Manuel Giraud 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-mark] -- mark bookmark to be displayed. -- 2.36.0 --=-=-= Content-Type: text/plain -- Manuel Giraud --=-=-=--