GNU bug report logs - #16937
Proposed feature (with patch): sort on multipart keys with sort-regexp-fields

Previous Next

Package: emacs;

Reported by: Eric Roode <sdn.gnuem <at> mailnull.com>

Date: Tue, 4 Mar 2014 17:03:03 UTC

Severity: wishlist

Tags: patch, wontfix

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 16937 in the body.
You can then email your comments to 16937 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#16937; Package emacs. (Tue, 04 Mar 2014 17:03:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Eric Roode <sdn.gnuem <at> mailnull.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 04 Mar 2014 17:03:03 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Eric Roode <sdn.gnuem <at> mailnull.com>
To: bug-gnu-emacs <at> gnu.org
Subject: Proposed feature (with patch): sort on multipart keys with
 sort-regexp-fields
Date: Tue, 4 Mar 2014 11:52:21 -0500
[Message part 1 (text/plain, inline)]
***Abstract:

    To `sort-regexp-fields', add the ability to sort records by
multi-part (non-contiguous) keys.

***Description:

    `sort-regexp-fields' can sort entire records, or a subset of each
record specified by a secondary regexp or by a single backreference to
the record as matched by the record-defining regexp.

    This fairly minor patch gives the user (or caller) the additional
ability to sort by multiple backreferences; e.g., \3\1\4

    It does this by storing a list of backreference numbers in the
`key-regexp' parameter to `sort-regexp-fields'. Then in the
`startkeyfun' function passed to `sort-subr', those backreference
strings are concatenated (separated by a NUL character) to form the
sort key.

***ChangeLog:

2014-03-04  Eric Roode  <sdn.gnuem <at> mailnull.com>

* lisp/sort.el (sort-regexp-fields): add multi-key sorting
* doc/lispref/text.texi (sort-regexp-fields): document multi-key sorting

***Patch 1 of 2 (lisp/sort.el):

*** /c/usr/emacs-24.3/lisp/sort.el 2013-08-07 12:18:53.540292800 -0400
--- /ejr/dev/emacs/sort.el 2014-03-04 10:59:02.280611700 -0500
*************** KEY-REGEXP specifies the part of each re
*** 417,422 ****
--- 417,424 ----
    RECORD-REGEXP) to be used for sorting.
    If it is \"\\\\digit\", use the digit'th \"\\\\(...\\\\)\"
    match field specified by RECORD-REGEXP.
+   If it is a sequence of such match fields: \"\\\\digit\\\\digit...\",
+   use a concatenation of those backreferences, in that order.
    If it is \"\\\\&\", use the whole record.
    Otherwise, KEY-REGEXP should be a regular expression with which
    to search within the record.  If a match for KEY-REGEXP is not
*************** sRegexp specifying key within record: \n
*** 438,444 ****
    (cond ((or (equal key-regexp "") (equal key-regexp "\\&"))
  (setq key-regexp 0))
  ((string-match "\\`\\\\[1-9]\\'" key-regexp)
! (setq key-regexp (- (aref key-regexp 1) ?0))))
    (save-excursion
      (save-restriction
        (narrow-to-region beg end)
--- 440,452 ----
    (cond ((or (equal key-regexp "") (equal key-regexp "\\&"))
  (setq key-regexp 0))
  ((string-match "\\`\\\\[1-9]\\'" key-regexp)
! (setq key-regexp (- (aref key-regexp 1) ?0)))
! ((string-match "\\`\\(\\\\[1-9]\\)+\\'" key-regexp)
!          (let ((st 1) (en (length key-regexp)) mlist)
!            (while (< st en)
!              (push (- (aref key-regexp st) ?0) mlist)
!              (setq st (+ 2 st)))
!            (setq key-regexp (nreverse mlist)))))
    (save-excursion
      (save-restriction
        (narrow-to-region beg end)
*************** sRegexp specifying key within record: \n
*** 453,470 ****
    (function (lambda ()
        (goto-char sort-regexp-record-end)))
    (function (lambda ()
!       (let ((n 0))
! (cond ((numberp key-regexp)
! (setq n key-regexp))
!       ((re-search-forward
!  key-regexp sort-regexp-record-end t)
! (setq n 0))
!       (t (throw 'key nil)))
! (condition-case ()
!     (cons (match-beginning n)
!   (match-end n))
!   ;; if there was no such register
!   (error (throw 'key nil)))))))))))


  (defvar sort-columns-subprocess t)
--- 461,482 ----
    (function (lambda ()
        (goto-char sort-regexp-record-end)))
    (function (lambda ()
!       (if (listp key-regexp)
!                                    (mapconcat
!                                     (function (lambda (ix) (match-string
ix)))
!                                     key-regexp "\0")
!                                  (let ((n 0))
!                                    (cond ((numberp key-regexp)
!                                           (setq n key-regexp))
!                                          ((re-search-forward
!                                            key-regexp
sort-regexp-record-end t)
!                                           (setq n 0))
!                                          (t (throw 'key nil)))
!                                    (condition-case ()
!                                        (cons (match-beginning n)
!                                              (match-end n))
!                                      ;; if there was no such register
!                                      (error (throw 'key nil))))))))))))


  (defvar sort-columns-subprocess t)

***Patch 2 of 2 (doc/lispref/text.texi):

*** text.texi~  2013-02-18 20:17:07.000000000 -0500
--- text.texi   2014-03-04 11:38:48.136225100 -0500
*************** on its own.
*** 1988,1999 ****
If @var{key-regexp} is:

@table @asis
@item @samp{\@var{digit}}
then the text matched by the @var{digit}th @samp{\(...\)} parenthesis
grouping in @var{record-regexp} is the sort key.

! @item @samp{\&}
! then the whole record is the sort key.

@item a regular expression
then @code{sort-regexp-fields} searches for a match for the regular
--- 1988,2003 ----
If @var{key-regexp} is:

@table @asis
+ @item @samp{\&}
+ then the whole record is the sort key.
+
@item @samp{\@var{digit}}
then the text matched by the @var{digit}th @samp{\(...\)} parenthesis
grouping in @var{record-regexp} is the sort key.

! @item a series of such backreferences: @samp{\@var{digit}\@var{digit}...}
! then the multiple subexpressions specified by the respective parenthesis
! groupings in @var{record-regexp} are combined to be the sort key.

@item a regular expression
then @code{sort-regexp-fields} searches for a match for the regular
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#16937; Package emacs. (Wed, 26 Jun 2019 14:45:02 GMT) Full text and rfc822 format available.

Message #8 received at 16937 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Eric Roode <sdn.gnuem <at> mailnull.com>
Cc: 16937 <at> debbugs.gnu.org
Subject: Re: bug#16937: Proposed feature (with patch): sort on multipart keys
 with sort-regexp-fields
Date: Wed, 26 Jun 2019 16:44:01 +0200
Eric Roode <sdn.gnuem <at> mailnull.com> writes:

>     It does this by storing a list of backreference numbers in the
> `key-regexp' parameter to `sort-regexp-fields'. Then in the
> `startkeyfun' function passed to `sort-subr', those backreference
> strings are concatenated (separated by a NUL character) to form the
> sort key.

Sorry for taking so long to get back to you on this, but I don't think
this is an ideal design for such a thing, and since it's unfortunately
been five years since this was proposed, I'm closing this bug report.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Added tag(s) wontfix. Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Wed, 26 Jun 2019 14:45:05 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 16937 <at> debbugs.gnu.org and Eric Roode <sdn.gnuem <at> mailnull.com> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Wed, 26 Jun 2019 14:45:05 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Thu, 25 Jul 2019 11:24:09 GMT) Full text and rfc822 format available.

This bug report was last modified 4 years and 276 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.