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 7C408431FC2 for ; Tue, 25 Mar 2014 13:03:34 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0.201 X-Spam-Level: X-Spam-Status: No, score=0.201 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_ENVFROM_END_DIGIT=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 l2WD0zRWcdGz for ; Tue, 25 Mar 2014 13:03:28 -0700 (PDT) Received: from mail-wi0-f171.google.com (mail-wi0-f171.google.com [209.85.212.171]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id C324F431FC0 for ; Tue, 25 Mar 2014 13:03:24 -0700 (PDT) Received: by mail-wi0-f171.google.com with SMTP id hr14so2383025wib.16 for ; Tue, 25 Mar 2014 13:03:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=VbXhcj1KD/Fx/viQT2LO3fUx6Wp7xDrCmlveWmD3TyY=; b=IsAhFjdkcrcV6j9NjNLRfTK39TUKvOMRdz+j/7eBvzkNxDcsYbfli1/vD6dOzhjcD1 EtygqzyLb8NwPyGMHFQsCzT6TDY44kr7ZMaaeMjQwPinJZCGvdMRT9JxNamNEX6b4Faf WVpF2KCMsbvbIb6GDZ6Vo/Dx+QbAVd3ipV0xUIIRfziutz7al+SF2V9ZUtfa0vsjmHmN 7BVRWD8XFgTbzZzUIQ0OmMqZIKBgzyfPYgAoxzyDof/3Hww91JoJI7nuy8xdsZDyTm8O jtp7fkZeN76QYJ8SBWw5pBtnWjouZJWh6eTqBvN7Wg83Q0Bm40SsE4uR8vObiabcV39r 9x/w== X-Received: by 10.180.188.169 with SMTP id gb9mr24697346wic.17.1395777803721; Tue, 25 Mar 2014 13:03:23 -0700 (PDT) Received: from localhost (93-97-24-31.zone5.bethere.co.uk. [93.97.24.31]) by mx.google.com with ESMTPSA id qg3sm53335450wic.10.2014.03.25.13.03.22 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 25 Mar 2014 13:03:23 -0700 (PDT) From: Mark Walters To: notmuch@notmuchmail.org Subject: [Patch v3 3/3] emacs: show: make `seen' mean user viewed whole message Date: Tue, 25 Mar 2014 20:03:13 +0000 Message-Id: <1395777793-13297-4-git-send-email-markwalters1009@gmail.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1395777793-13297-1-git-send-email-markwalters1009@gmail.com> References: <1395777793-13297-1-git-send-email-markwalters1009@gmail.com> 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, 25 Mar 2014 20:03:34 -0000 This changes `seen' to mean that the user viewed `enough' of the whole message: more precisely, a message is deemed seen if the top of the message and either the bottom of the message or a point at least some customisable number of lines into the message have each been visible in the buffer at some point. This is placed into the post-command-hook infrastructure introduced in the previous patch. --- emacs/notmuch-show.el | 63 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index 1a7de85..1abf24b 100644 --- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -211,6 +211,20 @@ (defcustom notmuch-show-mark-read-tags '("-unread") :type '(repeat string) :group 'notmuch-show) +(defcustom notmuch-show-seen-lines-needed 0.75 + "Control which messages get marked seen. + +A message is marked seen if both the top of the message and a +point far \"enough\" down in the message have each been visible +in the buffer at some point. This parameter controls the +definition of enough. + +Enough means either the bottom of the message or a point in the +message more than LINES-NEEDED lines into the message, where +LINES-NEEDED is this variable if this variable is an integer and +this variable times the current window height if it is a float." + :type 'number + :group 'notmuch-show) (defmacro with-current-notmuch-show-message (&rest body) "Evaluate body with current buffer set to the text of current message" @@ -1532,9 +1546,54 @@ (defun notmuch-show-mark-read (&optional unread) (apply 'notmuch-show-tag-message (notmuch-tag-change-list notmuch-show-mark-read-tags unread)))) +(defun notmuch-show-update-seen (top-or-bottom) + "Update seen status of current message + +Mark that we have seen the TOP-OR-BOTTOM of current message." + (let ((current (notmuch-show-get-prop :seen))) + (unless (or (eq current 'both) (eq current top-or-bottom)) + (if (not current) + (notmuch-show-set-prop :seen top-or-bottom) + (notmuch-show-set-prop :seen 'both) + (notmuch-show-mark-read))))) + +(defun notmuch-show-do-message-seen (start end) + "Update seen status for the current message. + +A message is seen if both the top and enough of the rest of the +message have been visible in the buffer. See the +`notmuch-show-seen-lines-needed' for the definition of `enough'." + (let* ((lines-needed (if (integerp notmuch-show-seen-lines-needed) + notmuch-show-seen-lines-needed + (truncate (* notmuch-show-seen-lines-needed (window-body-height))))) + (top (notmuch-show-message-top)) + (bottom (notmuch-show-message-bottom))) + (when (notmuch-show-message-visible-p) + (when (>= top start) + (notmuch-show-update-seen 'top)) + (when (or (<= bottom end) + (> (count-screen-lines top end) lines-needed)) + (notmuch-show-update-seen 'bottom))))) + (defun notmuch-show-do-seen (start end) - "Update seen status for all messages between start and end." - ) + "Update seen status for all messages between start and end. + +We mark the top (bottom) of a message seen if the top (enough of +the rest of the message) respectively have been visible in the +buffer. See the `notmuch-show-seen-lines-needed' for the +definition of `enough'. When both the top and bottom have been +seen we mark the message read." + (save-excursion + (goto-char start) + (notmuch-show-do-message-seen start end) + (while (and (< (notmuch-show-message-bottom) end) + (notmuch-show-goto-message-next)) + (notmuch-show-do-message-seen start end)) + ;; This is a work around because emacs gives weird answers for + ;; window-end if the buffer ends with invisible text. + (when (and (pos-visible-in-window-p (point-max)) + (notmuch-show-message-visible-p)) + (notmuch-show-update-seen 'bottom)))) (defun notmuch-show-command-hook () (when (eq major-mode 'notmuch-show-mode) -- 1.7.10.4