[PATCHv2] Restructure notmuch-hello-reflect
Sebastian Spaeth
Sebastian at SSpaeth.de
Fri Apr 30 05:42:45 PDT 2010
This function was "not lispy" according to a comment by dme, and it
also relied on a helper function that used 'cl code. Do away with all
that and provide a hopefully lispy solution that relies on elisp only
to "reflect" a (possibly non-square) matrix along it's diagonal.
Remove now unused notmuch-hello-reflect-generate-row function.
Remove unused notmuch-hello-roundup function (which did exactly the
same as (ceiling divident divisor) anyway).
Signed-off-by: Sebastian Spaeth <Sebastian at SSpaeth.de>
---
Just for the record, this is the final cleaned up version.
Still not sure if dme sees it as an improvement though :-)
emacs/notmuch-hello.el | 37 +++++++++++++++----------------------
1 files changed, 15 insertions(+), 22 deletions(-)
diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index 1358387..8dc8ff9 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -113,29 +113,22 @@
maximize (length (car elem)))
0))
-(defun notmuch-hello-roundup (dividend divisor)
- "Return the rounded up value of dividing `dividend' by `divisor'."
- (+ (/ dividend divisor)
- (if (> (% dividend divisor) 0) 1 0)))
-
-(defun notmuch-hello-reflect-generate-row (ncols nrows row list)
- (let ((len (length list)))
- (loop for col from 0 to (- ncols 1)
- collect (let ((offset (+ (* nrows col) row)))
- (if (< offset len)
- (nth offset list)
- ;; Don't forget to insert an empty slot in the
- ;; output matrix if there is no corresponding
- ;; value in the input matrix.
- nil)))))
-
(defun notmuch-hello-reflect (list ncols)
- "Reflect a `ncols' wide matrix represented by `list' along the
-diagonal."
- ;; Not very lispy...
- (let ((nrows (notmuch-hello-roundup (length list) ncols)))
- (loop for row from 0 to (- nrows 1)
- append (notmuch-hello-reflect-generate-row ncols nrows row list))))
+ "Reflect a `ncols' wide matrix `list' along diagonal."
+ (let* ((l (length list))
+ (brows (ceiling l ncols)) ;;#rows of new matrix
+ (bvector (make-vector l nil));;vector to be returned
+ offset)
+ (dotimes (pos l)
+ (aset bvector pos
+ (elt list (setq offset
+ (cond ;;return row number if in first colum
+ ((eq 0 (% pos ncols))
+ (setq offset (floor pos ncols)))
+ ((>= (% l ncols) (% pos ncols))
+ (+ offset brows)) ;;add brows for first 'long'cols
+ (t (1- (+ offset brows)))))))) ;;+ brows-1 for remainder
+ (append bvector nil)));; return bvector as list
(defun notmuch-hello-widget-search (widget &rest ignore)
(notmuch-search (widget-get widget
--
1.7.0.4
More information about the notmuch
mailing list