Browse files

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

  • Loading branch information...
tkf committed Aug 26, 2012
1 parent 7c712eb commit 751633bad3d825672302002a85cc82c382013afb
Showing with 9 additions and 3 deletions.
  1. +4 −2 ne2wm-utils.el
  2. +5 −1 tests/test-ne2wm-utils.el
@@ -145,10 +145,11 @@ Currently, only Magit (Git) and Monky (Mercurial) are supported."
-(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.
(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)))
@@ -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)

0 comments on commit 751633b

Please sign in to comment.