unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#57564: Add new function `seq-remove-at-position'
@ 2022-09-03 17:09 Damien Cassou
  2022-09-03 19:21 ` Juri Linkov
  2022-09-04 11:07 ` Lars Ingebrigtsen
  0 siblings, 2 replies; 7+ messages in thread
From: Damien Cassou @ 2022-09-03 17:09 UTC (permalink / raw)
  To: 57564

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

Tags: patch

Hi,

here is a patch adding seq-remove-at-position to seq.el.

-- 
Damien Cassou

"Success is the ability to go from one failure to another without
losing enthusiasm." --Winston Churchill

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-new-function-seq-remove-at-position.patch --]
[-- Type: text/patch, Size: 4488 bytes --]

From 244bb4ac72afb682c52e48a1308b569ce782174d Mon Sep 17 00:00:00 2001
From: Damien Cassou <damien@cassou.me>
Date: Sat, 3 Sep 2022 18:47:04 +0200
Subject: [PATCH] Add new function `seq-remove-at-position'

* doc/lispref/sequences.texi (Sequence Functions): Document it.

* lisp/emacs-lisp/seq.el (seq-remove-at-position): New function.

* lisp/emacs-lisp/shortdoc.el (sequence): Mention it.

* test/lisp/emacs-lisp/seq-tests.el (test-seq-remove-at-position):
Test it.
---
 doc/lispref/sequences.texi        | 18 ++++++++++++++++++
 etc/NEWS                          |  5 +++++
 lisp/emacs-lisp/seq.el            | 14 ++++++++++++++
 lisp/emacs-lisp/shortdoc.el       |  3 +++
 test/lisp/emacs-lisp/seq-tests.el |  8 ++++++++
 5 files changed, 48 insertions(+)

diff --git a/doc/lispref/sequences.texi b/doc/lispref/sequences.texi
index 1f6f80521c..e90502df3c 100644
--- a/doc/lispref/sequences.texi
+++ b/doc/lispref/sequences.texi
@@ -680,6 +680,24 @@ Sequence Functions
 @end example
 @end defun
 
+@defun seq-remove-at-position sequence n
+@cindex removing from sequences
+  This function returns a copy of @var{sequence} where the element at
+  (zero-based) index @var{n} got removed. The result is a sequence of
+  the same type as @var{sequence}.
+
+@example
+@group
+(seq-remove-at-position [1 -1 3 -3 5] 0)
+@result{} [-1 3 -3 5]
+@end group
+@group
+(seq-remove-at-position [1 -1 3 -3 5] 3)
+@result{} [1 -1 3 5]
+@end group
+@end example
+@end defun
+
 @defun seq-reduce function sequence initial-value
 @cindex reducing sequences
   This function returns the result of calling @var{function} with
diff --git a/etc/NEWS b/etc/NEWS
index cc4714e71c..2fdc63551f 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2734,6 +2734,11 @@ The default timeout value can be defined by the new variable
 ** New function 'seq-split'.
 This returns a list of sub-sequences of the specified sequence.
 
++++
+** New function 'seq-remove-at-position'.
+This function returns a copy of the specified sequence where the
+element at a given (zero-based) index got removed.
+
 +++
 ** 'plist-get', 'plist-put' and 'plist-member' are no longer limited to 'eq'.
 These function now take an optional comparison predicate argument.
diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el
index b6f0f66e5b..4d05f2c589 100644
--- a/lisp/emacs-lisp/seq.el
+++ b/lisp/emacs-lisp/seq.el
@@ -346,6 +346,20 @@ seq-remove
   (seq-filter (lambda (elt) (not (funcall pred elt)))
               sequence))
 
+;;;###autoload
+(cl-defgeneric seq-remove-at-position (sequence n)
+  "Return a copy of SEQUENCE where the element at N got removed.
+
+N is the (zero-based) index of the element that should not be in
+the result.
+
+The result is a sequence of the same type as SEQUENCE."
+  (seq-concatenate
+   (let ((type (type-of sequence)))
+     (if (eq type 'cons) 'list type))
+   (seq-subseq sequence 0 n)
+   (seq-subseq sequence (1+ n))))
+
 ;;;###autoload
 (cl-defgeneric seq-reduce (function sequence initial-value)
   "Reduce the function FUNCTION across SEQUENCE, starting with INITIAL-VALUE.
diff --git a/lisp/emacs-lisp/shortdoc.el b/lisp/emacs-lisp/shortdoc.el
index 990dabe351..6a366ec0fc 100644
--- a/lisp/emacs-lisp/shortdoc.el
+++ b/lisp/emacs-lisp/shortdoc.el
@@ -888,6 +888,9 @@ sequence
    :eval (seq-filter #'numberp '(a b 3 4 f 6)))
   (seq-remove
    :eval (seq-remove #'numberp '(1 2 c d 5)))
+  (seq-remove-at-position
+   :eval (seq-remove-at-position '(a b c d e) 3)
+   :eval (seq-remove-at-position [a b c d e] 0))
   (seq-group-by
    :eval (seq-group-by #'cl-plusp '(-1 2 3 -4 -5 6)))
   (seq-union
diff --git a/test/lisp/emacs-lisp/seq-tests.el b/test/lisp/emacs-lisp/seq-tests.el
index 1a27467d29..6249e48617 100644
--- a/test/lisp/emacs-lisp/seq-tests.el
+++ b/test/lisp/emacs-lisp/seq-tests.el
@@ -137,6 +137,14 @@ test-seq-remove
   (with-test-sequences (seq '())
     (should (equal (seq-remove #'test-sequences-evenp seq) '()))))
 
+(ert-deftest test-seq-remove-at-position ()
+  (with-test-sequences (seq '(1 2 3 4))
+    (should (same-contents-p (seq-remove-at-position seq 2) '(1 2 4)))
+    (should (same-contents-p (seq-remove-at-position seq 0) '(2 3 4)))
+    (should (same-contents-p (seq-remove-at-position seq 3) '(1 2 3)))
+    (should (eq (type-of (seq-remove-at-position seq 2))
+                (type-of seq)))))
+
 (ert-deftest test-seq-count ()
   (with-test-sequences (seq '(6 7 8 9 10))
     (should (equal (seq-count #'test-sequences-evenp seq) 3))
-- 
2.36.2


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

* bug#57564: Add new function `seq-remove-at-position'
  2022-09-03 17:09 bug#57564: Add new function `seq-remove-at-position' Damien Cassou
@ 2022-09-03 19:21 ` Juri Linkov
  2022-09-03 19:58   ` Damien Cassou
  2022-09-04 11:07 ` Lars Ingebrigtsen
  1 sibling, 1 reply; 7+ messages in thread
From: Juri Linkov @ 2022-09-03 19:21 UTC (permalink / raw)
  To: Damien Cassou; +Cc: 57564

> here is a patch adding seq-remove-at-position to seq.el.

I guess your next patch will be for seq-remove-at-positions
with a list of positions to remove ;-)





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

* bug#57564: Add new function `seq-remove-at-position'
  2022-09-03 19:21 ` Juri Linkov
@ 2022-09-03 19:58   ` Damien Cassou
  2022-09-04  2:44     ` Michael Heerdegen
  0 siblings, 1 reply; 7+ messages in thread
From: Damien Cassou @ 2022-09-03 19:58 UTC (permalink / raw)
  To: Juri Linkov; +Cc: 57564

Juri Linkov <juri@linkov.net> writes:
>> here is a patch adding seq-remove-at-position to seq.el.
>
> I guess your next patch will be for seq-remove-at-positions
> with a list of positions to remove ;-)

who knows :-).

-- 
Damien Cassou

"Success is the ability to go from one failure to another without
losing enthusiasm." --Winston Churchill





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

* bug#57564: Add new function `seq-remove-at-position'
  2022-09-03 19:58   ` Damien Cassou
@ 2022-09-04  2:44     ` Michael Heerdegen
  2022-09-04  8:21       ` Damien Cassou
  0 siblings, 1 reply; 7+ messages in thread
From: Michael Heerdegen @ 2022-09-04  2:44 UTC (permalink / raw)
  To: Damien Cassou; +Cc: 57564, Juri Linkov

Damien Cassou <damien@cassou.me> writes:

> Juri Linkov <juri@linkov.net> writes:
> >> here is a patch adding seq-remove-at-position to seq.el.
> >
> > I guess your next patch will be for seq-remove-at-positions
> > with a list of positions to remove ;-)
>
> who knows :-).

I want to know.  What else do you plan?

Michael.





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

* bug#57564: Add new function `seq-remove-at-position'
  2022-09-04  2:44     ` Michael Heerdegen
@ 2022-09-04  8:21       ` Damien Cassou
  2022-09-04  8:26         ` Eli Zaretskii
  0 siblings, 1 reply; 7+ messages in thread
From: Damien Cassou @ 2022-09-04  8:21 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: 57564, Juri Linkov

Michael Heerdegen <michael_heerdegen@web.de> writes:
> What else do you plan?

I'm currently working on a new package I would like to submit to Emacs
core. Here is its description:

;; Thousands times a day you want to jump from a file to its test file
;; (or to its CSS file or any other related file) and just as many
;; times you want to go back to the initial file.  JUMPing to RELated
;; (jumprel) files is what this package is about.

The 2 seq.el functions I just sent patches for are the only ones I need
before sending a patch for jumprel. I'm documenting the package right
now and you shouldn't expect more patches from me before I send my new
package. I can give more information if you want, but it feels out of
scope for this thread.

-- 
Damien Cassou

"Success is the ability to go from one failure to another without
losing enthusiasm." --Winston Churchill





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

* bug#57564: Add new function `seq-remove-at-position'
  2022-09-04  8:21       ` Damien Cassou
@ 2022-09-04  8:26         ` Eli Zaretskii
  0 siblings, 0 replies; 7+ messages in thread
From: Eli Zaretskii @ 2022-09-04  8:26 UTC (permalink / raw)
  To: Damien Cassou; +Cc: michael_heerdegen, 57564, juri

> Cc: 57564@debbugs.gnu.org, Juri Linkov <juri@linkov.net>
> From: Damien Cassou <damien@cassou.me>
> Date: Sun, 04 Sep 2022 10:21:50 +0200
> 
> I'm currently working on a new package I would like to submit to Emacs
> core. Here is its description:
> 
> ;; Thousands times a day you want to jump from a file to its test file
> ;; (or to its CSS file or any other related file) and just as many
> ;; times you want to go back to the initial file.  JUMPing to RELated
> ;; (jumprel) files is what this package is about.

How will this be different from what we already have:

  . the find-file.el package
  . the new command 'find-sibling-file'





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

* bug#57564: Add new function `seq-remove-at-position'
  2022-09-03 17:09 bug#57564: Add new function `seq-remove-at-position' Damien Cassou
  2022-09-03 19:21 ` Juri Linkov
@ 2022-09-04 11:07 ` Lars Ingebrigtsen
  1 sibling, 0 replies; 7+ messages in thread
From: Lars Ingebrigtsen @ 2022-09-04 11:07 UTC (permalink / raw)
  To: Damien Cassou; +Cc: 57564

Damien Cassou <damien@cassou.me> writes:

> here is a patch adding seq-remove-at-position to seq.el.

Makes sense to me; pushed to Emacs 29.






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

end of thread, other threads:[~2022-09-04 11:07 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-03 17:09 bug#57564: Add new function `seq-remove-at-position' Damien Cassou
2022-09-03 19:21 ` Juri Linkov
2022-09-03 19:58   ` Damien Cassou
2022-09-04  2:44     ` Michael Heerdegen
2022-09-04  8:21       ` Damien Cassou
2022-09-04  8:26         ` Eli Zaretskii
2022-09-04 11:07 ` 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).