[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/ebdb dcb1fcc 6/9: Turns out ebdb-fmt-collect-fields cou
From: |
Eric Abrahamsen |
Subject: |
[elpa] externals/ebdb dcb1fcc 6/9: Turns out ebdb-fmt-collect-fields could have been a lot simpler |
Date: |
Wed, 18 Oct 2017 17:51:57 -0400 (EDT) |
branch: externals/ebdb
commit dcb1fcc9814b9a77d3a280018aba38f73699ffa0
Author: Eric Abrahamsen <address@hidden>
Commit: Eric Abrahamsen <address@hidden>
Turns out ebdb-fmt-collect-fields could have been a lot simpler
* ebdb-format.el (ebdb-fmt-collect-fields): All these methods were
basically duplicating the work of `ebdb-record-current-fields', so
just use that instead, and filter according to the formatter.
---
ebdb-format.el | 119 ++++++++++++++++-----------------------------------------
1 file changed, 32 insertions(+), 87 deletions(-)
diff --git a/ebdb-format.el b/ebdb-format.el
index 47b4f48..181a58f 100644
--- a/ebdb-format.el
+++ b/ebdb-format.el
@@ -118,19 +118,22 @@ lists, respectively.")
"Format the body of RECORD, using the fields in FIELDS.")
(cl-defgeneric ebdb-fmt-collect-fields (fmt record &optional fields)
- "Return a list of RECORD's FIELDS to be formatted.
+ "Return a list of RECORD's FIELDS to be formatted.")
-Each element of FIELDS is either a single field instance, or a
-list of field instances. Which fields are present, how they're
-sorted, and how they're combined into lists is determined by the
-\"exclude\" and \"sort\" slots of FMT.")
+(cl-defgeneric ebdb-fmt-process-fields (fmt record &optional fields)
+ "Process the FIELDS belonging to RECORD.
+This means grouping them into lists containing various formatting
+information, mostly drawn from FMT's `combine' and `collapse'
+slots.")
-(cl-defgeneric ebdb-fmt-process-fields (fmt record &optional fields))
-
-(cl-defgeneric ebdb-fmt-sort-fields (fmt record &optional fields))
+(cl-defgeneric ebdb-fmt-sort-fields (fmt record &optional fields)
+ "Sort FIELDS belonging to RECORD according to FMT.")
;; Do we still need this now that formatters and specs are collapsed?
-(cl-defgeneric ebdb-fmt-compose-field (fmt field-cons record))
+(cl-defgeneric ebdb-fmt-compose-field (fmt field-cons record)
+ "Convert the lists produced by `ebdb-fmt-process-fields'.
+The lists of class instances and formatting information are
+turned into lists holding labels strings and instance strings.")
(cl-defgeneric ebdb-fmt-field (fmt field style record)
"Format FIELD value of RECORD.
@@ -235,88 +238,30 @@ FIELD-STRING1 FIELD-STRING2 ..)."
(cl-defmethod ebdb-fmt-collect-fields ((fmt ebdb-formatter)
(record ebdb-record)
&optional field-list)
- (let (f-class)
- (with-slots (fields notes uuid creation-date timestamp) record
- (with-slots (exclude include) fmt
- (dolist (f (append fields (list notes uuid creation-date timestamp)))
- (when f
- (setq f-class (eieio-object-class-name f))
- (when (if include
- (ebdb-class-in-list-p f-class include)
- (null (ebdb-class-in-list-p f-class exclude)))
- (push f field-list))))
- field-list))))
-
-(cl-defmethod ebdb-fmt-collect-fields ((fmt ebdb-formatter)
- (record ebdb-record-entity)
- &optional field-list)
- (with-slots (include exclude primary) fmt
- (with-slots (mail phone address) record
- (when (and mail
- (if include
- (memq 'ebdb-field-mail include)
- (null (memq 'ebdb-field-mail exclude))))
- (if primary
- (push (object-assoc 'primary 'priority mail) field-list)
- (dolist (m mail)
- (push m field-list))))
- (when (and phone
- (if include
- (memq 'ebdb-field-phone include)
- (null (memq 'ebdb-field-phone exclude))))
- (dolist (p phone)
- (push p field-list)))
- (when (and address
- (if include
- (memq 'ebdb-field-address include)
- (null (memq 'ebdb-field-address exclude))))
- (dolist (a address)
- (push a field-list)))
- (cl-call-next-method fmt record field-list))))
-
-(cl-defmethod ebdb-fmt-collect-fields ((fmt ebdb-formatter)
- (record ebdb-record-person)
- &optional field-list)
-
- (with-slots (exclude include) fmt
- (with-slots (aka organizations relations) record
- (when (and aka
- (if include
- (memq 'ebdb-field-name include)
- (null (memq 'ebdb-field-name exclude))))
- (dolist (n aka)
- (push n field-list)))
- (when (and organizations
- (if include
- (memq 'ebdb-field-role include)
- (null (memq 'ebdb-field-role exclude))))
- (dolist (r organizations)
- (push r field-list)))
- (when (and relations
- (if include
- (memq 'ebdb-field-relation include)
- (null (memq 'ebdb-field-relation exclude))))
- (dolist (r relations)
- (push r field-list)))
- (cl-call-next-method fmt record field-list))))
+ "Collect all fields of RECORD, and filter according to FMT."
+ ;; Remove the `name' slot entry from the list.
+ (let ((fields (append
+ field-list
+ (mapcar #'cdr
+ (seq-remove
+ (lambda (elt) (eql (car elt) 'name))
+ (ebdb-record-current-fields record nil t)))))
+ f-class)
+ (with-slots (exclude include) fmt
+ (seq-filter
+ (lambda (f)
+ (setq f-class (eieio-object-class-name f))
+ (if include
+ (ebdb-class-in-list-p f-class include)
+ (null (ebdb-class-in-list-p f-class exclude))))
+ fields))))
(cl-defmethod ebdb-fmt-collect-fields ((fmt ebdb-formatter)
(record ebdb-record-organization)
&optional field-list)
- (with-slots (exclude include) fmt
- (when (and (slot-value record 'domain)
- (if include
- (memq 'ebdb-field-domain include)
- (null (memq 'ebdb-field-domain exclude))))
- (push (slot-value record 'domain) field-list))
- (let ((roles (gethash (ebdb-record-uuid record) ebdb-org-hashtable)))
- (when (and roles
- (if include
- (memq 'ebdb-field-role include)
- (null (memq 'ebdb-field-role exclude))))
- (dolist (r roles)
- (push r field-list)))
- (cl-call-next-method fmt record field-list))))
+ (cl-call-next-method
+ fmt record
+ (append field-list (gethash (ebdb-record-uuid record) ebdb-org-hashtable))))
(cl-defmethod ebdb-fmt-sort-fields ((fmt ebdb-formatter)
(_record ebdb-record)
- [elpa] externals/ebdb updated (b0029d3 -> aac31a3), Eric Abrahamsen, 2017/10/18
- [elpa] externals/ebdb e8c956d 1/9: Adjust database checks when loading, Eric Abrahamsen, 2017/10/18
- [elpa] externals/ebdb 64dbf86 5/9: Bah, commited a bit of (erroneous) test code, Eric Abrahamsen, 2017/10/18
- [elpa] externals/ebdb 94b11b9 2/9: Various tweaks, Eric Abrahamsen, 2017/10/18
- [elpa] externals/ebdb c6aef3b 3/9: Fix parsing of address countries during migration, Eric Abrahamsen, 2017/10/18
- [elpa] externals/ebdb 9acc6d4 4/9: Provide more control over faces in *EBDB* buffers, Eric Abrahamsen, 2017/10/18
- [elpa] externals/ebdb dcb1fcc 6/9: Turns out ebdb-fmt-collect-fields could have been a lot simpler,
Eric Abrahamsen <=
- [elpa] externals/ebdb 864c1f3 7/9: Give formatters a post-format-function slot, Eric Abrahamsen, 2017/10/18
- [elpa] externals/ebdb aac31a3 9/9: Add browse-url action for domain fields, Eric Abrahamsen, 2017/10/18
- [elpa] externals/ebdb 1ebd9eb 8/9: Fix function call, Eric Abrahamsen, 2017/10/18