Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add REVERSE argument to ne2wm:find-next-in-seq

  • Loading branch information...
commit 751633bad3d825672302002a85cc82c382013afb 1 parent 7c712eb
@tkf authored
Showing with 9 additions and 3 deletions.
  1. +4 −2 ne2wm-utils.el
  2. +5 −1 tests/test-ne2wm-utils.el
View
6 ne2wm-utils.el
@@ -145,10 +145,11 @@ Currently, only Magit (Git) and Monky (Mercurial) are supported."
(e2wm:pst-update-windows))
-(defun ne2wm:find-next-in-seq (seq item &optional offset)
+(defun ne2wm:find-next-in-seq (seq item &optional offset reverse)
"[internal] Return OFFSET-next position from ITEM in SEQ.
If OFFSET is omitted or nil, it is assumed to be 1.
+If REVERSE is non-nil, find OFFSET-previous position instead.
Examples:
(ne2wm:find-next-in-seq '(a b c d) 'b) ; => c
@@ -159,7 +160,8 @@ Examples:
(nth (loop for current in seq
for i from 0
when (eql current item)
- return (mod (+ i (or offset 1)) (length seq)))
+ return (mod (funcall (if reverse #'- #'+) i (or offset 1))
+ (length seq)))
seq))
View
6 tests/test-ne2wm-utils.el
@@ -33,7 +33,11 @@
(should (eql (ne2wm:find-next-in-seq '(a b c d) 'b) 'c))
(should (eql (ne2wm:find-next-in-seq '(a b c d) 'd) 'a))
(should (eql (ne2wm:find-next-in-seq '(a b c d) 'b 2) 'd))
- (should (eql (ne2wm:find-next-in-seq '(a b c d) 'b -1) 'a)))
+ (should (eql (ne2wm:find-next-in-seq '(a b c d) 'b -1) 'a))
+ (should (eql (ne2wm:find-next-in-seq '(a b c d) 'c nil t) 'b))
+ (should (eql (ne2wm:find-next-in-seq '(a b c d) 'a nil t) 'd))
+ (should (eql (ne2wm:find-next-in-seq '(a b c d) 'd 2 t) 'b))
+ (should (eql (ne2wm:find-next-in-seq '(a b c d) 'a -1 t) 'b)))
(provide 'test-ne2wm-utils)
Please sign in to comment.
Something went wrong with that request. Please try again.