[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/ebdb 8d81a19 132/350: Add EBDB record citation
From: |
Eric Abrahamsen |
Subject: |
[elpa] externals/ebdb 8d81a19 132/350: Add EBDB record citation |
Date: |
Mon, 14 Aug 2017 11:46:21 -0400 (EDT) |
branch: externals/ebdb
commit 8d81a192216fc352ddf50173cb41816c326910fb
Author: Eric Abrahamsen <address@hidden>
Commit: Eric Abrahamsen <address@hidden>
Add EBDB record citation
* ebdb.el (ebdb-cite-records-mail, ebdb-records-cite-mail): Add an
interactive function and several methods for citing record name/mail
pairs. `ebdb-cite-records-mail' is the interactive command, which
hands off to the `ebdb-records-cite-mail' method, which dispatches
on the current major mode.
---
ebdb.el | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 90 insertions(+), 1 deletion(-)
diff --git a/ebdb.el b/ebdb.el
index f9bcd14..677a504 100644
--- a/ebdb.el
+++ b/ebdb.el
@@ -4449,7 +4449,96 @@ The formatting rules are defined in
`ebdb-address-format-list'."
(error "No match of `ebdb-address-format-list'"))
string))
-;; Loading and saving EBDB
+
+;;; Citing EBDB records
+
+;; "Citation" means inserting some sort of string representing the
+;; record(s) into the current buffer.
+
+(defun ebdb-cite-records-mail (&optional records arg)
+ (interactive (list (ebdb-prompt-for-record)
+ current-prefix-arg))
+ (let ((recs (ebdb-record-list records))
+ (style (if arg 'list 'inline))
+ usable)
+ (dolist (r recs)
+ (if-let ((m (ebdb-record-mail r t)))
+ (push (cons r (or (object-assoc 'primary 'priority m)
+ (car m)))
+ usable)))
+ (insert (ebdb-records-cite-mail style usable))))
+
+(cl-defgeneric ebdb-records-cite-mail (style records)
+ "Insert mode-appropriate mail strings for RECORDS.
+
+STYLE is a symbol, one of 'inline or 'list. This is interpreted
+differently by different major modes.
+
+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-mail (style records)
+ "The fallback catch-all method."
+ (when records
+ (mapconcat (lambda (pair)
+ (format "%s <%s>"
+ (ebdb-string (car pair))
+ (ebdb-string (cdr pair))))
+ records
+ (if (eql style 'inline)
+ " "
+ "\n"))))
+
+(cl-defmethod ebdb-records-cite-mail :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-mail :around ((style (eql inline))
+ (records list)
+ &context (major-mode org-mode))
+ (let ((list (cl-call-next-method)))
+ (mapconcat #'identity list " ")))
+
+(cl-defmethod ebdb-records-cite-mail
+ (_style records &context (major-mode org-mode))
+ "Insert RECORDS as a list of org links."
+ (when records
+ (mapcar (lambda (pair)
+ (format "[[mailto:%s][%s]]"
+ (slot-value (cdr pair) 'mail)
+ (ebdb-string (car pair))))
+ records)))
+
+(cl-defmethod ebdb-records-cite-mail :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-mail :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-mail
+ (style records &context (major-mode html-mode))
+ (when records
+ (mapcar
+ (lambda (pair)
+ (format "<a href=\"mailto:%s>%s</a>"
+ (slot-value (cdr pair) 'mail)
+ (ebdb-string (car pair))))
+ records)))
+
+
+;;; Loading and saving EBDB
(defun ebdb-save (&optional prompt)
"Save the EBDB if it is modified.
- [elpa] externals/ebdb db930f6 163/350: Compiler-inspired fixes, and removal of old-code references, (continued)
- [elpa] externals/ebdb db930f6 163/350: Compiler-inspired fixes, and removal of old-code references, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 281c61e 154/350: Don't ((lambda ()), Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 4cce4c8 096/350: Simplify role field adoption process, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 0910ddd 105/350: Change default of ebdb-default-user-field, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb b495e29 083/350: Omnibus changes to display and redisplay, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 29bf304 101/350: Rework MUA window popups, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 81e23c3 134/350: Simplify record mail citing, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb b661aac 124/350: First generalized version of snarfing, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb aae57ff 139/350: Ensure that extra name field instances go in 'aka slot, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 057c4c0 144/350: Have ebdb-snarf accept optional records argument, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 8d81a19 132/350: Add EBDB record citation,
Eric Abrahamsen <=
- [elpa] externals/ebdb 7662133 140/350: Simplify ebdb-dwim-mail, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 0cfe1ec 164/350: Provide keybinding for ebdb-format-all-records, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb bf51b58 161/350: Fix ebdb-delete-redundant-mails, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 279eb56 169/350: Tweaks and additions to manual, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb eea0abf 165/350: VCard export is good enough, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 64b5e43 170/350: Fix autoloads in ebdb.el, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb a968dd3 143/350: First actually-working version of snarfing, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb a8e0221 179/350: Missing local variable binding, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb e71548d 172/350: Allow for characters before mail addresses when snarfing, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 14b03b5 186/350: Fix menu entry of ebdb-create-record, Eric Abrahamsen, 2017/08/14