From e64eda11301fb0f8f82e772f1d78b29e958f5cea Mon Sep 17 00:00:00 2001 From: Jani Nikula Date: Wed, 29 Oct 2014 22:45:05 +0200 Subject: [PATCH] Re: [PATCH] emacs: add stash support for git send-email command line --- af/3c7b38c253acacdfcaa1322948ebb4f20a3624 | 195 ++++++++++++++++++++++ 1 file changed, 195 insertions(+) create mode 100644 af/3c7b38c253acacdfcaa1322948ebb4f20a3624 diff --git a/af/3c7b38c253acacdfcaa1322948ebb4f20a3624 b/af/3c7b38c253acacdfcaa1322948ebb4f20a3624 new file mode 100644 index 000000000..8d2d05470 --- /dev/null +++ b/af/3c7b38c253acacdfcaa1322948ebb4f20a3624 @@ -0,0 +1,195 @@ +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 0F3A2431FC2 + for ; Wed, 29 Oct 2014 13:45:18 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.7 +X-Spam-Level: +X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 + tests=[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 shKk7to4iLk0 for ; + Wed, 29 Oct 2014 13:45:09 -0700 (PDT) +Received: from mail-wi0-f177.google.com (mail-wi0-f177.google.com + [209.85.212.177]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id B442B431FB6 + for ; Wed, 29 Oct 2014 13:45:09 -0700 (PDT) +Received: by mail-wi0-f177.google.com with SMTP id ex7so5692978wid.16 + for ; Wed, 29 Oct 2014 13:45:08 -0700 (PDT) +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=1e100.net; s=20130820; + h=x-gm-message-state:from:to:subject:in-reply-to:references + :user-agent:date:message-id:mime-version:content-type; + bh=SVKru4Azns5MQ5g6p1U6Cdf8+hNkM/wPcqhApBnQu1E=; + b=OkNBAfypXVjfIQBcWKa/T6tPKffCXLCwLqA+6/V/xZXZkIMAenDIKf1wJedL8tssVk + 46pBWiE90tO5XQOy+MBTIw6YS9tY0jvK2rBhHLZvbqDYXd0cqKQzrIelJo4S1dDpRLoZ + YF8VcIAH9TyN1dFYfaBIaGWJyvjT8YUk5JfXNbIl6MVmMuhXDo+k9oQb/OhBy5J5yRQk + Aka0zYxfiR2L4wDORqvflq0uNfQ9EsiNPd6bMLfRWSjP2jOXYb8hB8Rfjgi0yZXmNCfC + hVYO34isgj5RsaFp1AxZATB1354phv3Na1gmb9x/ANZAuEEqYONeD+4kGYjE28qXdEID + /tGQ== +X-Gm-Message-State: + ALoCoQnw6qprKYqc4ecLw72/lL0x+YM1DDe0UKT4SOyvRLHy/nXtH0vGObf1cH8cyoB7WLs/cu4p +X-Received: by 10.180.104.99 with SMTP id gd3mr15085080wib.10.1414615508357; + Wed, 29 Oct 2014 13:45:08 -0700 (PDT) +Received: from localhost (dsl-hkibrasgw2-58c36d-48.dhcp.inet.fi. + [88.195.109.48]) + by mx.google.com with ESMTPSA id eu8sm15030747wic.1.2014.10.29.13.45.07 + for + (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); + Wed, 29 Oct 2014 13:45:07 -0700 (PDT) +From: Jani Nikula +To: David Edmondson , notmuch@notmuchmail.org +Subject: Re: [PATCH] emacs: add stash support for git send-email command line +In-Reply-To: +References: <1414525138-838-1-git-send-email-jani@nikula.org> + +User-Agent: Notmuch/0.18.2+148~g4214adf (http://notmuchmail.org) Emacs/24.3.1 + (x86_64-pc-linux-gnu) +Date: Wed, 29 Oct 2014 22:45:05 +0200 +Message-ID: <87y4ryzju6.fsf@nikula.org> +MIME-Version: 1.0 +Content-Type: text/plain +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: Wed, 29 Oct 2014 20:45:18 -0000 + +On Wed, 29 Oct 2014, David Edmondson wrote: +> On Tue, Oct 28 2014, Jani Nikula wrote: +>> Stash From/To/Cc as --to/--to/--cc, respectively, and Message-Id as +>> --in-reply-to, suitable for pasting to git send-email command line. +>> --- +>> emacs/notmuch-show.el | 25 +++++++++++++++++++++++++ +>> 1 file changed, 25 insertions(+) +>> +>> diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el +>> index a9974826e824..328c93ba0584 100644 +>> --- a/emacs/notmuch-show.el +>> +++ b/emacs/notmuch-show.el +>> @@ -1274,6 +1274,7 @@ reset based on the original query." +>> (define-key map "t" 'notmuch-show-stash-to) +>> (define-key map "l" 'notmuch-show-stash-mlarchive-link) +>> (define-key map "L" 'notmuch-show-stash-mlarchive-link-and-go) +>> + (define-key map "G" 'notmuch-show-stash-git-send-email) +>> (define-key map "?" 'notmuch-subkeymap-help) +>> map) +>> "Submap for stash commands") +>> @@ -2125,6 +2126,30 @@ the user (see `notmuch-show-stash-mlarchive-link-alist')." +>> (notmuch-show-stash-mlarchive-link mla) +>> (browse-url (current-kill 0 t))) +>> +>> +(defun notmuch-show-stash-git-helper (addresses prefix) +>> + "Escape, trim, and add PREFIX to each address in list of ADDRESSES." +>> + (when addresses +>> + (mapconcat (lambda (x) +>> + (concat prefix "\"" +>> + ;; escape double-quotes +>> + (replace-regexp-in-string +>> + "\"" "\\\\\"" +>> + ;; trim leading and trailing spaces +>> + (replace-regexp-in-string +>> + "\\(^ *\\| *$\\)" "" +>> + x)) "\" ")) +>> + addresses ""))) +> +> This doesn't seem quite right. You leave a spurious trailing +> space. Maybe that's because you need it in the following function to +> separate the from/to/cc elements? That kind of interaction between the +> two functions is icky. + +Agreed, thanks for pointing it out. + +> There's no need to test `addresses' at the head of the list - mapconcat +> is fine with nil. +> +> How about: +> +> (defun notmuch-show-stash-git-helper (addresses prefix) +> "Escape, trim, and add PREFIX to each address in list of ADDRESSES." +> (mapconcat (lambda (x) +> (concat prefix "\"" +> ;; escape double-quotes +> (replace-regexp-in-string +> "\"" "\\\\\"" +> ;; trim leading and trailing spaces +> (replace-regexp-in-string +> "\\(^ *\\| *$\\)" "" +> x)) "\"")) +> addresses " ")) +> +> This would remove the trailing space, so... +> +>> + +>> +(defun notmuch-show-stash-git-send-email () +>> + "Copy From/To/Cc/Message-Id of current message to kill-ring in a form suitable for pasting to git send-email command line." +>> + (interactive) +>> + (notmuch-common-do-stash +>> + (concat +>> + (notmuch-show-stash-git-helper (message-tokenize-header (notmuch-show-get-from)) "--to=") +>> + (notmuch-show-stash-git-helper (message-tokenize-header (notmuch-show-get-to)) "--to=") +>> + (notmuch-show-stash-git-helper (message-tokenize-header (notmuch-show-get-cc)) "--cc=") +>> + (concat "--in-reply-to=\"" (notmuch-show-get-message-id t) "\"")))) +> +> ...this would have to use something like: +> +> (mapconcat 'identity (list +> (notmuch-show-stash-git-helper (message-tokenize-header (notmuch-show-get-from)) "--to=") +> (notmuch-show-stash-git-helper (message-tokenize-header (notmuch-show-get-to)) "--to=") +> (notmuch-show-stash-git-helper (message-tokenize-header (notmuch-show-get-cc)) "--cc=") +> (concat "--in-reply-to=\"" (notmuch-show-get-message-id t) "\"")) +> "") +> +> to separate the chunks (untested). + +The last "" has to be " " to separate the elements, but this brings +another small wrinkle: if one of the headers is missing, typically Cc:, +it will be nil in the list, and mapconcat adds spaces both sides of +that, i.e. double space. Any ideas how to fix that? + +> Could you avoid the double-quote quoting by using single quotes inside +> the strings? + +The addresses may contain both single quotes and double quotes, so +escaping either of them seems like the only option. + +> Do the leading and trailing spaces really matter? + +Does aesthetically displeasing count? Because message-tokenize-header +splits using "," but headers typically have ", " between addresses, the +end result will practically always have --to=" user@example.com" without +the trimming. + +Thanks for the helpful review; I'm not much of a lisp coder... + +BR, +Jani. + + +> +> (Domo: Look, I managed to write 'separate', twice!) +> +>> + +>> ;; Interactive part functions and their helpers +>> +>> (defun notmuch-show-generate-part-buffer (message-id nth) +>> -- +>> 2.1.1 +>> +>> _______________________________________________ +>> notmuch mailing list +>> notmuch@notmuchmail.org +>> http://notmuchmail.org/mailman/listinfo/notmuch -- 2.26.2