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 1DD6A431FBC for ; Thu, 24 Dec 2009 06:39:18 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org 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 lsCPVCYfQt41 for ; Thu, 24 Dec 2009 06:39:17 -0800 (PST) Received: from pivot.cs.unb.ca (pivot.cs.unb.ca [131.202.240.57]) by olra.theworths.org (Postfix) with ESMTP id 6850F431FAE for ; Thu, 24 Dec 2009 06:39:17 -0800 (PST) Received: from fctnnbsc30w-142167182194.pppoe-dynamic.high-speed.nb.bellaliant.net ([142.167.182.194] helo=localhost) by pivot.cs.unb.ca with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1NNoqR-00086Y-Se; Thu, 24 Dec 2009 10:39:16 -0400 Received: from bremner by localhost with local (Exim 4.71) (envelope-from ) id 1NNoqM-0000eM-DJ; Thu, 24 Dec 2009 10:39:10 -0400 From: david@tethera.net To: notmuch@notmuchmail.org Date: Thu, 24 Dec 2009 10:38:54 -0400 Message-Id: <1261665534-2445-1-git-send-email-david@tethera.net> X-Mailer: git-send-email 1.6.5.7 In-Reply-To: <87ws0jydx0.fsf@yoom.home.cworth.org> References: <87ws0jydx0.fsf@yoom.home.cworth.org> X-Sender-Verified: bremner@pivot.cs.unb.ca Cc: David Bremner Subject: [notmuch] [PATCH] notmuch.el: Refactor citation markup. Variables for minimum size, button text. X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.12 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: Thu, 24 Dec 2009 14:39:18 -0000 From: David Bremner This is a fairly intrusive rewrite. - I pulled the common code for the signature and citation case out into a separate function. This is not so much shorter, but I think it will be easier to maintain. - I replaced the sequence of (looking-at blah) (forward-line) with a single re-search-forward per citation. New variables - notmuch-show-signature-button-format, notmuch-show-citation-button-format Allow customization of button text. - notmuch-show-citation-lines-min Do not buttonize citations below the given threshold. --- I decided to start with a simple threshold, and only convert sufficiently long citations to buttons. Once I started messing with that code, I decided to rework it to be more maintainable and hopefully faster. This patch also fixes the problem of merging cites separated by a single line of whitespace This is also fixed by the much simpler <1260769295-12924-3-git-send-email-kanru@kanru.info>, but unlike that patch there _shouldn't_ be a problem with eating the blank line after a citation. I'm not sure about the other bugs fixed by Kan-Ru's series; perhaps Kan-Ru can comment. notmuch.el | 130 ++++++++++++++++++++++++++++++++++++++---------------------- 1 files changed, 83 insertions(+), 47 deletions(-) diff --git a/notmuch.el b/notmuch.el index 97914f2..6a5ceea 100644 --- a/notmuch.el +++ b/notmuch.el @@ -92,9 +92,24 @@ for indentation at the beginning of the line. But notmuch will move past the indentation when testing this pattern, (so that the pattern can still test against the entire line).") +(defvar notmuch-show-signature-button-format + "[ %d-line hidden 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-show-citation-button-format + "[ %d-line hidden citation. 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-show-signature-lines-max 12 "Maximum length of signature that will be hidden by default.") +(defvar notmuch-show-citation-lines-min 4 + "Minimum length of citation that will be hidden.") + (defvar notmuch-command "notmuch" "Command to run the notmuch binary.") @@ -593,54 +608,75 @@ which this thread was originally shown." 'face 'notmuch-message-summary-face :supertype 'notmuch-button-invisibility-toggle-type) +(defun notmuch-show-citation-regexp (depth) + "Build a regexp for matching citations at a given DEPTH (indent)" + (let ((line-regexp (format "[[:space:]]\\{%d\\}*>.*\n" depth))) + (concat "\\(?:^" line-regexp + "\\(?:[[:space:]]*\n" line-regexp + "\\)?\\)+"))) + +(defun notmuch-show-region-to-button (beg end type prefix button-text) + "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." + +;; This uses some slightly tricky conversions between strings and +;; symbols because of the way the button code works. Note that +;; replacing intern-soft with make-symbol will cause this to fail, +;; since the newly created symbol has no plist. + + (let ((overlay (make-overlay beg end)) + (invis-spec (make-symbol (concat "notmuch-" type "-region"))) + (button-type (intern-soft (concat "notmuch-button-" + type "-toggle-type")))) + (add-to-invisibility-spec invis-spec) + (overlay-put overlay 'invisible invis-spec) + (goto-char (1+ end)) + (save-excursion + (goto-char (1- beg)) + (insert prefix) + (insert-button button-text + 'invisibility-spec invis-spec + :type button-type) + ))) + + (defun notmuch-show-markup-citations-region (beg end depth) - (goto-char beg) - (beginning-of-line) - (while (< (point) end) - (let ((beg-sub (point-marker)) - (indent (make-string depth ? )) - (citation ">")) - (move-to-column depth) - (if (looking-at citation) - (progn - (while (looking-at citation) - (forward-line) - (move-to-column depth)) - (let ((overlay (make-overlay beg-sub (point))) - (invis-spec (make-symbol "notmuch-citation-region"))) - (add-to-invisibility-spec invis-spec) - (overlay-put overlay 'invisible invis-spec) - (let ((p (point-marker)) - (cite-button-text - (concat "[" (number-to-string (count-lines beg-sub (point))) - "-line citation. Click/Enter to show.]"))) - (goto-char (- beg-sub 1)) - (insert (concat "\n" indent)) - (insert-button cite-button-text - 'invisibility-spec invis-spec - :type 'notmuch-button-citation-toggle-type) - (forward-line) - )))) - (move-to-column depth) - (if (looking-at notmuch-show-signature-regexp) - (let ((sig-lines (- (count-lines beg-sub end) 1))) - (if (<= sig-lines notmuch-show-signature-lines-max) - (progn - (let ((invis-spec (make-symbol "notmuch-signature-region"))) - (add-to-invisibility-spec invis-spec) - (overlay-put (make-overlay beg-sub end) - 'invisible invis-spec) - - (goto-char (- beg-sub 1)) - (insert (concat "\n" indent)) - (let ((sig-button-text (concat "[" (number-to-string sig-lines) - "-line signature. Click/Enter to show.]"))) - (insert-button sig-button-text 'invisibility-spec invis-spec - :type 'notmuch-button-signature-toggle-type) - ) - (insert "\n") - (goto-char end)))))) - (forward-line)))) + "Markup citations, and up to one signature in the given region" + + (let ((citation-regexp (notmuch-show-citation-regexp depth)) + (signature-regexp (concat (format "^[[:space:]]\\{%d\\}" depth) + notmuch-show-signature-regexp)) + (indent (make-string depth ? ))) + (goto-char beg) + (beginning-of-line) + (while (and (< (point) end) + (re-search-forward citation-regexp end t)) + (let* ((cite-start (match-beginning 0)) + (cite-end (match-end 0)) + (cite-lines (count-lines cite-start cite-end))) + (if (>= cite-lines notmuch-show-citation-lines-min) + (notmuch-show-region-to-button + cite-start cite-end + "citation" + indent + (format notmuch-show-citation-button-format cite-lines) + )))) + (if (re-search-forward signature-regexp end t) + (let* ((sig-start (match-beginning 0)) + (sig-end (match-end 0)) + (sig-lines (1- (count-lines sig-start end)))) + (if (<= sig-lines notmuch-show-signature-lines-max) + (notmuch-show-region-to-button + sig-start + end + "signature" + indent + (format notmuch-show-signature-button-format sig-lines) + )))))) (defun notmuch-show-markup-part (beg end depth) (if (re-search-forward notmuch-show-part-begin-regexp nil t) -- 1.6.5.7