From fea883eef5d80866a41ce61df91e925b6d2cb417 Mon Sep 17 00:00:00 2001 From: Mark Walters Date: Sat, 6 Sep 2014 17:22:11 +0100 Subject: [PATCH] [Patch v2 2/2] emacs: show: mark messages unread if seen in buffer --- 03/f9a9a844d27e4266ded69407ca100aed55c56b | 165 ++++++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 03/f9a9a844d27e4266ded69407ca100aed55c56b diff --git a/03/f9a9a844d27e4266ded69407ca100aed55c56b b/03/f9a9a844d27e4266ded69407ca100aed55c56b new file mode 100644 index 000000000..f19ca2a6a --- /dev/null +++ b/03/f9a9a844d27e4266ded69407ca100aed55c56b @@ -0,0 +1,165 @@ +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 A6A80431FC9 + for ; Sat, 6 Sep 2014 09:22:29 -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 aS7uEH18ZMXQ for ; + Sat, 6 Sep 2014 09:22:24 -0700 (PDT) +Received: from mail-we0-f179.google.com (mail-we0-f179.google.com + [74.125.82.179]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 74CE9431FBD + for ; Sat, 6 Sep 2014 09:22:19 -0700 (PDT) +Received: by mail-we0-f179.google.com with SMTP id t60so13004364wes.38 + for ; Sat, 06 Sep 2014 09:22:18 -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=KjyWvD6uthdBToASOkGKWvGoe4QzlekxHceLBhw5fUk=; + b=dKjq2dpM0nnBlNl1G1Opv4Ki6upsA8OPg6nKLgMQz49kPHUBd5xRtKD4JtgH1XAZTV + rVtiFM+EK2c+wFUuaQp7sQp5u4cwVH2ezL3EHf+AXx8skRZVtvkUOAGmoRLU+w7X8pv/ + wiiEnSAbaCne9xSlIQyqYFSB05SXaQuNkfrRGlZY3UPXLV2uBhnny1oPEGO2+fr1y2Eq + x+vExw8ohAnbZs/oSQ34c/K4+gzNkrNKZXYCZtQNGtPFOhJDhk4R/nUo/BpEoldZj6j8 + dgrj7do18+IuhE0hzB410N7tYdZZ6FvifLc29CUtj0Hg4Nv5zICkjaKv8U5bwXETxO6R + VI3g== +X-Received: by 10.194.58.244 with SMTP id u20mr22729067wjq.36.1410020538330; + Sat, 06 Sep 2014 09:22:18 -0700 (PDT) +Received: from localhost (5751dfa2.skybroadband.com. [87.81.223.162]) + by mx.google.com with ESMTPSA id h6sm4976836wjb.33.2014.09.06.09.22.17 + for + (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); + Sat, 06 Sep 2014 09:22:17 -0700 (PDT) +From: Mark Walters +To: notmuch@notmuchmail.org +Subject: [Patch v2 2/2] emacs: show: mark messages unread if seen in buffer +Date: Sat, 6 Sep 2014 17:22:11 +0100 +Message-Id: <1410020531-24419-3-git-send-email-markwalters1009@gmail.com> +X-Mailer: git-send-email 1.7.10.4 +In-Reply-To: <1410020531-24419-1-git-send-email-markwalters1009@gmail.com> +References: <1410020531-24419-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: Sat, 06 Sep 2014 16:22:29 -0000 + +This adds a function that marks messages unread if they are "seen" +that is a user configurable amount of them has been visible in the +buffer. +--- + emacs/notmuch-show.el | 74 ++++++++++++++++++++++++++++++++++++++++++++++++- + 1 file changed, 73 insertions(+), 1 deletion(-) + +diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el +index 5695d95..7d2c5d2 100644 +--- a/emacs/notmuch-show.el ++++ b/emacs/notmuch-show.el +@@ -231,7 +231,27 @@ be the start and end of the visible portion of the buffer and + should mark the appropriate messages read by applying + `notmuch-show-mark-read'. This function will be called after + every user interaction with notmuch." +- :type 'function ++ :type '(radio (const :format "%h" :doc "Mark current message read. ++ ++Marks the message containing point read." ++ notmuch-show-seen-current-message) ++ (group :format "%v" ++ (const :inline t :format "" (lambda (start end))) ++ (list :format "%h %v\n" ++ :doc "Mark read if enough of the message has been visible. ++ ++A message is marked read 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. The definition of enough is ++controlled by the following paramater. Seeing the bottom of message is ++always deemed enough. Additionally, it is deemed enough if a ++point n lines into the message has been visible in the window ++where n is this variable if this variable is an integer and n is ++this variable times the height of the window if this variable is ++a float." ++ (const :inline t :tag "" :format "" (notmuch-show-do-seen start end)) ++ (number :tag "Proportion needed" 0.75))) ++ (function)) + :group 'notmuch-show) + + (defmacro with-current-notmuch-show-message (&rest body) +@@ -1576,6 +1596,58 @@ marked as unread, i.e. the tag changes in + (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 (needed 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. Enough means either the ++bottom of the message or a point in the message more than ++LINES-NEEDED lines into the message. LINES-NEEDED is ++NEEDED if NEEDED is an integer and NEEDED ++times the current window height if NEEDED is a float." ++ (let* ((lines-needed (if (integerp needed) ++ needed ++ (truncate (* 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 needed) ++ "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 `notmuch-show-do-message-seen` 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 needed start end) ++ (while (and (< (notmuch-show-message-bottom) end) ++ (notmuch-show-goto-message-next)) ++ (notmuch-show-do-message-seen needed 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-seen-current-message (start end) + "Mark the current message read if it is open. + +-- +1.7.10.4 + -- 2.26.2