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 269FA431FD0 for ; Sun, 22 May 2011 11:57:40 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.799 X-Spam-Level: X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled 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 7m7BDDqY+2TG for ; Sun, 22 May 2011 11:57:39 -0700 (PDT) Received: from mail-fx0-f53.google.com (mail-fx0-f53.google.com [209.85.161.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 25B4E431FB6 for ; Sun, 22 May 2011 11:57:39 -0700 (PDT) Received: by fxm8 with SMTP id 8so3802481fxm.26 for ; Sun, 22 May 2011 11:57:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer; bh=i841bAsi2HFEniAaMgQTp10UhOXpcCp2T4rjh5Bp3+I=; b=fyLxi+zXV5x2wE+updedb4fLEUPWm5O+XeSwCk0qmwL1R8BDaqs3w8DEeOta1NKJbr JcWHWkt+HhZz8FMOVgmQ6lwLYfmY/WFdMgdeN5j1bgRLGS3CrB8p0Uc/He1I1B6EIFBi VfpwB651r4c/eCp85XmMD1OYJYYFxgfgijewo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; b=odXwAWAgWwwp4Cjy1M8XuSscpceYbWp7mjxkTL2w+kUA3P3ns2Vq+/OrIK5EoR+8vt mv4cyaPAVcosQR/kxawCB24hagSbZJplZ0OI3fPIpWHjB0Xk4RhJJR8IqEDxVHBmNOHX MvDr2phqEXhO0DqhB4uKXdxkMPucoI2sbkHaM= Received: by 10.223.62.194 with SMTP id y2mr1606769fah.123.1306090657542; Sun, 22 May 2011 11:57:37 -0700 (PDT) Received: from localhost ([91.144.186.21]) by mx.google.com with ESMTPS id 14sm2063558fas.6.2011.05.22.11.57.36 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 22 May 2011 11:57:36 -0700 (PDT) From: Dmitry Kurochkin To: notmuch@notmuchmail.org Subject: [PATCH 1/3] Use different labels for wash buttons when text is visible or hidden. Date: Sun, 22 May 2011 22:57:53 +0400 Message-Id: <1306090675-26982-1-git-send-email-dmitry.kurochkin@gmail.com> X-Mailer: git-send-email 1.7.5.1 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: Sun, 22 May 2011 18:57:40 -0000 Before the change, citation and signature wash buttons used the same label in both visible and hidden states. Sometimes it is very convenient when you can determine if the text is hidden or shown without reading the context and/or clicking the button. The patch makes it easy to see if the text is shown or hidden by explicitly saying what the button does (shows or hides the text). --- emacs/notmuch-wash.el | 55 +++++++++++++++++++++++++++++++++++------------- 1 files changed, 40 insertions(+), 15 deletions(-) diff --git a/emacs/notmuch-wash.el b/emacs/notmuch-wash.el index 0e64eb2..863459e 100644 --- a/emacs/notmuch-wash.el +++ b/emacs/notmuch-wash.el @@ -35,16 +35,26 @@ "\\(^[[:space:]]*>.*\n\\)+" "Pattern to match citation lines.") -(defvar notmuch-wash-signature-button-format - "[ %d-line signature. Click/Enter to toggle visibility. ]" +(defvar notmuch-wash-button-signature-hidden-format + "[ %d-line signature. Click/Enter to show. ]" "String used to construct button text for hidden signatures. Can use up to one integer format parameter, i.e. %d") -(defvar notmuch-wash-citation-button-format - "[ %d more citation lines. Click/Enter to toggle visibility. ]" +(defvar notmuch-wash-button-signature-visible-format + "[ %d-line signature. Click/Enter to hide. ]" + "String used to construct button text for visible signatures. +Can use up to one integer format parameter, i.e. %d") + +(defvar notmuch-wash-button-citation-hidden-format + "[ %d more citation lines. Click/Enter to show. ]" "String used to construct button text for hidden citations. Can use up to one integer format parameter, i.e. %d") +(defvar notmuch-wash-button-citation-visible-format + "[ %d more citation lines. Click/Enter to hide. ]" + "String used to construct button text for visible citations. +Can use up to one integer format parameter, i.e. %d") + (defvar notmuch-wash-signature-lines-max 12 "Maximum length of signature that will be hidden by default.") @@ -69,6 +79,16 @@ collapse the remaining lines into a button.") (if (invisible-p invis-spec) (remove-from-invisibility-spec invis-spec) (add-to-invisibility-spec invis-spec))) + (let* ((new-start (button-start cite-button)) + (overlay (button-get cite-button 'overlay)) + (button-label (notmuch-wash-button-label overlay)) + (inhibit-read-only t)) + (save-excursion + (goto-char new-start) + (insert button-label) + (let ((old-end (button-end cite-button))) + (move-overlay cite-button new-start (point)) + (delete-region (point) old-end)))) (force-window-update) (redisplay t)) @@ -88,13 +108,21 @@ collapse the remaining lines into a button.") (defun notmuch-wash-region-isearch-show (overlay) (remove-from-invisibility-spec (overlay-get overlay 'invisible))) -(defun notmuch-wash-region-to-button (beg end type prefix button-text) +(defun notmuch-wash-button-label (overlay) + (let* ((type (overlay-get overlay 'type)) + (invis-spec (overlay-get overlay 'invisible)) + (state (if (invisible-p invis-spec) "hidden" "visible")) + (label-format (symbol-value (intern-soft (concat "notmuch-wash-button-" + type "-" state "-format")))) + (lines-count (count-lines (overlay-start overlay) (overlay-end overlay)))) + (format label-format lines-count))) + +(defun notmuch-wash-region-to-button (beg end type prefix) "Auxilary function to do the actual making of overlays and buttons BEG and END are buffer locations. TYPE should a string, either \"citation\" or \"signature\". PREFIX is some arbitrary text to -insert before the button, probably for indentation. BUTTON-TEXT -is what to put on the button." +insert before the button, probably for indentation." ;; This uses some slightly tricky conversions between strings and ;; symbols because of the way the button code works. Note that @@ -108,12 +136,14 @@ is what to put on the button." (add-to-invisibility-spec invis-spec) (overlay-put overlay 'invisible invis-spec) (overlay-put overlay 'isearch-open-invisible #'notmuch-wash-region-isearch-show) + (overlay-put overlay 'type type) (goto-char (1+ end)) (save-excursion (goto-char (1- beg)) (insert prefix) - (insert-button button-text + (insert-button (notmuch-wash-button-label overlay) 'invisibility-spec invis-spec + 'overlay overlay :type button-type)))) (defun notmuch-wash-excerpt-citations (depth) @@ -136,11 +166,7 @@ is what to put on the button." (forward-line (- notmuch-wash-citation-lines-suffix)) (notmuch-wash-region-to-button hidden-start (point-marker) - "citation" "\n" - (format notmuch-wash-citation-button-format - (- cite-lines - notmuch-wash-citation-lines-prefix - notmuch-wash-citation-lines-suffix))))))) + "citation" "\n"))))) (if (and (not (eobp)) (re-search-forward notmuch-wash-signature-regexp nil t)) (let* ((sig-start (match-beginning 0)) @@ -154,8 +180,7 @@ is what to put on the button." (overlay-put (make-overlay sig-start-marker sig-end-marker) 'face 'message-cited-text) (notmuch-wash-region-to-button sig-start-marker sig-end-marker - "signature" "\n" - (format notmuch-wash-signature-button-format sig-lines))))))) + "signature" "\n")))))) ;; -- 1.7.5.1