branch: externals/ebdb commit 9102219eb28c1b02af4aa93dc4f72ae1706fbb3c Author: Eric Abrahamsen <e...@ericabrahamsen.net> Commit: Eric Abrahamsen <e...@ericabrahamsen.net>
Re-work ebdb-records-cite * ebdb.el (ebdb-records-cite): I was trying to be too clever combining :around methods with &context specializers, and generally tripping over my own feet. This version has more duplicate code, but behaves correctly. --- ebdb.el | 121 +++++++++++++++++++++++++++++----------------------------------- 1 file changed, 54 insertions(+), 67 deletions(-) diff --git a/ebdb.el b/ebdb.el index b3cf84c..356b90c 100644 --- a/ebdb.el +++ b/ebdb.el @@ -4980,79 +4980,66 @@ inserting it." (cl-defgeneric ebdb-records-cite (style records) "Return mode-appropriate mail strings for RECORDS. STYLE is a symbol, one of 'inline or 'list. This is interpreted -differently by different major modes. +differently by different major modes; the default looks like +\"Firstname Lastname <em...@address.com>\". This is a generic function that dispatches on the value of `major-mode'. It only inserts names and mail addresses.") +(cl-defmethod ebdb-records-cite ((_style (eql list)) + (records list)) + (mapconcat (lambda (pair) + (format "%s <%s>" + ;; TODO: Wrap non-ASCII record names in double + ;; quotes? + (ebdb-string (car pair)) + (ebdb-string (cdr pair)))) + records "\n")) + (cl-defmethod ebdb-records-cite ((_style (eql inline)) + (records list)) + (mapconcat (lambda (pair) + (format "%s <%s>" + (ebdb-string (car pair)) + (ebdb-string (cdr pair)))) + records ", ")) + +(cl-defmethod ebdb-records-cite ((_style (eql list)) + (records list) + &context (major-mode org-mode)) + (mapconcat (lambda (pair) + (format "- [[mailto:%s][%s]]" + (slot-value (cdr pair) 'mail) + (ebdb-string (car pair)))) + records "\n")) + +(cl-defmethod ebdb-records-cite ((_style (eql inline)) + (records list) + &context (major-mode org-mode)) + (mapconcat (lambda (pair) + (format "[[mailto:%s][%s]]" + (slot-value (cdr pair) 'mail) + (ebdb-string (car pair)))) + records ", ")) + +(cl-defmethod ebdb-records-cite ((_style (eql list)) (records list) - &context (major-mode message-mode)) - (when records - (mapcar (lambda (pair) - (format "%s <%s>" - (ebdb-string (car pair)) - (ebdb-string (cdr pair)))) - records))) - -(cl-defmethod ebdb-records-cite :around ((_style (eql inline)) - (_records list) - &context (major-mode message-mode)) - (let ((lst (cl-call-next-method))) - (mapconcat #'identity lst ", "))) - - -(cl-defmethod ebdb-records-cite :around ((_style (eql list)) - (_records list) - &context (major-mode message-mode)) - (let ((lst (cl-call-next-method))) - (mapconcat #'identity lst "\n"))) - -(cl-defmethod ebdb-records-cite :around ((_style (eql list)) - (_records list) - &context (major-mode org-mode)) - (let ((list (cl-call-next-method))) - (mapconcat (lambda (elt) - (format "- %s" elt)) - list "\n"))) - -(cl-defmethod ebdb-records-cite :around ((_style (eql inline)) - (_records list) - &context (major-mode org-mode)) - (let ((lst (cl-call-next-method))) - (mapconcat #'identity lst " "))) - -(cl-defmethod ebdb-records-cite - (_style (records list) &context (major-mode org-mode)) - "Insert RECORDS as a list of org links." - (mapcar (lambda (pair) - (format "[[mailto:%s][%s]]" - (slot-value (cdr pair) 'mail) - (ebdb-string (car pair)))) - records)) - -(cl-defmethod ebdb-records-cite :around ((_style (eql list)) - (_records list) - &context (major-mode html-mode)) - (let ((list (cl-call-next-method))) - (mapconcat (lambda (l) - (format "<li>%s</li>" l)) - list "\n"))) - -(cl-defmethod ebdb-records-cite :around ((_style (eql inline)) - (_records list) - &context (major-mode html-mode)) - (let ((list (cl-call-next-method))) - (mapconcat #'identity list " "))) - -(cl-defmethod ebdb-records-cite - (_style (records list) &context (major-mode html-mode)) - (mapcar - (lambda (pair) - (format "<a href=\"mailto:%s>%s</a>" - (slot-value (cdr pair) 'mail) - (ebdb-string (car pair)))) - records)) + &context (major-mode html-mode)) + (mapconcat (lambda (pair) + (format "<li><a href=\"mailto:%s>%s</a></li>" + (slot-value (cdr pair) 'mail) + (ebdb-string (car pair)))) + records "\n")) + +(cl-defmethod ebdb-records-cite ((_style (eql inline)) + (records list) + &context (major-mode html-mode)) + (mapconcat (lambda (pair) + (format "<a href=\"mailto:%s>%s</a>" + (slot-value (cdr pair) 'mail) + (ebdb-string (car pair)))) + records ", ")) + ;;; Loading and saving EBDB