From c6eebc3999d56af688c630c85209116de3154ccf Mon Sep 17 00:00:00 2001 From: Tomi Ollila Date: Tue, 31 Jul 2012 20:59:40 +0300 Subject: [PATCH] Re: [PATCH v2] emacs: Split the function notmuch-show-clean-address --- 6f/78e12a0124110636f2748746404f417fc8fbeb | 123 ++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 6f/78e12a0124110636f2748746404f417fc8fbeb diff --git a/6f/78e12a0124110636f2748746404f417fc8fbeb b/6f/78e12a0124110636f2748746404f417fc8fbeb new file mode 100644 index 000000000..9cffe31ff --- /dev/null +++ b/6f/78e12a0124110636f2748746404f417fc8fbeb @@ -0,0 +1,123 @@ +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 6B38F431FAF + for ; Tue, 31 Jul 2012 10:59:32 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 0 +X-Spam-Level: +X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] + 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 DpZdulzsrYRW for ; + Tue, 31 Jul 2012 10:59:31 -0700 (PDT) +Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) + by olra.theworths.org (Postfix) with ESMTP id 8BA0C431FAE + for ; Tue, 31 Jul 2012 10:59:31 -0700 (PDT) +Received: by guru.guru-group.fi (Postfix, from userid 501) + id 95BD110036F; Tue, 31 Jul 2012 20:59:40 +0300 (EEST) +From: Tomi Ollila +To: Mark Walters , notmuch@notmuchmail.org +Subject: Re: [PATCH v2] emacs: Split the function notmuch-show-clean-address +In-Reply-To: <878vdzzyfg.fsf@qmul.ac.uk> +References: <87ehnw84e5.fsf@qmul.ac.uk> + <87boivzyls.fsf@qmul.ac.uk> <878vdzzyfg.fsf@qmul.ac.uk> +User-Agent: Notmuch/0.13.2+103~g9610d35 (http://notmuchmail.org) Emacs/23.1.1 + (x86_64-redhat-linux-gnu) +X-Face: HhBM'cA~ +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +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: Tue, 31 Jul 2012 17:59:32 -0000 + +On Tue, Jul 31 2012, Mark Walters wrote: + +> This function is also used by pick so split it out in preperation for +> moving to lib. In fact, pick and show want a slightly different +> combination of name and email on return so make the separated function +> return them as a pair, and let show or pick extract the combination +> they want from that. +> --- +> emacs/notmuch-show.el | 27 ++++++++++++++++++--------- +> 1 files changed, 18 insertions(+), 9 deletions(-) +> +> diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el +> index 6335d45..4ab6f92 100644 +> --- a/emacs/notmuch-show.el +> +++ b/emacs/notmuch-show.el +> @@ -351,9 +351,10 @@ operation on the contents of the current buffer." +> 'face 'notmuch-tag-face) +> ")")))))) +> +> -(defun notmuch-show-clean-address (address) +> - "Try to clean a single email ADDRESS for display. Return +> -unchanged ADDRESS if parsing fails." +> +(defun notmuch-clean-address (address) +> + "Try to clean a single email ADDRESS for display. Return a cons +> +cell of (AUTHOR_EMAIL AUTHOR_NAME). Return (ADDRESS nil) if +> +parsing fails." + +Looks good to me. + +It took a few iterations to understand that the error case in expression +below can be experimented with: + +(condition-case nil (error "caught") (error (cons "car" "cdr"))) c-x c-e + +Tomi + +> (condition-case nil +> (let (p-name p-address) +> ;; It would be convenient to use `mail-header-parse-address', +> @@ -401,12 +402,20 @@ unchanged ADDRESS if parsing fails." +> (when (string= p-name p-address) +> (setq p-name nil)) +> +> - ;; If no name results, return just the address. +> - (if (not p-name) +> - p-address +> - ;; Otherwise format the name and address together. +> - (concat p-name " <" p-address ">"))) +> - (error address))) +> + (cons p-address p-name)) +> + (error (cons address nil)))) +> + +> +(defun notmuch-show-clean-address (address) +> + "Try to clean a single email ADDRESS for display. Return +> +unchanged ADDRESS if parsing fails." +> + (let* ((clean-address (notmuch-clean-address address)) +> + (p-address (car clean-address)) +> + (p-name (cdr clean-address))) +> + ;; If no name, return just the address. +> + (if (not p-name) +> + p-address +> + ;; Otherwise format the name and address together. +> + (concat p-name " <" p-address ">")))) +> +> (defun notmuch-show-insert-headerline (headers date tags depth) +> "Insert a notmuch style headerline based on HEADERS for a +> -- +> 1.7.9.1 +> +> _______________________________________________ +> notmuch mailing list +> notmuch@notmuchmail.org +> http://notmuchmail.org/mailman/listinfo/notmuch -- 2.26.2