From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id cN+FByQW4mHQmgAAgWs5BA (envelope-from ) for ; Sat, 15 Jan 2022 01:32:36 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id MCYiACQW4mHU2AAAG6o9tA (envelope-from ) for ; Sat, 15 Jan 2022 01:32:36 +0100 Received: from mail.notmuchmail.org (yantan.tethera.net [135.181.149.255]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 65165336B0 for ; Sat, 15 Jan 2022 01:32:35 +0100 (CET) Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id BA65A5F703; Sat, 15 Jan 2022 00:32:30 +0000 (UTC) Received: from eggs.gnu.org (eggs.gnu.org [209.51.188.92]) by mail.notmuchmail.org (Postfix) with ESMTPS id 836D15F6CC for ; Sat, 15 Jan 2022 00:32:28 +0000 (UTC) Received: from [2001:470:142:3::e] (port=40016 helo=fencepost.gnu.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n8Wza-0008JD-ER; Fri, 14 Jan 2022 19:32:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:Subject:To:From:in-reply-to: references; bh=58cEcDgo6nf5Q069e7vvIK4q1EQFMBY8eDoEVtMhtio=; b=at3Uxif1OIAR9s uX6RiiP+J71qkcomnx9WGfpCu0VBNwmnfH80Wtye1UIAgwdcPB3gamf0DKCG6kmCnVabpN599wscW e9J7LmYBIIghPK5GB3sBMJikxmWqkZ8zfyP+c46QnehJ13fQJ0ew76OX5qa5B96OWdug2141C1W9F Sc1cDFkbJWNQ0wB9nw+wP4gtTAmMFilgTOmVhjH12Yj/i6AFmITIrPBGqNbtgQ5z2OTmBzkdrRCCU yms06tdlYgPG/FfBS4F7EpxTwxka9g+ZgGYeU1iM/yY45XY5lBkDC1XwAmdmh1eDBWoI4hWB7/qTq wJnykXPa0wnLvy13sj8Q==; Received: from cpc103048-sgyl39-2-0-cust502.18-2.cable.virginm.net ([92.233.85.247]:33530 helo=rivendell.localdomain) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n8WzZ-0005Q3-UI; Fri, 14 Jan 2022 19:32:26 -0500 From: jao To: notmuch@notmuchmail.org Subject: [PATCH v5] emacs: customizable names for search buffers Date: Sat, 15 Jan 2022 00:32:14 +0000 Message-Id: <20220115003214.63224-1-jao@gnu.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Message-ID-Hash: FOTJ3WT6JD6F7N2YESVMTHBU2Z73LDBV X-Message-ID-Hash: FOTJ3WT6JD6F7N2YESVMTHBU2Z73LDBV X-MailFrom: jao@gnu.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: jao X-Mailman-Version: 3.3.3 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN X-Migadu-Country: DE ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1642206755; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-owner:list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=igrg3ksXuO4l8BdHuGA/J6onq9JUTGTj1K97N1pmfMg=; b=oRfJrishQ65M8FWtdPpmo2NvcFr8Qe2/a5YkwwBxvBvNofsZFcwQbOArXOhY8JwZ6Rtcg/ yXKF6ArfxBDG/GcgIp14WMyzLOq+dhdJn14h9uO0CCgFeR6m5MMuiyUZXU87qQMzh1eynG 1HzYvhu6twDP3rsB9mtxlWH2m28m8hua45MW0KOaQp6B+LtENW16Ng73RtnBF7w6SO/fYJ 16E12OnTiURA4qCDdqzdK9BNzb4TuTgQCcxqYLlP/AKcfmkG+FuhZIJIDz2V9HLiiLdLjP 6sNjeS+5M3PWdpZhovq0pcByWT/ymTxny2URR7UhE8uykJu/BjbVWuv5BqyOww== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1642206755; a=rsa-sha256; cv=none; b=JNulZk1+Fipjxxjbbb+PamWYEUJS26a/0ZNndyX30Q37RO/Yk7BARZec++T5fdSWEAqq29 8dthr6lzFQ4BbiK9kkAcC8WADpx0Z9nFpLyUVQtykveXvy1YmglAgdBMLk3rI7ZsJpKzqt Cg9WcsIASmQpoWQzyE7UZfe8M7oMVO9fe3IYqnHI5mhpWcE3HlqXTYSjdi+1HRtzxWV0ru uK7D0ggVDDoTbhYG2Fb1WTQDrrYaZEVwbPAhvN5junN1Vu3rzHm+IbVOJCNcOqMu45F+Xm 5uiMLL825KMbCQyJ4VHzEdysWfbwdTypNG9MXNuZuT4VCFSohdmxhxV1ieTy7w== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gnu.org header.s=fencepost-gnu-org header.b=at3Uxif1; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gnu.org (policy=none); spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 135.181.149.255 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -0.64 Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gnu.org header.s=fencepost-gnu-org header.b=at3Uxif1; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gnu.org (policy=none); spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 135.181.149.255 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 65165336B0 X-Spam-Score: -0.64 X-Migadu-Scanner: scn1.migadu.com X-TUID: go05uGD+M164 Customizable names for buffers presenting search results, via two custom variables (notmuch-search-buffer-name-format and notmuch-saved-search-buffer-name-format), defaulting to values currently used for plain searches and including too tree and unthreaded search buffers. --- This is a much improved version of the patch in id:20220108204121.1053932-1-jao@gnu.org, according to discussion on that thread. This version fixes the regexp for detecting %t in emacs < 27, skipping word boundary checks. Signed-off-by: jao --- emacs/notmuch-hello.el | 11 +++++---- emacs/notmuch-tree.el | 10 ++++----- emacs/notmuch.el | 51 +++++++++++++++++++++++++++++++++--------- 3 files changed, 53 insertions(+), 19 deletions(-) diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el index fc007c4c..44341dd6 100644 --- a/emacs/notmuch-hello.el +++ b/emacs/notmuch-hello.el @@ -486,11 +486,14 @@ diagonal." (defun notmuch-hello-widget-search (widget &rest _ignore) (cl-case (widget-get widget :notmuch-search-type) (tree - (notmuch-tree (widget-get widget :notmuch-search-terms) - nil nil nil nil nil nil - (widget-get widget :notmuch-search-oldest-first))) + (let ((n (notmuch-search-format-buffer-name (widget-value widget) "tree" t))) + (notmuch-tree (widget-get widget :notmuch-search-terms) + nil nil n nil nil nil + (widget-get widget :notmuch-search-oldest-first)))) (unthreaded - (notmuch-unthreaded (widget-get widget :notmuch-search-terms))) + (let ((n (notmuch-search-format-buffer-name (widget-value widget) + "unthreaded" t))) + (notmuch-unthreaded (widget-get widget :notmuch-search-terms) nil nil n))) (t (notmuch-search (widget-get widget :notmuch-search-terms) (widget-get widget :notmuch-search-oldest-first))))) diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el index d7486904..303c6fad 100644 --- a/emacs/notmuch-tree.el +++ b/emacs/notmuch-tree.el @@ -1191,11 +1191,11 @@ The arguments are: (setq query (notmuch-read-query (concat "Notmuch " (if unthreaded "unthreaded " "tree ") "view search: ")))) - (let ((buffer (get-buffer-create (generate-new-buffer-name - (or buffer-name - (concat "*notmuch-" - (if unthreaded "unthreaded-" "tree-") - query "*"))))) + (let* ((name + (or buffer-name + (notmuch-search-buffer-title query + (if unthreaded "unthreaded" "tree")))) + (buffer (get-buffer-create (generate-new-buffer-name name))) (inhibit-read-only t)) (pop-to-buffer-same-window buffer)) ;; Don't track undo information for this buffer diff --git a/emacs/notmuch.el b/emacs/notmuch.el index 85a54706..8c7eb519 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -915,7 +915,37 @@ See `notmuch-tag' for information on the format of TAG-CHANGES." (notmuch-search-get-tags-region (point-min) (point-max)) "Tag all"))) (notmuch-search-tag tag-changes (point-min) (point-max) t)) -(defun notmuch-search-buffer-title (query) +(defcustom notmuch-search-buffer-name-format "*notmuch-%t-%s*" + "Format for the name of search results buffers. + +In this spec, %s will be replaced by a description of the search +query and %t by its type (search, tree or unthreaded). + +See also `notmuch-saved-search-buffer-name-format'" + :type 'string + :group 'notmuch-search) + +(defcustom notmuch-saved-search-buffer-name-format "*notmuch-saved-%t-%s*" + "Format for the name of search results buffers. + +In this spec, %s will be replaced by the saved search name and %t +by its type (search, tree or unthreaded). + +See also `notmuch-search-buffer-name-format'" + :type 'string + :group 'notmuch-search) + +(defun notmuch-search-format-buffer-name (query type saved) + "Compose a buffer name for the given QUERY, TYPE (search, tree, +unthreaded) and whether it's SAVED (t or nil)." + (let ((fmt (if saved + notmuch-saved-search-buffer-name-format + notmuch-search-buffer-name-format))) + (if (fboundp 'format-spec) + (format-spec fmt `((?t . ,(or type "search")) (?s . ,query)))) + (format (replace-regexp-in-string "%t" (or type "search") fmt) query))) + +(defun notmuch-search-buffer-title (query &optional type) "Returns the title for a buffer with notmuch search results." (let* ((saved-search (let (longest @@ -930,19 +960,20 @@ See `notmuch-tag' for information on the format of TAG-CHANGES." do (setq longest tuple)) longest)) (saved-search-name (notmuch-saved-search-get saved-search :name)) + (saved-search-type (notmuch-saved-search-get saved-search :search-type)) (saved-search-query (notmuch-saved-search-get saved-search :query))) (cond ((and saved-search (equal saved-search-query query)) ;; Query is the same as saved search (ignoring case) - (concat "*notmuch-saved-search-" saved-search-name "*")) + (notmuch-search-format-buffer-name saved-search-name + saved-search-type + t)) (saved-search - (concat "*notmuch-search-" - (replace-regexp-in-string - (concat "^" (regexp-quote saved-search-query)) - (concat "[ " saved-search-name " ]") - query) - "*")) - (t - (concat "*notmuch-search-" query "*"))))) + (let ((query (replace-regexp-in-string + (concat "^" (regexp-quote saved-search-query)) + (concat "[ " saved-search-name " ]") + query))) + (notmuch-search-format-buffer-name query saved-search-type t))) + (t (notmuch-search-format-buffer-name query type nil))))) (defun notmuch-read-query (prompt) "Read a notmuch-query from the minibuffer with completion. -- 2.34.1