From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jean Louis Newsgroups: gmane.emacs.bugs Subject: bug#45361: 28.0.50; tabulated-list-mode: should be sorting by specified sort function Date: Tue, 22 Dec 2020 08:13:50 +0100 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15492"; mail-complaints-to="usenet@ciao.gmane.io" To: 45361@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Dec 22 08:15:18 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1krbt8-0003sd-2m for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 22 Dec 2020 08:15:18 +0100 Original-Received: from localhost ([::1]:38136 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1krbt6-0002LZ-KO for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 22 Dec 2020 02:15:16 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:57362) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1krbss-0002L7-IR for bug-gnu-emacs@gnu.org; Tue, 22 Dec 2020 02:15:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:37298) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1krbss-0006qe-BJ for bug-gnu-emacs@gnu.org; Tue, 22 Dec 2020 02:15:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1krbss-0007Nf-6Y for bug-gnu-emacs@gnu.org; Tue, 22 Dec 2020 02:15:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Jean Louis Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 22 Dec 2020 07:15:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 45361 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.160862127428310 (code B ref -1); Tue, 22 Dec 2020 07:15:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 22 Dec 2020 07:14:34 +0000 Original-Received: from localhost ([127.0.0.1]:48844 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1krbsQ-0007MY-Cu for submit@debbugs.gnu.org; Tue, 22 Dec 2020 02:14:34 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:60514) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1krbsL-0007MO-Hi for submit@debbugs.gnu.org; Tue, 22 Dec 2020 02:14:32 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:57324) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1krbsL-0002HT-AA for bug-gnu-emacs@gnu.org; Tue, 22 Dec 2020 02:14:29 -0500 Original-Received: from stw1.rcdrun.com ([217.170.207.13]:60337) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1krbsI-00069p-QB for bug-gnu-emacs@gnu.org; Tue, 22 Dec 2020 02:14:28 -0500 Original-Received: from localhost ([::ffff:41.202.241.37]) (AUTH: PLAIN securesender, TLS: TLS1.2,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 0000000000012004.000000005FE19CB0.000034A7; Tue, 22 Dec 2020 00:13:52 -0700 Received-SPF: pass client-ip=217.170.207.13; envelope-from=support1@rcdrun.com; helo=stw1.rcdrun.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.25, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:196561 Archived-At: PROBLEM: The variable `tabulated-list-format' provides for programmer option to sort columns and I would like to sort number as strings "12" as numbers, not as strings. I do not know how to properly provide the sorting function to `tabulated-list-format' so that it works when actually sorting. DATA: The tabulated list mode works as this: (let ((buffer "*tabulated*")) (switch-to-buffer-other-window buffer) (setq tabulated-list-format [("Count" 10 t :right-align t) ("Name" 60 t)]) (setq tabulated-list-entries '((6 ["6" "Mercury"]) (7 ["7" "GNU Emacs"]) (8 ["8" "YouTube Videos"]) (9 ["9" "Speedy worker cleaning tables in a restaurant"]) (71 ["71" "Trenching"]) (82 ["82" "Easier trenching idea"]))) (tabulated-list-mode) (tabulated-list-init-header) (hl-line-mode) (tabulated-list-print)) When evaluated I would get the list such as: 6 Mercury 7 GNU Emacs 71 Trenching 8 YouTube Videos 82 Easier trenching idea 9 Speedy worker cleaning tables in a restaurant and my goal would be to be able to sort the column "Count" so that I get a result sorted by the number (which is string): 6 Mercury 7 GNU Emacs 8 YouTube Videos 9 Speedy worker cleaning tables in a restaurant 71 Trenching 82 Easier trenching idea The description of `tabulated-list-format' says: The format of the current Tabulated List mode buffer. This should be a vector of elements (NAME WIDTH SORT . PROPS), where: - NAME is a string describing the column. This is the label for the column in the header line. Different columns must have non-‘equal’ names. - WIDTH is the width to reserve for the column. For the final element, its numerical value is ignored. - SORT specifies how to sort entries by this column. If nil, this column cannot be used for sorting. If t, sort by comparing the string value printed in the column. Otherwise, it should be a predicate function suitable for ‘sort’, accepting arguments with the same form as the elements of ‘tabulated-list-entries’. I could make a function to list what elements are accepted on click: (defun my-sort (&rest args) (message "%s" args)) and include it here: (let ((buffer "*tabulated*")) (switch-to-buffer-other-window buffer) (setq tabulated-list-format [("Count" 10 my-sort :right-align t) ("Name" 60 t)]) (setq tabulated-list-entries '((1 ["6" "Mercury"]) (2 ["7" "GNU Emacs"]) (3 ["8" "YouTube Videos"]) (4 ["9" "Speedy worker cleaning tables in a restaurant"]) (5 ["71" "Trenching"]) (6 ["82" "Easier trenching idea"]))) (tabulated-list-mode) (tabulated-list-init-header) (hl-line-mode) (tabulated-list-print)) Then I can see something like this in `*Messages*' buffer: ((6 [82 Easier trenching idea]) (5 [71 Trenching])) ((6 [82 Easier trenching idea]) (4 [9 Speedy worker cleaning tables in a restaurant])) ((5 [71 Trenching]) (4 [9 Speedy worker cleaning tables in a restaurant])) ((3 [8 YouTube Videos]) (2 [7 GNU Emacs])) ((3 [8 YouTube Videos]) (1 [6 Mercury])) ((2 [7 GNU Emacs]) (1 [6 Mercury])) ((6 [82 Easier trenching idea]) (3 [8 YouTube Videos])) ((5 [71 Trenching]) (3 [8 YouTube Videos])) ((4 [9 Speedy worker cleaning tables in a restaurant]) (3 [8 YouTube Videos])) Then I would like to use the function `string-collate-lessp' as that seem to understand how numbers should be compared. For example this is giving me correct result: (sort '("121" "117" "1") 'string-collate-lessp) => ("1" "117" "121") Then I am attempting to make the sorting function: (defun my-sort (s1 s2) (let* ((s1-number (elt (cadr s1) 0)) (s2-number (elt (cadr s2) 0))) (string-collate-lessp s1-number s2-number))) (my-sort '(2 ["7" "GNU Emacs"]) '(1 ["6" "Mercury"])) Now this works well first time as when the list is displayed it is already sorted by "Count": (let ((buffer "*tabulated*")) (switch-to-buffer-other-window buffer) (setq tabulated-list-format [("Count" 10 my-sort :right-align t) ("Name" 60 nil)]) (setq tabulated-list-entries '((1 ["6" "Mercury"]) (2 ["7" "GNU Emacs"]) (3 ["8" "YouTube Videos"]) (4 ["9" "Speedy worker cleaning tables in a restaurant"]) (5 ["71" "Trenching"]) (6 ["82" "Easier trenching idea"]))) (tabulated-list-mode) (tabulated-list-init-header) (hl-line-mode) (tabulated-list-print)) But when I click on "Count" column or press S then it again gets sorted rather alphabetic, not by using my function. That is where I would need help to understand what is happening. Because when I press S in the column "Count" when cursor is on the number, it invokes this function: (defun tabulated-list-sort (&optional n) "Sort Tabulated List entries by the column at point. With a numeric prefix argument N, sort the Nth column." (interactive "P") (let ((name (if n (car (aref tabulated-list-format n)) (get-text-property (point) 'tabulated-list-column-name)))) (if (nth 2 (assoc name (append tabulated-list-format nil))) (tabulated-list--sort-by-column-name name) (user-error "Cannot sort by %s" name)))) Then this one: (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))) (tabulated-list-init-header) (tabulated-list-print t))) And if I read well those functions do not search for my function and invoke `my-sort', but they should. Am I right there? Jean In GNU Emacs 28.0.50 (build 2, x86_64-pc-linux-gnu, X toolkit, cairo version 1.14.8, Xaw3d scroll bars) of 2020-11-25 built on protected.rcdrun.com Repository revision: 30c437752df0a3a9410f1249fa0f237110811af2 Repository branch: master Windowing system distributor 'The X.Org Foundation', version 11.0.11907000 System Description: Hyperbola GNU/Linux-libre Configured using: 'configure --prefix=/package/text/emacs --with-modules --with-x-toolkit=lucid' Configured features: XAW3D XPM JPEG TIFF GIF PNG RSVG CAIRO SOUND GPM DBUS GSETTINGS GLIB NOTIFY INOTIFY ACL GNUTLS LIBXML2 FREETYPE HARFBUZZ M17N_FLT LIBOTF ZLIB TOOLKIT_SCROLL_BARS LUCID X11 XDBE XIM MODULES THREADS JSON PDUMPER LCMS2 Important settings: value of $LC_ALL: en_US.UTF-8 value of $LANG: de_DE.UTF-8 value of $XMODIFIERS: @im=exwm-xim locale-coding-system: utf-8-unix -- Thanks, Jean Louis ⎔ λ 🄯 𝍄 𝌡 𝌚