From: Mark Walters Date: Fri, 9 May 2014 15:45:20 +0000 (+0100) Subject: [RFC PATCH] emacs: show: mark messages unread if seen in buffer X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=3003b29f83ceaa20e00fcab640c7f43e1ecbfdfe;p=notmuch-archives.git [RFC PATCH] emacs: show: mark messages unread if seen in buffer --- diff --git a/27/1697ad97ec4cd3e72f8602a1ce068a0299ece9 b/27/1697ad97ec4cd3e72f8602a1ce068a0299ece9 new file mode 100644 index 000000000..da29e1ca5 --- /dev/null +++ b/27/1697ad97ec4cd3e72f8602a1ce068a0299ece9 @@ -0,0 +1,177 @@ +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 17B55431FC0 + for ; Fri, 9 May 2014 08:45:33 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 2.7 +X-Spam-Level: ** +X-Spam-Status: No, score=2.7 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, + FREEMAIL_REPLY=2.499, 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 G6j9lgmWUdXB for ; + Fri, 9 May 2014 08:45:28 -0700 (PDT) +Received: from mail-we0-f177.google.com (mail-we0-f177.google.com + [74.125.82.177]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id AF99E431FBC + for ; Fri, 9 May 2014 08:45:28 -0700 (PDT) +Received: by mail-we0-f177.google.com with SMTP id x48so4067733wes.22 + for ; Fri, 09 May 2014 08:45:27 -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=DKeJsncyKoPOaXvO/sY48v3dgxspZqg8sn31MDqzVvE=; + b=wE/zVhbHKEOvaZlReklvnVeA7Ecfq8vIGbLsuEHCOvLjLDMUE+vniTQ1nYFqSc3w5/ + fUTOYF/QtFPajGb6V13Gz6L7JSwvZKjBpK+DzZcxforP3u4ml8ZqR5zI7rVPbMogc4w+ + RQAHJ9rkVt087gCJt859fnXWerSgBNmxZ+B3VK3WQOGFWQRFTy+7oadlt79KwHDkLgYv + +XoLRkyTxK6Jz96z4GUjH7btVZxyiPrtDkrWUC9YKJCSj/RkZ843YzIF+7xSGavIQeQy + cap3B9j3rHCB/fSGCVCs4V0vuMCdnNdYMHu3YaLtAwOoWiMtZ1idiGKTlO/TarySzHUS + VI6A== +X-Received: by 10.194.59.226 with SMTP id c2mr9152340wjr.6.1399650327498; + Fri, 09 May 2014 08:45:27 -0700 (PDT) +Received: from localhost (5751dfa2.skybroadband.com. [87.81.223.162]) + by mx.google.com with ESMTPSA id n5sm5731872wiz.1.2014.05.09.08.45.26 + for + (version=TLSv1.2 cipher=RC4-SHA bits=128/128); + Fri, 09 May 2014 08:45:26 -0700 (PDT) +From: Mark Walters +To: notmuch@notmuchmail.org +Subject: [RFC PATCH] emacs: show: mark messages unread if seen in buffer +Date: Fri, 9 May 2014 16:45:20 +0100 +Message-Id: <1399650320-1382-1-git-send-email-markwalters1009@gmail.com> +X-Mailer: git-send-email 1.7.10.4 +In-Reply-To: <1399594808-2815-3-git-send-email-markwalters1009@gmail.com> +References: <1399594808-2815-3-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: Fri, 09 May 2014 15:45:33 -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. + +To use set notmuch-show-mark-read-function to #'notmuch-show-do-seen +--- + +This adds the functionality to do my previous mark unread logic (see +id:1395777793-13297-1-git-send-email-markwalters1009@gmail.com) as an +option. It applies on top of the parent series. + +This is not intended to be applied as is, but people can see whether +they prefer this or the logic introduced in patch 2. I think we might +as well include the patch 2 logic as an option regardless as some +people will prefer it, and it is very small. + +This functionality could go in notmuch-show if many people prefer it, +it could go in contrib if a rather small number like it, or it could +just go on the wiki. + +Indeed, a user can have this functionality by loading a file with this +diffs contents (doesn't need to be in the notmuch tree) and setting +notmuch-show-mark-function. + +Best wishes + +Mark + + + + emacs/notmuch-show.el | 67 +++++++++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 67 insertions(+) + +diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el +index 2620f84..3f45830 100644 +--- a/emacs/notmuch-show.el ++++ b/emacs/notmuch-show.el +@@ -1550,6 +1550,73 @@ (defun notmuch-show-mark-read (&optional unread) + (apply 'notmuch-show-tag-message + (notmuch-tag-change-list notmuch-show-mark-read-tags unread)))) + ++(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. 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." ++ :type 'number ++ :group 'notmuch-show) ++ ++(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. 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 ++`notmuch-show-seen-lines-needed` if that is an integer and that ++times the current window height if it is a float." ++ (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. ++ ++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 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-seen-current-message (start end) + "Mark the current message read if it is open. + +-- +1.7.10.4 +