Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 4DCCA4196F0 for ; Fri, 30 Apr 2010 05:28:09 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -1.9 X-Spam-Level: X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5 tests=[BAYES_00=-1.9] autolearn=ham Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id IsYj7+fZUC61 for ; Fri, 30 Apr 2010 05:28:08 -0700 (PDT) Received: from homiemail-a23.g.dreamhost.com (caiajhbdccac.dreamhost.com [208.97.132.202]) by olra.theworths.org (Postfix) with ESMTP id 7A2CF431FC1 for ; Fri, 30 Apr 2010 05:28:08 -0700 (PDT) Received: from localhost.localdomain (unknown [195.190.188.219]) (Authenticated sender: sebastian@sspaeth.de) by homiemail-a23.g.dreamhost.com (Postfix) with ESMTPA id EAB114B006D; Fri, 30 Apr 2010 05:28:05 -0700 (PDT) From: Sebastian Spaeth To: Notmuch developer list Subject: [PATCH] Restructure notmuch-hello-reflect Date: Fri, 30 Apr 2010 14:28:02 +0200 Message-Id: <1272630482-27386-1-git-send-email-Sebastian@SSpaeth.de> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1272623637-23951-1-git-send-email-Sebastian@SSpaeth.de> References: <1272623637-23951-1-git-send-email-Sebastian@SSpaeth.de> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 30 Apr 2010 12:28:09 -0000 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 --- emacs/notmuch-hello.el | 36 ++++++++++++++---------------------- 1 files changed, 14 insertions(+), 22 deletions(-) diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el index 1358387..1999858 100644 --- a/emacs/notmuch-hello.el +++ b/emacs/notmuch-hello.el @@ -113,29 +113,21 @@ 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)))) + "Transpose a `ncols' wide matrix `list' along diagonal." + (let ((brows (ceiling (length list) ncols)) ;;#rows of new matrix + bvector offset) + (setq bvector (make-vector (length list) nil));;vector to be returned + (dotimes (pos (length list)) + (aset bvector pos + (elt list (setq offset + (cond ;;return row number if in first colum + ((eq 0 (% pos ncols)) + (setq offset (floor pos ncols))) + ((>= (% (length list) 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