unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#31800: suggestion of improvement for sort-numeric-fields function.
@ 2018-06-12 16:09 SK Kim
  2019-07-13  3:41 ` Lars Ingebrigtsen
  2022-02-03 19:34 ` Lars Ingebrigtsen
  0 siblings, 2 replies; 8+ messages in thread
From: SK Kim @ 2018-06-12 16:09 UTC (permalink / raw)
  To: 31800

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

This is not likely a bug but sort-numeric-fields function does not allow
region with blank lines, while sort-lines does.

This was because sort-skip-fields occurs error with blank line. And when I
added condition for sort-skip-fields like below, sort-numeric-fields was
working with blank lines too.

                     (when (not (string-match-p "^\\s-*$" (thing-at-point
'line)))
                       (sort-skip-fields field))

So, I just hope sort-numeric-fields would work for region with blank lines
too.

I tested with GNU Emacs 26.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version
3.18.9) of 2018-05-29


Always appreciate for contribution.
Thanks.

[-- Attachment #2: Type: text/html, Size: 895 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#31800: suggestion of improvement for sort-numeric-fields function.
  2018-06-12 16:09 bug#31800: suggestion of improvement for sort-numeric-fields function SK Kim
@ 2019-07-13  3:41 ` Lars Ingebrigtsen
  2019-07-13  8:21   ` SK Kim
  2022-02-03 19:34 ` Lars Ingebrigtsen
  1 sibling, 1 reply; 8+ messages in thread
From: Lars Ingebrigtsen @ 2019-07-13  3:41 UTC (permalink / raw)
  To: SK Kim; +Cc: 31800

SK Kim <tttuuu888@gmail.com> writes:

> This is not likely a bug but sort-numeric-fields function does not
> allow region with blank lines, while sort-lines does.
>
> This was because sort-skip-fields occurs error with blank line. And
> when I added condition for sort-skip-fields like below,
> sort-numeric-fields was working with blank lines too.
>
>                      (when (not (string-match-p "^\\s-*$" (thing-at-point 'line)))
>                        (sort-skip-fields field))
>
> So, I just hope sort-numeric-fields would work for region with blank
> lines too.

Can you create a patch for this fix?

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





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#31800: suggestion of improvement for sort-numeric-fields function.
  2019-07-13  3:41 ` Lars Ingebrigtsen
@ 2019-07-13  8:21   ` SK Kim
  2020-01-20 19:55     ` Stefan Kangas
  0 siblings, 1 reply; 8+ messages in thread
From: SK Kim @ 2019-07-13  8:21 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 31800


[-- Attachment #1.1: Type: text/plain, Size: 967 bytes --]

I made this patch from github emacs-mirror repository.
I hope this will be of help.

Thanks.

2019년 7월 13일 (토) 오후 12:42, Lars Ingebrigtsen <larsi@gnus.org>님이 작성:

> SK Kim <tttuuu888@gmail.com> writes:
>
> > This is not likely a bug but sort-numeric-fields function does not
> > allow region with blank lines, while sort-lines does.
> >
> > This was because sort-skip-fields occurs error with blank line. And
> > when I added condition for sort-skip-fields like below,
> > sort-numeric-fields was working with blank lines too.
> >
> >                      (when (not (string-match-p "^\\s-*$"
> (thing-at-point 'line)))
> >                        (sort-skip-fields field))
> >
> > So, I just hope sort-numeric-fields would work for region with blank
> > lines too.
>
> Can you create a patch for this fix?
>
> --
> (domestic pets only, the antidote for overdose, milk.)
>    bloggy blog: http://lars.ingebrigtsen.no
>

[-- Attachment #1.2: Type: text/html, Size: 1782 bytes --]

[-- Attachment #2: 0001-Improve-sort-numeric-fields.patch --]
[-- Type: text/x-patch, Size: 908 bytes --]

From d08c5d368337ee49bb72d9915c409edcbc73b4e0 Mon Sep 17 00:00:00 2001
From: SeungKi Kim <tttuuu888@gmail.com>
Date: Sat, 13 Jul 2019 17:12:46 +0900
Subject: [PATCH] Improve `sort-numeric-fields'

* lisp/sort.el (sort-numeric-fields) : Allow including empty lines.
---
 lisp/sort.el | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lisp/sort.el b/lisp/sort.el
index 6ea1c44060..3e9413e4af 100644
--- a/lisp/sort.el
+++ b/lisp/sort.el
@@ -281,7 +281,8 @@ FIELD, BEG and END.  BEG and END specify region to sort."
       ((inhibit-field-text-motion t))
     (sort-fields-1 field beg end
 		   (lambda ()
-		     (sort-skip-fields field)
+                     (unless (string-match-p "^\\s-*$" (thing-at-point 'line))
+                       (sort-skip-fields field))
 		     (let* ((case-fold-search t)
 			    (base
 			     (if (looking-at "\\(0x\\)[0-9a-f]\\|\\(0\\)[0-7]")
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* bug#31800: suggestion of improvement for sort-numeric-fields function.
  2019-07-13  8:21   ` SK Kim
@ 2020-01-20 19:55     ` Stefan Kangas
  2020-01-22 13:44       ` Lars Ingebrigtsen
  0 siblings, 1 reply; 8+ messages in thread
From: Stefan Kangas @ 2020-01-20 19:55 UTC (permalink / raw)
  To: SK Kim; +Cc: Lars Ingebrigtsen, 31800

SK Kim <tttuuu888@gmail.com> writes:

> I made this patch from github emacs-mirror repository.
> I hope this will be of help.
>
> Thanks.
>
> 2019년 7월 13일 (토) 오후 12:42, Lars Ingebrigtsen <larsi@gnus.org>님이 작성:
>
>  SK Kim <tttuuu888@gmail.com> writes:
>
>  > This is not likely a bug but sort-numeric-fields function does not
>  > allow region with blank lines, while sort-lines does.
>  >
>  > This was because sort-skip-fields occurs error with blank line. And
>  > when I added condition for sort-skip-fields like below,
>  > sort-numeric-fields was working with blank lines too.
>  >
>  >                      (when (not (string-match-p "^\\s-*$" (thing-at-point 'line)))
>  >                        (sort-skip-fields field))
>  >
>  > So, I just hope sort-numeric-fields would work for region with blank
>  > lines too.

The patch below looks good to me.  Does anyone else have an opinion
here, or should I go ahead and commit it to master?

Best regards,
Stefan Kangas

> From d08c5d368337ee49bb72d9915c409edcbc73b4e0 Mon Sep 17 00:00:00 2001
> From: SeungKi Kim <tttuuu888@gmail.com>
> Date: Sat, 13 Jul 2019 17:12:46 +0900
> Subject: [PATCH] Improve `sort-numeric-fields'
>
> * lisp/sort.el (sort-numeric-fields) : Allow including empty lines.
> ---
>  lisp/sort.el | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/lisp/sort.el b/lisp/sort.el
> index 6ea1c44060..3e9413e4af 100644
> --- a/lisp/sort.el
> +++ b/lisp/sort.el
> @@ -281,7 +281,8 @@ FIELD, BEG and END.  BEG and END specify region to sort."
>        ((inhibit-field-text-motion t))
>      (sort-fields-1 field beg end
>  		   (lambda ()
> -		     (sort-skip-fields field)
> +                     (unless (string-match-p "^\\s-*$" (thing-at-point 'line))
> +                       (sort-skip-fields field))
>  		     (let* ((case-fold-search t)
>  			    (base
>  			     (if (looking-at "\\(0x\\)[0-9a-f]\\|\\(0\\)[0-7]")





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#31800: suggestion of improvement for sort-numeric-fields function.
  2020-01-20 19:55     ` Stefan Kangas
@ 2020-01-22 13:44       ` Lars Ingebrigtsen
  2020-01-23 14:50         ` Stefan Kangas
  0 siblings, 1 reply; 8+ messages in thread
From: Lars Ingebrigtsen @ 2020-01-22 13:44 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: SK Kim, 31800

Stefan Kangas <stefan@marxist.se> writes:

> The patch below looks good to me.  Does anyone else have an opinion
> here, or should I go ahead and commit it to master?

[...]

>> -		     (sort-skip-fields field)
>> +                     (unless (string-match-p "^\\s-*$" (thing-at-point 'line))
>> +                       (sort-skip-fields field))

I don't think this patch makes sense as is -- I think that's a
convoluted way of saying `looking-at'?  But it makes conceptual sense, I
think.

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





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#31800: suggestion of improvement for sort-numeric-fields function.
  2020-01-22 13:44       ` Lars Ingebrigtsen
@ 2020-01-23 14:50         ` Stefan Kangas
  2020-01-24 15:30           ` Lars Ingebrigtsen
  0 siblings, 1 reply; 8+ messages in thread
From: Stefan Kangas @ 2020-01-23 14:50 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: SK Kim, 31800

Lars Ingebrigtsen <larsi@gnus.org> writes:

>>> -		     (sort-skip-fields field)
>>> +                     (unless (string-match-p "^\\s-*$" (thing-at-point 'line))
>>> +                       (sort-skip-fields field))
>
> I don't think this patch makes sense as is -- I think that's a
> convoluted way of saying `looking-at'?  But it makes conceptual sense, I
> think.

I'm not sure.  Do you mean to use:

    (looking-at "\\s*$")

Are we sure point is at the beginning of line here though?  The above
code doesn't require that, but also seems to be wrong if region is in
the middle of a line.  But I'm not sure how people typically use this
in that case.

BTW, shouldn't we also fix the same bug in sort-fields while we're at
it?

Best regards,
Stefan Kangas





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#31800: suggestion of improvement for sort-numeric-fields function.
  2020-01-23 14:50         ` Stefan Kangas
@ 2020-01-24 15:30           ` Lars Ingebrigtsen
  0 siblings, 0 replies; 8+ messages in thread
From: Lars Ingebrigtsen @ 2020-01-24 15:30 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: SK Kim, 31800

Stefan Kangas <stefan@marxist.se> writes:

> Lars Ingebrigtsen <larsi@gnus.org> writes:
>
>>>> -		     (sort-skip-fields field)
>>>> + (unless (string-match-p "^\\s-*$" (thing-at-point 'line))
>>>> +                       (sort-skip-fields field))
>>
>> I don't think this patch makes sense as is -- I think that's a
>> convoluted way of saying `looking-at'?  But it makes conceptual sense, I
>> think.
>
> I'm not sure.  Do you mean to use:
>
>     (looking-at "\\s*$")
>
> Are we sure point is at the beginning of line here though?  The above
> code doesn't require that, but also seems to be wrong if region is in
> the middle of a line.  But I'm not sure how people typically use this
> in that case.

I assumed that

  (thing-at-point 'line)

returns the current line, but I haven't actually looked at the code, but
you're right -- we don't know where point is, so that has to be moved
before checking.  In any case, using thing-at-point is not the right
thing.

> BTW, shouldn't we also fix the same bug in sort-fields while we're at
> it?

Yes.

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





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#31800: suggestion of improvement for sort-numeric-fields function.
  2018-06-12 16:09 bug#31800: suggestion of improvement for sort-numeric-fields function SK Kim
  2019-07-13  3:41 ` Lars Ingebrigtsen
@ 2022-02-03 19:34 ` Lars Ingebrigtsen
  1 sibling, 0 replies; 8+ messages in thread
From: Lars Ingebrigtsen @ 2022-02-03 19:34 UTC (permalink / raw)
  To: SK Kim; +Cc: 31800

SK Kim <tttuuu888@gmail.com> writes:

> This is not likely a bug but sort-numeric-fields function does not allow region with
> blank lines, while sort-lines does.
>
> This was because sort-skip-fields occurs error with blank line. And
> when I added condition for sort-skip-fields like below,
> sort-numeric-fields was working with blank lines too.

I've now fixed this in Emacs 29.

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





^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-02-03 19:34 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-12 16:09 bug#31800: suggestion of improvement for sort-numeric-fields function SK Kim
2019-07-13  3:41 ` Lars Ingebrigtsen
2019-07-13  8:21   ` SK Kim
2020-01-20 19:55     ` Stefan Kangas
2020-01-22 13:44       ` Lars Ingebrigtsen
2020-01-23 14:50         ` Stefan Kangas
2020-01-24 15:30           ` Lars Ingebrigtsen
2022-02-03 19:34 ` Lars Ingebrigtsen

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).