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 C6ECC4196F0 for ; Fri, 30 Apr 2010 05:42:50 -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, RCVD_IN_DNSWL_NONE=-0.0001] 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 D423OXzmI6tm for ; Fri, 30 Apr 2010 05:42:50 -0700 (PDT) Received: from homiemail-a15.g.dreamhost.com (mailbigip.dreamhost.com [208.97.132.5]) by olra.theworths.org (Postfix) with ESMTP id EB0AB431FC1 for ; Fri, 30 Apr 2010 05:42:49 -0700 (PDT) Received: from localhost.localdomain (unknown [195.190.188.219]) (Authenticated sender: sebastian@sspaeth.de) by homiemail-a15.g.dreamhost.com (Postfix) with ESMTPA id 94D0B76C06B; Fri, 30 Apr 2010 05:42:48 -0700 (PDT) From: Sebastian Spaeth To: Notmuch developer list Subject: [PATCHv2] Restructure notmuch-hello-reflect Date: Fri, 30 Apr 2010 14:42:45 +0200 Message-Id: <1272631365-27995-1-git-send-email-Sebastian@SSpaeth.de> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1272630482-27386-1-git-send-email-Sebastian@SSpaeth.de> References: <1272630482-27386-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:42:50 -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 --- 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