[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/ebdb 88f5e12 261/350: Fill out functionality of gnorb m
From: |
Eric Abrahamsen |
Subject: |
[elpa] externals/ebdb 88f5e12 261/350: Fill out functionality of gnorb messages field |
Date: |
Mon, 14 Aug 2017 11:46:50 -0400 (EDT) |
branch: externals/ebdb
commit 88f5e125410738850bde16b0d3303d5aae6b52d0
Author: Eric Abrahamsen <address@hidden>
Commit: Eric Abrahamsen <address@hidden>
Fill out functionality of gnorb messages field
Though the "notice" plumbing isn't actually hooked up yet! Actually
this should be disconnected from Gnorb altogether (in fact it already
is, there's no use of Gnorb in this file at all), and the field should
be made capable of collecting and following links from any MUA, not
just Gnus. We'll get there.
* ebdb-gnorb.el (gnorb-ebdb): New group.
(gnorb-ebdb-collect-N-messages, gnorb-ebdb-define-recent,
gnorb-ebdb-message-format): Customization options all stolen from
Gnorb.
(gnorb-ebdb-follow-link): New function for following a link.
(ebdb-fmt-field, ebdb-string): Functions for formatting field
contents.
(ebdb-notice-field): Notice field method for storing links.
---
ebdb-gnorb.el | 149 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 145 insertions(+), 4 deletions(-)
diff --git a/ebdb-gnorb.el b/ebdb-gnorb.el
index 1e9c0b9..668fa38 100644
--- a/ebdb-gnorb.el
+++ b/ebdb-gnorb.el
@@ -24,6 +24,65 @@
;;; Code:
+(require 'ebdb-format)
+(require 'ebdb-com)
+
+;; Probably we shouldn't use this, EBDB should not have a dependency
+;; on Org.
+
+;; Actually the real problem is that this is Gnus specific, we should
+;; have equivalent methods for all the MUAs, something like
+;; `ebdb-mua-find-messages'.
+(autoload 'org-gnus-follow-link "org-gnus")
+(autoload 'article-lapsed-string "gnus-art")
+
+(defgroup gnorb-ebdb nil
+ "Customizations for Gnorb-specific functionality."
+ :group 'ebdb)
+
+(defcustom gnorb-ebdb-collect-N-messages 5
+ "For records with a `ebdb-gnorb-messages-field',
+collect links to a maximum of this many messages."
+
+ :group 'gnorb-ebdb
+ :type 'integer)
+
+(defcustom gnorb-ebdb-define-recent 'seen
+ "For records with a `gnorb-ebdb-message-tag-field',
+this variable controls how gnorb defines a \"recent\" message.
+Setting it to the symbol 'seen will collect the messages most
+recently opened and viewed. The symbol 'received means gnorb will
+collect the most recent messages by Date header.
+
+In other words, if this variable is set to `received', and a
+record's messages field is already full of recently-received
+messages, opening a five-year-old message (for instance) from
+this record will not push a link to the message into the field."
+
+ :group 'gnorb-ebdb
+ :type '(choice (const :tag "Most recently seen" 'seen)
+ (const :tag "Most recently received" 'received)))
+
+(defcustom gnorb-ebdb-message-format "%:count. %:lapsed: %:subject"
+ "How a single message is formatted in the list of recent messages.
+This format string is used in multi-line record display.
+
+Available information for each message includes the subject, the
+date, and the message's count in the list, as an integer. You can
+access subject and count using the %:subject and %:count escapes.
+The message date can be formatted using any of the escapes
+mentioned in the docstring of `format-time-string', which see, or
+the escape %:lapsed, which shows how many days ago the message
+was received."
+
+ :group 'gnorb-ebdb
+ :type 'string)
+
+(defface gnorb-ebdb-link '((t :inherit org-link))
+ "Custom face for displaying message links in the *BBDB* buffer.
+ Defaults to org-link."
+ :group 'gnorb-ebdb)
+
(cl-defstruct gnorb-ebdb-link
subject date group id)
@@ -31,10 +90,92 @@
((messages
:type (list-of gnorb-ebdb-link)
:initarg :messages
- :initform nil))
- :human-readable "gnorb messages")
+ :initform nil)
+ (actions :initform '(("Follow link" . gnorb-ebdb-follow-link))))
+ :human-readable "gnus messages")
+
+(defun gnorb-ebdb-follow-link (record field)
+ (when-let ((link (or
+ (get-text-property (point) 'gnorb-link)
+ (get-text-property
+ (ebdb-scan-property 'gnorb-link #'gnorb-ebdb-link-p 1)
+ 'gnorb-link))))
+ (org-gnus-follow-link (gnorb-ebdb-link-group link)
+ (gnorb-ebdb-link-id link))))
+
+(cl-defmethod ebdb-string ((field gnorb-ebdb-field-messages))
+ (format "%d messages" (length (slot-value field 'messages))))
+
+(cl-defmethod ebdb-fmt-field ((fmt ebdb-formatter-ebdb)
+ (field gnorb-ebdb-field-messages)
+ _style
+ (record ebdb-record))
+ ;; Hard-code this for now, we can provide more options later.
+ (let* ((article-time-units '((day . 86400)))
+ (msgs (slot-value field 'messages))
+ (outstring
+ (if (= (length msgs) 0)
+ "No message yet"
+ (mapconcat
+ #'identity
+ (let ((count 0))
+ (mapcar
+ (lambda (m)
+ (propertize
+ (format-time-string
+ (replace-regexp-in-string
+ "%:lapsed" (article-lapsed-string
+ (gnorb-ebdb-link-date m) 1)
+ (replace-regexp-in-string
+ "%:subject" (substring
+ (gnorb-ebdb-link-subject m)
+ 0 (min 30
+ (length (gnorb-ebdb-link-subject m))))
+ (replace-regexp-in-string
+ "%:count" (number-to-string (cl-incf count))
+ gnorb-ebdb-message-format)))
+ (gnorb-ebdb-link-date m))
+ 'face 'gnorb-ebdb-link
+ 'gnorb-link m))
+ msgs))
+ "\n"))))
+ outstring))
+
+(cl-defmethod ebdb-notice-field ((field gnorb-ebdb-field-messages)
+ (_type (eql from))
+ _hdrs
+ (record ebdb-record))
+ "Used in the `bbdb-notice' to possibly save a link
+to a message into the record's `gnorb-ebdb-messages-field'."
-(cl-defmethod ebdb-string ((_field gnorb-ebdb-field-messages))
- "Some messages")
+ (when (memq major-mode '(gnus-summary-mode gnus-article-mode))
+ (with-current-buffer gnus-summary-buffer
+ (let* ((val (slot-value field 'messages))
+ (art-no (gnus-summary-article-number))
+ (heads (gnus-summary-article-header art-no))
+ (date (apply 'encode-time
+ (parse-time-string (mail-header-date heads))))
+ (subject (mail-header-subject heads))
+ (id (mail-header-id heads))
+ (group (gnorb-get-real-group-name
+ gnus-newsgroup-name
+ art-no))
+ link)
+ (if (not (and date subject id group))
+ (message "Could not save a link to this message")
+ (setq link (make-gnorb-ebdb-link :subject subject :date date
+ :group group :id id))
+ (setq val (cons link (delete link val)))
+ (when (eq gnorb-ebdb-define-recent 'received)
+ (setq val (sort val
+ (lambda (a b)
+ (time-less-p
+ (gnorb-bbdb-link-date b)
+ (gnorb-bbdb-link-date a))))))
+ (setq val (cl-subseq val 0 (min (length val)
gnorb-ebdb-collect-N-messages)))
+ (ebdb-record-change-field
+ record field
+ (make-instance 'gnorb-ebdb-field-messages
+ :messages val)))))))
(provide 'ebdb-gnorb)
- [elpa] externals/ebdb a776d37 248/350: Don't use copy-sequence plus add-text-properties on strings, (continued)
- [elpa] externals/ebdb a776d37 248/350: Don't use copy-sequence plus add-text-properties on strings, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 96b113d 251/350: New functions for folding/unfolding long vCard lines, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb b52cdc0 265/350: Record-insert|delete-field methods can find their own slots, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb fcee6ab 267/350: Protect against no current record when redisplaying, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb f3b9525 269/350: Temporarily abandon having record-change-name accept strings, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 1a31515 274/350: Fixes to record loading, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 01262e3 277/350: Mark EBDB buffers as modified after edits, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb cc83f62 197/350: Add protection around ebdb-record-uuid, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 4f3db7f 195/350: Save match data around ebdb-parse-i18n, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb fcf0702 275/350: Mark EBDB buffers as unmodified after save, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 88f5e12 261/350: Fill out functionality of gnorb messages field,
Eric Abrahamsen <=
- [elpa] externals/ebdb a81769c 272/350: Allow custom hash predicates, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb e80753a 264/350: Change ebdb-record-change-name to accept strings, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb d3e1485 283/350: Reinstate the notice record hook, and move notice-record method, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb d8bc159 290/350: Fairly embarrassing oversight in setting ebdb buffers modified, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb afe5495 279/350: Adjust indentation of multi-line field values, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb bbe407e 257/350: Code tweaks and re-arrangments, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 727eddb 262/350: Change databases' buffer-char slot into actual character, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 5362b12 291/350: require pyim, for chinese-pyim has been renamed to pyim (#45), Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb f62f15f 282/350: Pop up empty *EBDB* buffer for users with no records, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb f3f9f37 292/350: Move, rename and bind ebdb-mail-yank, Eric Abrahamsen, 2017/08/14