emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 5809728: * lisp/emacs-lisp/lisp-mnt.el (lm-crack-address): Handle


From: Stefan Monnier
Subject: master 5809728: * lisp/emacs-lisp/lisp-mnt.el (lm-crack-address): Handle multi-addresses
Date: Thu, 12 Aug 2021 13:55:42 -0400 (EDT)

branch: master
commit 5809728bc502d58f4fe96e98b472c569da3d8879
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>

    * lisp/emacs-lisp/lisp-mnt.el (lm-crack-address): Handle multi-addresses
    
    (lm-authors, lm-maintainers): Adjust accordingly.
---
 lisp/emacs-lisp/lisp-mnt.el            | 31 ++++++++++++++++-------------
 test/lisp/emacs-lisp/lisp-mnt-tests.el | 36 ++++++++++++++++++++++++++++++++++
 2 files changed, 53 insertions(+), 14 deletions(-)

diff --git a/lisp/emacs-lisp/lisp-mnt.el b/lisp/emacs-lisp/lisp-mnt.el
index d6a6a5f..4d1b42e 100644
--- a/lisp/emacs-lisp/lisp-mnt.el
+++ b/lisp/emacs-lisp/lisp-mnt.el
@@ -357,18 +357,21 @@ Return argument is of the form (\"HOLDER\" \"YEAR1\" ... 
\"YEARN\")"
            summary)))))
 
 (defun lm-crack-address (x)
-  "Split up an email address X into full name and real email address.
-The value is a cons of the form (FULLNAME . ADDRESS)."
-  (cond ((string-match "\\(.+\\) [(<]\\(\\S-+@\\S-+\\)[>)]" x)
-        (cons (string-trim-right (match-string 1 x))
-              (match-string 2 x)))
-       ((string-match "\\(\\S-+@\\S-+\\) [(<]\\(.*\\)[>)]" x)
-        (cons (string-trim-right (match-string 2 x))
-              (match-string 1 x)))
-       ((string-match "\\S-+@\\S-+" x)
-        (cons nil x))
-       (t
-        (cons x nil))))
+  "Split up email address(es) X into full name and real email address.
+The value is a list of elements of the form (FULLNAME . ADDRESS)."
+  (cond ((string-match
+         (concat "[,\s\t]*\\(?:"
+                 "\\(.+?\\) +[(<]\\(\\S-+@\\S-+\\)[>)]"
+                 "\\|"
+                 "\\(?2:\\S-+@\\S-+\\) +[(<]\\(?1:[^,]*\\)[>)]"
+                 "\\|"
+                 "\\(?2:\\S-+@\\S-+\\)"
+                 "\\)")
+         x)
+        `((,(string-trim-right (match-string 1 x)) . ,(match-string 2 x))
+          . ,(lm-crack-address (substring x (match-end 0)))))
+       ((string-match "\\`[,\s\t]*\\'" x) nil)
+       (t `((,x)))))
 
 (defun lm-authors (&optional file)
   "Return the author list of file FILE, or current buffer if FILE is nil.
@@ -376,7 +379,7 @@ Each element of the list is a cons; the car is the full 
name,
 the cdr is an email address."
   (lm-with-file file
     (let ((authorlist (lm-header-multiline "author")))
-      (mapcar #'lm-crack-address authorlist))))
+      (mapcan #'lm-crack-address authorlist))))
 
 (defun lm-maintainers (&optional file)
   "Return the maintainer list of file FILE, or current buffer if FILE is nil.
@@ -384,7 +387,7 @@ If the maintainers are unspecified, then return the authors.
 Each element of the list is a cons; the car is the full name,
 the cdr is an email address."
   (lm-with-file file
-    (mapcar #'lm-crack-address
+    (mapcan #'lm-crack-address
             (or (lm-header-multiline "maintainer")
                 (lm-header-multiline "author")))))
 
diff --git a/test/lisp/emacs-lisp/lisp-mnt-tests.el 
b/test/lisp/emacs-lisp/lisp-mnt-tests.el
new file mode 100644
index 0000000..84cdc72
--- /dev/null
+++ b/test/lisp/emacs-lisp/lisp-mnt-tests.el
@@ -0,0 +1,36 @@
+;;; lisp-mnt-tests.el --- Tests for lisp-mnt  -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2021  2020-2021 Free Software Foundation, Inc.
+
+;; Author: Stefan Monnier <monnier@iro.umontreal.ca>
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;
+
+;;; Code:
+
+(require 'ert)
+(require 'lisp-mnt)
+
+(ert-deftest lm--tests-crack-address ()
+  (should (equal (lm-crack-address
+                  "Bob Weiner <rsw@gnu.org>, Mats Lidell <matsl@gnu.org>")
+                 '(("Bob Weiner" . "rsw@gnu.org")
+                   ("Mats Lidell" . "matsl@gnu.org")))))
+
+(provide 'lisp-mnt-tests)
+;;; lisp-mnt-tests.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]