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: Thu, 26 May 2022 22:09:22 +0200 Message-ID: <87leuo12fh.fsf@elite.giraud> References: <877d6b88pz.fsf@elite.giraud> <875ylv6j58.fsf@elite.giraud> <87o7zngcgf.fsf@gnus.org> <87k0a93g4z.fsf@elite.giraud> <87y1yp1vnw.fsf@elite.giraud> <877d69lyt2.fsf@red-bean.com> <87ilpsd0hv.fsf@gnus.org> <87tu9c1c0k.fsf@elite.giraud> 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="15785"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (berkeley-unix) Cc: Lars Ingebrigtsen , Karl Fogel , Drew Adams , emacs-devel To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu May 26 22:10:26 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 1nuJoP-0003vv-6F for ged-emacs-devel@m.gmane-mx.org; Thu, 26 May 2022 22:10:25 +0200 Original-Received: from localhost ([::1]:55008 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nuJoN-0007Rw-U7 for ged-emacs-devel@m.gmane-mx.org; Thu, 26 May 2022 16:10:23 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:38976) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nuJnW-0006kH-7p for emacs-devel@gnu.org; Thu, 26 May 2022 16:09:30 -0400 Original-Received: from ledu-giraud.fr ([51.159.28.247]:43488) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nuJnT-0002dW-Qk for emacs-devel@gnu.org; Thu, 26 May 2022 16:09:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=rsa; bh=YE/cBKTryxGhxvPd Hnwqt8GNdSl07Zf4VBF6ywi396s=; h=in-reply-to:date:references:subject: cc:to:from; d=ledu-giraud.fr; b=UrGp14QmFO7kHqPK83jw0MQctubKK8TlYywlzj T94b4HvLP5kvK/JXUJw1SHV/a7SOWgCPwrX/PqIJdKENdp47pkHDEMvd3vG2KXxmntArnj S5Oyop3t+pXkuzHdH7IkDKDJ4QucoHVHgfqP9LlhBXE0s+ph/BlJiZpv+o0ZEyugKP8Lcj utN0KsfQqSEzK9m2EfNfEC+gUiVqnbcGfc9DP6KH7ZoEf9CD4Sg3krB8ybZrwOzEpXSrIA FwyGip/DQc94aHzd2kYknT9gXjFdrfPS6knClln4P4QB9qWQVurN5x1F55FA/SqYKY/xvM nQfvop1Cb5OETd1NpGM8NeIg== Original-Received: from elite.giraud ( [10.1.1.1]) by ledu-giraud.fr (OpenSMTPD) with ESMTPSA id 12e3aaac (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Thu, 26 May 2022 22:09:25 +0200 (CEST) In-Reply-To: (Stefan Monnier's message of "Thu, 26 May 2022 12:59:37 -0400") 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:290289 Archived-At: --=-=-= Content-Type: text/plain Stefan Monnier writes: > Manuel Giraud [2022-05-26 18:42:19] wrote: >> This time I add a timestamp field to each bookmark upon setting it. I >> also add the possibility to set `bookmark-sort-flag' to 'timestamp which >> means sort the displayed bookmark list from most recently set to the >> least recently set. > > "timestamp" doesn't say which time it's referring to. > I think we should call it "last-modified" or something like that, so > there's no ambiguity. Yes, that makes sense. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-add-a-last-modified-field-when-a-bookmark-is-set.patch >From cd0e1165c4eb5a45382317f73109cc2b46fd4d54 Mon Sep 17 00:00:00 2001 From: Manuel Giraud Date: Thu, 26 May 2022 18:25:52 +0200 Subject: [PATCH] add a last-modified field when a bookmark is set. add the 'last-modified option to `bookmark-sort-flag' to display bookmark list sorted by those timestamp. --- etc/NEWS | 5 +++ lisp/bookmark.el | 92 ++++++++++++++++++++++++++++-------------------- 2 files changed, 58 insertions(+), 39 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 4ebaf6e07a..fb5fafe5bd 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1673,6 +1673,11 @@ manual for more details. Types are registered via a 'bookmark-handler-type' symbol property on the jumping function. ++++ +*** 'bookmark-sort-flag' can now be set to 'last-modified. +This will display bookmark list from most recently set to least +recently set. + --- *** New minor mode 'elide-head-mode'. Enabling this minor mode turns on hiding header material, like diff --git a/lisp/bookmark.el b/lisp/bookmark.el index c604395dd7..5460a9a297 100644 --- a/lisp/bookmark.el +++ b/lisp/bookmark.el @@ -115,10 +115,14 @@ bookmark-completion-ignore-case (defcustom bookmark-sort-flag t - "Non-nil means that bookmarks will be displayed sorted by bookmark name. + "T means that bookmarks will be displayed sorted by bookmark name. +LAST-MODIFIED means that bookmarks will be displayed sorted from most +recently set to last recently set. Otherwise they will be displayed in LIFO order (that is, most -recently set ones come first, oldest ones come last)." - :type 'boolean) +recently created ones come first, oldest ones come last)." + :type '(choice (const :tag "By name" t) + (const :tag "By modified time" last-modified) + (const :tag "By creation time" nil))) (defcustom bookmark-menu-confirm-deletion nil @@ -460,6 +464,10 @@ bookmark-get-handler "Return the handler function for BOOKMARK-NAME-OR-RECORD, or nil if none." (bookmark-prop-get bookmark-name-or-record 'handler)) +(defun bookmark-get-last-modified (bookmark-name-or-record) + "Return the last-modified for BOOKMARK-NAME-OR-RECORD, or nil if none." + (bookmark-prop-get bookmark-name-or-record 'last-modified)) + (defvar bookmark-history nil "The history list for bookmark functions.") @@ -497,6 +505,21 @@ bookmark--remove-fringe-mark (when (eq 'bookmark (overlay-get temp 'category)) (delete-overlay (setq found temp)))))))))) +(defun bookmark-maybe-sort-alist () + "Return `bookmark-alist' for display. +If `bookmark-sort-flag' is T, then return a sorted by name copy of the alist. +If `bookmark-sort-flag' is LAST-MODIFIED, then return a sorted by last modified +copy of the alist. Otherwise, just return `bookmark-alist', which by default +is ordered from most recently created to least recently created bookmark." + (let ((copy (copy-alist bookmark-alist))) + (cond ((eq bookmark-sort-flag t) + (sort copy (lambda (x y) (string-lessp (car x) (car y))))) + ((eq bookmark-sort-flag 'last-modified) + (sort copy (lambda (x y) + (time-less-p (bookmark-get-last-modified y) + (bookmark-get-last-modified x))))) + (t copy)))) + (defun bookmark-completing-read (prompt &optional default) "Prompting with PROMPT, read a bookmark name in completion. PROMPT will get a \": \" stuck on the end no matter what, so you @@ -506,10 +529,8 @@ bookmark-completing-read (bookmark-maybe-load-default-file) ; paranoia (if (listp last-nonmenu-event) (bookmark-menu-popup-paned-menu t prompt - (if bookmark-sort-flag - (sort (bookmark-all-names) - 'string-lessp) - (bookmark-all-names))) + (mapcar 'bookmark-name-from-full-record + (bookmark-maybe-sort-alist))) (let* ((completion-ignore-case bookmark-completion-ignore-case) (default (unless (equal "" default) default))) (completing-read (format-prompt prompt default) @@ -630,7 +651,8 @@ bookmark-make-record-default (point) (- (point) bookmark-search-size)) nil)))) - (position . ,(or posn (point))))) + (position . ,(or posn (point))) + (last-modified . ,(current-time)))) ;;; File format stuff @@ -1140,15 +1162,6 @@ bookmark-maybe-load-default-file (car bookmark-bookmarks-timestamp))))))) (bookmark-load (car bookmark-bookmarks-timestamp) t t)))) -(defun 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." - (if bookmark-sort-flag - (sort (copy-alist bookmark-alist) - (lambda (x y) (string-lessp (car x) (car y)))) - bookmark-alist)) (defvar bookmark-after-jump-hook nil @@ -1825,27 +1838,28 @@ bookmark-bmenu--revert 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))) + (cond ((eq bookmark-sort-flag t) + (setq tabulated-list-sort-key '("Bookmark Name" . nil) + tabulated-list-entries entries)) + ((or (null bookmark-sort-flag) + (eq bookmark-sort-flag 'last-modified)) + (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)))) ;; Generate the header only after `tabulated-list-sort-key' is ;; settled, because if that's non-nil then the sort-direction ;; indicator will be shown in the named column, but if it's @@ -1953,7 +1967,7 @@ bookmark-bmenu-mode ,@(if bookmark-bmenu-toggle-filenames '(("File" 0 bookmark-bmenu--file-predicate)))]) (setq tabulated-list-padding bookmark-bmenu-marks-width) - (when bookmark-sort-flag + (when (eq bookmark-sort-flag t) (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) -- 2.36.0 --=-=-= Content-Type: text/plain -- Manuel Giraud --=-=-=--