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 00F7E431FBC for ; Thu, 24 Dec 2009 17:48:05 -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 hSo2Zg1uuRtW for ; Thu, 24 Dec 2009 17:48:04 -0800 (PST) Received: from cp20.secserverpros.com (cp20.secserverpros.com [67.220.217.187]) by olra.theworths.org (Postfix) with ESMTP id C3ABE431FAE for ; Thu, 24 Dec 2009 17:48:03 -0800 (PST) Received: from 61-30-10-70.static.tfn.net.tw ([61.30.10.70] helo=kanru.info) by cp20.secserverpros.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.69) (envelope-from ) id 1NNzHd-0007y4-78 for notmuch@notmuchmail.org; Fri, 25 Dec 2009 01:48:03 +0000 Received: from kanru (uid 1000) (envelope-from kanru@kanru.info) id 4c by kanru.info (DragonFly Mail Agent) Fri, 25 Dec 2009 09:47:05 +0800 From: Kan-Ru Chen To: david@tethera.net, notmuch@notmuchmail.org In-Reply-To: <1261665534-2445-1-git-send-email-david@tethera.net> References: <87ws0jydx0.fsf@yoom.home.cworth.org> <1261665534-2445-1-git-send-email-david@tethera.net> Date: Fri, 25 Dec 2009 09:47:02 +0800 Message-ID: <87my17965l.fsf@anar.kanru.info> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" X-ACL-Warn: { X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - cp20.secserverpros.com X-AntiAbuse: Original Domain - notmuchmail.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - kanru.info X-Source: X-Source-Args: X-Source-Dir: Cc: David Bremner Subject: Re: [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: Fri, 25 Dec 2009 01:48:05 -0000 --=-=-= Content-Transfer-Encoding: quoted-printable On Thu, 24 Dec 2009 10:38:54 -0400, david@tethera.net wrote: > From: David Bremner >=20 > This is a fairly intrusive rewrite. >=20 > - 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. >=20 > - I replaced the sequence of (looking-at blah) (forward-line) with a sin= gle > re-search-forward per citation. >=20 > New variables >=20 > - notmuch-show-signature-button-format, notmuch-show-citation-button-form= at > Allow customization of button text. >=20 > - notmuch-show-citation-lines-min > Do not buttonize citations below the given threshold. I like this idea, but this patch hides all citations larger than the threshold. I'd like to see limited lines of citations been displayed. For example: > Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do > eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enimad > minim veniam, quis nostrud exercitation ullamco laboris nisi ut > aliquip ex ea commodo consequat. Duis aute irure dolor in [ 6-line hidden citation. Click/Enter to show ] And click the button shows the rest. > --- >=20 > 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. >=20 > 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. >=20 > notmuch.el | 130 > ++++++++++++++++++++++++++++++++++++++---------------------- 1 files > changed, 83 insertions(+), 47 deletions(-) >=20 > 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 notm= uch will > move past the indentation when testing this pattern, (so that the > pattern can still test against the entire line).") >=20=20 > +(defvar notmuch-show-signature-button-format=20 > + "[ %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=20 > + "[ %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.") >=20=20 > +(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.") >=20=20 > @@ -593,54 +608,75 @@ which this thread was originally shown." > 'face 'notmuch-message-summary-face > :supertype 'notmuch-button-invisibility-toggle-type) >=20=20 > +(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=20 > + "\\(?:[[: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,=20 > +;; 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-"=20 > + type "-toggle-type")))) > + (add-to-invisibility-spec invis-spec) > + (overlay-put overlay 'invisible invis-spec) > + (goto-char (1+ end)) > + (save-excursion=20 > + (goto-char (1- beg)) > + (insert prefix) > + (insert-button button-text > + 'invisibility-spec invis-spec > + :type button-type) > + ))) > + > +=09=09=09=09=09=09=20 > (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-typ= e) > - (forward-line) > - )))) > - (move-to-column depth) > - (if (looking-at notmuch-show-signature-regexp) > - (let ((sig-lines (- (count-lines beg-sub end) 1))) > - (if (<=3D sig-lines notmuch-show-signature-lines-max) > - (progn > - (let ((invis-spec (make-symbol "notmuch-signature-regi= on"))) > - (add-to-invisibility-spec invis-spec) > - (overlay-put (make-overlay beg-sub end) > - 'invisible invis-spec) > -=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 > - (goto-char (- beg-sub 1)) > - (insert (concat "\n" indent)) > - (let ((sig-button-text (concat "[" (number-to-string= sig-lines) > - "-line signature. Cli= ck/Enter to show.]"))) > - (insert-button sig-button-text 'invisibility-spec = invis-spec > - :type 'notmuch-button-signature-tog= gle-type) > - ) > - (insert "\n") > - (goto-char end)))))) > - (forward-line)))) > + "Markup citations, and up to one signature in the given region" > +=20=20 > + (let ((citation-regexp (notmuch-show-citation-regexp depth)) > + (signature-regexp (concat (format "^[[:space:]]\\{%d\\}" depth)=20 > + notmuch-show-signature-regexp)) > + (indent (make-string depth ? ))) > + (goto-char beg) > + (beginning-of-line) > + (while (and (< (point) end)=20 > + (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 (>=3D cite-lines notmuch-show-citation-lines-min) > + (notmuch-show-region-to-button=20 > + 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 (<=3D sig-lines notmuch-show-signature-lines-max) > + (notmuch-show-region-to-button=20 > + sig-start > + end > + "signature" > + indent > + (format notmuch-show-signature-button-format sig-lines) > + )))))) >=20=20 > (defun notmuch-show-markup-part (beg end depth) > (if (re-search-forward notmuch-show-part-begin-regexp nil t) > --=20 > 1.6.5.7 >=20 > _______________________________________________ > notmuch mailing list > notmuch@notmuchmail.org > http://notmuchmail.org/mailman/listinfo/notmuch =2D-=20 Kan-Ru Chen | http://kanru.info Q: Why are my replies five sentences or less? A: http://five.sentenc.es/ --=-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.13 (GNU/Linux) iQIcBAEBCAAGBQJLNBmYAAoJEBsTLgHOxq1GHjkQAJ0q6tthvg669D19GxpXIKDC FBSsjbB92IpbJaZLg6OZrM+Rkq2sLB7B1hxKukBiF9B7F0BKrUKceZ+ei6Q+FNuU 1BBTKsS/1oBBbOp6sHnq1wDY+YFd+x8lhrGi83V2yWpNjMXy4XOFO8F2Q53gsB0P SloGeit5Dzd3ey3QwDtYuSxhnvOjI4mR0oAZuvoWDNp55wjRJUCj+daspL9gv+qO AVSg8rfzeJ31syq6Me9GEkL9gQABSiEfciH5Nrf7LO+nueEOQ/GeQqolK4H2u/o0 pi68wx03dJfHo04wzSzfVAkg3r/VdtLYs3LyWNVWCH1QZ1cMekR4d5/uFOr9L7If Fj1o38RPaBhLveedz0kz4qcL2Czz7dDWIrEB0t253oGjOmYr3qUX6Pn/bt2YLz0X Sq3iWs3/gEKyi7ll2lPS+RnrRqZoLWMm/RgvseVHG1R38hRBzLa1b8r9jqvwWYVe RqwyjgNl/1Hl5RYL3QmBsJhAzKlTzXzfSKo3KLnY8mgjM46Jl3Yz3sqLQIFQ85mR QAiZMDg14VqTnkt23ZkSbwG/ETsNSjd9TXQfL+veCQTNhmD4oBryOehcUdFlChzF gQRdm3LTCBn6Ok8BPWnj78g11z6GlgZeIhibACXpr6NVB71KhsSQhJ4U0Ztal8eD Tk0hA457z9e9zFtyppSr =2FCw -----END PGP SIGNATURE----- --=-=-=--