From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 421956DE10F3 for ; Thu, 29 Aug 2019 10:24:50 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: 0.294 X-Spam-Level: X-Spam-Status: No, score=0.294 tagged_above=-999 required=5 tests=[AWL=-0.358, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_NEUTRAL=0.652, UNPARSEABLE_RELAY=0.001] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id fZRW6kDHQYmZ for ; Thu, 29 Aug 2019 10:24:49 -0700 (PDT) Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by arlo.cworth.org (Postfix) with ESMTPS id 93D8C6DE10F9 for ; Thu, 29 Aug 2019 10:24:49 -0700 (PDT) Received: by mail-wm1-f67.google.com with SMTP id n2so3256196wmk.4 for ; Thu, 29 Aug 2019 10:24:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dme-org.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=wh/wVk+gjez5jSTMZLvyslIm5amhZm48F/gaWalyTYo=; b=GQ6h/ig2YB6L9yLxj5gTug/LEEUwjXvoiZTv/rThqW40tMvEGuofjUkFrz1yMCAB2h UinfCX2AgSMIydHslpqX3E3+x4kOp0P3XAlAHMzl55J/6NmShIc/aLtsYcgIsKdrSkyK 6XhaJiPyJiwpvZFGM3KHl24O3I6b5qN3rvjSKiK0FqsaeDx4uHZYbdDJ+agwqwA1kPEO o3gzFOCkrnyzatMyAZAmzJMFXy3KExwt9XkaQSRxa8zQfDtkZ8y+qu79yFe1FS314NC4 4a0hdFdDJv1LLh1DYuDip53kIKUAtXUzoPM4T3URRX3M4Zim1pdzqmCSZS4fW4UV2OFa i5ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wh/wVk+gjez5jSTMZLvyslIm5amhZm48F/gaWalyTYo=; b=Q5rQSpE6Nb0NIe27WIegfEUgdm94AGXGAEMGlBMYLonYNUKPkQ9Px+c2hquX79iJ1v Y+drRhkLIBZDzyvZ+TvwDAcJJGIzAqjVsnvbVTtvrBohsxApslXaXl3k+QKVRrmOTZDW Q+w0l8wl/ah8wzyUUKhTNoq5pcUV2pL4L61/rB0+8x5XgIMQYc8Z2V+nnsASYKIJBZ9+ qUj238WqMUIrYUdj95pFw5x+P5ind8ae1+UqWeZEo0Llr+mHD0d7hX9Ol9UI2ZUDDaBP QZKDLrPez876nQhVRJ/2j4lve6Ud1CDAmkzuCb090yXEHH6aqTgXfaVzLtCPj1sXgqbP /GWg== X-Gm-Message-State: APjAAAWrl2DHEZ3jClFgQQ272ertdQLYRVWF2OQOFg5yRUS7rEVSYbnp h6PPV25/rLQRlbfDtG8Mz5C6oIXxH8s= X-Google-Smtp-Source: APXvYqwvpm6nIm86zxLISZCZtEPGt7zBx3oT4LulucqDjdqBthAVKT+liszmWuECp2i5ZWbCHdpoBQ== X-Received: by 2002:a1c:3cc3:: with SMTP id j186mr2797985wma.119.1567099487836; Thu, 29 Aug 2019 10:24:47 -0700 (PDT) Received: from disaster-area.hh.sledj.net (disaster-area.hh.sledj.net. [81.149.164.25]) by smtp.gmail.com with ESMTPSA id c201sm6606627wmd.33.2019.08.29.10.24.46 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Aug 2019 10:24:46 -0700 (PDT) Received: from localhost (disaster-area.hh.sledj.net [local]) by disaster-area.hh.sledj.net (OpenSMTPD) with ESMTPA id 8737154c for ; Thu, 29 Aug 2019 17:24:42 +0000 (UTC) From: David Edmondson To: notmuch@notmuchmail.org Subject: [PATCH v1 2/2] emacs: Bind "u" to jump to the parent message in a thread Date: Thu, 29 Aug 2019 18:24:41 +0100 Message-Id: <20190829172441.6849-3-dme@dme.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190829172441.6849-1-dme@dme.org> References: <87a7bxh8bm.fsf@len.workgroup> <20190829172441.6849-1-dme@dme.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.29 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: Thu, 29 Aug 2019 17:24:50 -0000 --- emacs/notmuch-show.el | 55 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index 1e3834f2..7c50d2cd 100644 --- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -1173,6 +1173,60 @@ is t, hide the part initially and show the button." (setq notmuch-show--forest forest) (mapc (lambda (thread) (notmuch-show-insert-thread thread 0)) forest)) +(defun notmuch-show--find-parent-in-thread-node (thread-node id) + (let* ((msg (car thread-node)) + (reply-nodes (cadr thread-node)) + ;; Is one of the replies to this message the one we are looking + ;; for? + (candidate + (catch 'found + (mapc (lambda (reply-node) + (let* ((reply-msg (car reply-node)) + (reply-id (plist-get reply-msg :id))) + (when (string= reply-id id) + (throw 'found (plist-get msg :id))))) + reply-nodes) + nil))) + (if candidate + candidate + ;; Otherwise recurse down. + (notmuch-show--find-parent-in-thread reply-nodes id)))) + +(defun notmuch-show--find-parent-in-thread (thread id) + (let ((msg (catch 'found + (mapc (lambda (thread-node) + (setq msg (notmuch-show--find-parent-in-thread-node thread-node id)) + (when msg + (throw 'found msg))) + thread) + nil))) + msg)) + +(defun notmuch-show--find-parent-in-thread-set (thread-set id) + (let ((msg (catch 'found + (mapc (lambda (thread) + (setq msg (notmuch-show--find-parent-in-thread thread id)) + (when msg + (throw 'found msg))) + thread-set) + nil))) + msg)) + +(defun notmuch-show--find-parent () + "Find the parent of the current message." + (notmuch-show--find-parent-in-thread-set notmuch-show--forest + (notmuch-show-get-message-id t))) + +(defun notmuch-show--show-parent () + "Jump to the parent of the current message, opening it if necessary." + (interactive) + (let ((parent (notmuch-show--find-parent))) + (unless parent + (error "The current message has no parent.")) + (notmuch-show-goto-message (notmuch-id-to-query parent)) + (unless (notmuch-show-message-visible-p) + (notmuch-show-toggle-message)))) + (defvar notmuch-id-regexp (concat ;; Match the id: prefix only if it begins a word (to disallow, for @@ -1516,6 +1570,7 @@ reset based on the original query." (define-key map "t" 'toggle-truncate-lines) (define-key map "." 'notmuch-show-part-map) (define-key map "B" 'notmuch-show-browse-urls) + (define-key map "u" 'notmuch-show--show-parent) map) "Keymap for \"notmuch show\" buffers.") (fset 'notmuch-show-mode-map notmuch-show-mode-map) -- 2.22.0