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 8EF5F418C3C for ; Tue, 13 Apr 2010 11:47:25 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -2.301 X-Spam-Level: X-Spam-Status: No, score=-2.301 tagged_above=-999 required=5 tests=[BAYES_20=-0.001, RCVD_IN_DNSWL_MED=-2.3] 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 tj0qlkNOhVxs for ; Tue, 13 Apr 2010 11:47:21 -0700 (PDT) Received: from ipex4.johnshopkins.edu (ipex4.johnshopkins.edu [128.220.161.141]) by olra.theworths.org (Postfix) with ESMTP id 40B7F418C25 for ; Tue, 13 Apr 2010 11:47:21 -0700 (PDT) X-IronPort-AV: E=Sophos;i="4.52,199,1270440000"; d="scan'208";a="354301918" Received: from c-69-255-36-229.hsd1.md.comcast.net (HELO lucky) ([69.255.36.229]) by ipex4.johnshopkins.edu with ESMTP/TLS/AES256-SHA; 13 Apr 2010 14:47:20 -0400 Received: from jkr by lucky with local (Exim 4.69) (envelope-from ) id 1O1l8p-0006Md-Or; Tue, 13 Apr 2010 14:47:19 -0400 From: Jesse Rosenthal To: Carl Worth , notmuch@notmuchmail.org Subject: [PATCH] Fix bug, and clean up code duplication, in adding or removing tag by region. In-Reply-To: <878w8rkzis.fsf@yoom.home.cworth.org> References: <87sk90ragj.fsf@jhu.edu> <87aatfq88h.fsf@yoom.home.cworth.org> <877hogaf7v.fsf@jhu.edu> <878w8rkzis.fsf@yoom.home.cworth.org> Date: Tue, 13 Apr 2010 14:47:19 -0400 Message-ID: <871vejxk94.fsf@jhu.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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: Tue, 13 Apr 2010 18:47:25 -0000 There was a bug in notmuch-search-{add,remove}-tag-region, which would not behave correctly if the region went beyond the last message. Now, instead of simply iterating to the last line of the region, these functions will iterate to the minimum of the last line of the region and the last possible line, i.e. (- (line-number-at-pos (point-max)) 2) Also clean up code duplication, as per Carl's suggestion, by making notmuch-search-{add/remove}-tag-thread a special case of the -region commands, where the region in question is between (point) and (point). --- emacs/notmuch.el | 26 ++++++++++++++------------ 1 files changed, 14 insertions(+), 12 deletions(-) diff --git a/emacs/notmuch.el b/emacs/notmuch.el index 517c53a..be09f42 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -399,10 +399,11 @@ Complete list of currently available key bindings: (defun notmuch-search-properties-in-region (property beg end) (save-excursion (let ((output nil) - (last-line (line-number-at-pos end))) + (last-line (line-number-at-pos end)) + (max-line (- (line-number-at-pos (point-max)) 2))) (goto-char beg) (beginning-of-line) - (while (<= (line-number-at-pos) last-line) + (while (<= (line-number-at-pos) (min last-line max-line)) (setq output (cons (get-text-property (point) property) output)) (forward-line 1)) output))) @@ -497,38 +498,39 @@ and will also appear in a buffer named \"*Notmuch errors*\"." (defun notmuch-search-get-tags-region (beg end) (save-excursion (let ((output nil) - (last-line (line-number-at-pos end))) + (last-line (line-number-at-pos end)) + (max-line (- (line-number-at-pos (point-max)) 2))) (goto-char beg) - (while (<= (line-number-at-pos) last-line) + (while (<= (line-number-at-pos) (min last-line max-line)) (setq output (append output (notmuch-search-get-tags))) (forward-line 1)) output))) (defun notmuch-search-add-tag-thread (tag) - (notmuch-call-notmuch-process "tag" (concat "+" tag) (notmuch-search-find-thread-id)) - (notmuch-search-set-tags (delete-dups (sort (cons tag (notmuch-search-get-tags)) 'string<)))) + (notmuch-search-add-tag-region tag (point) (point))) (defun notmuch-search-add-tag-region (tag beg end) (let ((search-id-string (mapconcat 'identity (notmuch-search-find-thread-id-region beg end) " or "))) (notmuch-call-notmuch-process "tag" (concat "+" tag) search-id-string) (save-excursion - (let ((last-line (line-number-at-pos end))) + (let ((last-line (line-number-at-pos end)) + (max-line (- (line-number-at-pos (point-max)) 2))) (goto-char beg) - (while (<= (line-number-at-pos) last-line) + (while (<= (line-number-at-pos) (min last-line max-line)) (notmuch-search-set-tags (delete-dups (sort (cons tag (notmuch-search-get-tags)) 'string<))) (forward-line)))))) (defun notmuch-search-remove-tag-thread (tag) - (notmuch-call-notmuch-process "tag" (concat "-" tag) (notmuch-search-find-thread-id)) - (notmuch-search-set-tags (delete tag (notmuch-search-get-tags)))) + (notmuch-search-remove-tag-region tag (point) (point))) (defun notmuch-search-remove-tag-region (tag beg end) (let ((search-id-string (mapconcat 'identity (notmuch-search-find-thread-id-region beg end) " or "))) (notmuch-call-notmuch-process "tag" (concat "-" tag) search-id-string) (save-excursion - (let ((last-line (line-number-at-pos end))) + (let ((last-line (line-number-at-pos end)) + (max-line (- (line-number-at-pos (point-max)) 2))) (goto-char beg) - (while (<= (line-number-at-pos) last-line) + (while (<= (line-number-at-pos) (min last-line max-line)) (notmuch-search-set-tags (delete tag (notmuch-search-get-tags))) (forward-line)))))) -- 1.6.5.3