[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/gnorb 69c3312 089/449: Refactoring of gnorb-org link sc
From: |
Stefan Monnier |
Subject: |
[elpa] externals/gnorb 69c3312 089/449: Refactoring of gnorb-org link scanning |
Date: |
Fri, 27 Nov 2020 23:15:14 -0500 (EST) |
branch: externals/gnorb
commit 69c331286c8f1e5f94817d28debedf1cee544cbf
Author: Eric Abrahamsen <eric@ericabrahamsen.net>
Commit: Eric Abrahamsen <eric@ericabrahamsen.net>
Refactoring of gnorb-org link scanning
lisp/gnorb-utils.el: New separate function `gnorb-scan-links',
previously a part of `gnorb-org-extract-mail-stuff'. New helper subst
`gnorb-bbdb-link-to-mail'.
lisp/gnorb-org.el: Rejigger `gnorb-org-extract-mail-stuff' to use new
functions.
---
lisp/gnorb-org.el | 43 +++++++++++++++++--------------------------
lisp/gnorb-utils.el | 34 ++++++++++++++++++++++++++++++++++
2 files changed, 51 insertions(+), 26 deletions(-)
diff --git a/lisp/gnorb-org.el b/lisp/gnorb-org.el
index fce23ff..934642a 100644
--- a/lisp/gnorb-org.el
+++ b/lisp/gnorb-org.el
@@ -275,32 +275,23 @@ heading text will be scanned for message and mail links."
((eq gnorb-org-mail-scan-scope 'subtree)
(goto-char (point-max))))
(point)))
- message mails)
- (cl-labels
- ((scan-for-links
- (bound)
- (unless (eq (point) bound)
- (while (re-search-forward org-any-link-re bound t)
- (let ((addr (or (match-string-no-properties 2)
- (match-string-no-properties 0))))
- (cond
- ((string-match "^<?gnus:" addr)
- (push (substring addr (match-end 0)) message))
- ((string-match "^<?mailto:" addr)
- (push (substring addr (match-end 0)) mails))
- ((string-match-p "^<?bbdb:" addr)
- (with-current-buffer bbdb-buffer-name
- (let ((recs bbdb-records))
- (org-open-link-from-string (concat "[[" addr "]]"))
- (let ((mail (bbdb-mail-address
(bbdb-current-record))))
- (bbdb-display-records recs)
- (push mail mails)))))))))))
- (org-back-to-heading t)
- (unless state-info
- (scan-for-links (line-end-position)))
- (goto-char start)
- (scan-for-links end))
- (list message mails)))))
+ strings links bbdb-mails)
+ (org-back-to-heading t)
+ (unless state-info
+ (push (buffer-substring (point) (line-end-position)) strings))
+ (push (buffer-substring start end) strings)
+ (with-temp-buffer
+ (dolist (s strings)
+ (insert s)
+ (insert "\n"))
+ (goto-char (point-min))
+ (setq links (gnorb-scan-links (point-max) 'gnus 'mail 'bbdb)))
+ (when (plist-get links :bbdb)
+ (dolist (b (plist-get links :bbdb))
+ (push (gnorb-bbdb-link-to-mail b) bbdb-mails)))
+ (list (plist-get links :gnus)
+ (append bbdb-mails
+ (plist-get links :mail)))))))
(defun gnorb-org-setup-message
(&optional messages mails from cc bcc attachments text ids)
diff --git a/lisp/gnorb-utils.el b/lisp/gnorb-utils.el
index bb63698..1c4a37c 100644
--- a/lisp/gnorb-utils.el
+++ b/lisp/gnorb-utils.el
@@ -144,5 +144,39 @@ the prefix arg."
(call-interactively note-func)
(call-interactively todo-func)))))
+(defsubst gnorb-bbdb-link-to-mail (link)
+ (with-current-buffer bbdb-buffer-name
+ (let ((recs bbdb-records))
+ (org-open-link-from-string (concat "[[bbdb:" link "]]"))
+ (let ((mail (bbdb-mail-address (bbdb-current-record))))
+ (bbdb-display-records recs)
+ mail))))
+
+(defun gnorb-scan-links (bound &rest types)
+ ;; this function could be refactored somewhat -- lots of code
+ ;; repetition. It also should be a little faster for when we're
+ ;; scanning for gnus links only, that's a little slow. We should
+ ;; probably use a different regexp based on the value of TYPES.
+ ;;
+ ;; This function should also *not* be responsible for unescaping
+ ;; links -- we don't know what they're going to be used for, and
+ ;; unescaped is safer.
+ (unless (eq (point) bound)
+ (let (addr gnus mail bbdb)
+ (while (re-search-forward org-any-link-re bound t)
+ (setq addr (or (match-string-no-properties 2)
+ (match-string-no-properties 0)))
+ (cond
+ ((and (memq 'gnus types)
+ (string-match "^<?gnus:" addr))
+ (push (substring addr (match-end 0)) gnus))
+ ((and (memq 'mail types)
+ (string-match "^<?mailto:" addr))
+ (push (substring addr (match-end 0)) mail))
+ ((and (memq 'bbdb types)
+ (string-match "^<?bbdb:" addr))
+ (push (substring addr (match-end 0)) bbdb))))
+ `(:gnus ,gnus :mail ,mail :bbdb ,bbdb))))
+
(provide 'gnorb-utils)
;;; gnorb-utils.el ends here
- [elpa] externals/gnorb 0db3991 051/449: Move mail search backend stuff to gnorb-gnus, (continued)
- [elpa] externals/gnorb 0db3991 051/449: Move mail search backend stuff to gnorb-gnus, Stefan Monnier, 2020/11/27
- [elpa] externals/gnorb 9fff78a 057/449: Changing email TODO handling to operate by org ID, Stefan Monnier, 2020/11/27
- [elpa] externals/gnorb 30afb67 068/449: Various docstring and comment edits., Stefan Monnier, 2020/11/27
- [elpa] externals/gnorb 7052248 069/449: New generalized function gnorb-trigger-todo-action, Stefan Monnier, 2020/11/27
- [elpa] externals/gnorb 70b5534 070/449: Make TODOs from outgoing messages, Stefan Monnier, 2020/11/27
- [elpa] externals/gnorb bda9cfe 079/449: More complete docs: How to use Gnorb for email tracking, Stefan Monnier, 2020/11/27
- [elpa] externals/gnorb c0e03b2 081/449: Actually add the sent message ID to the TODO, Stefan Monnier, 2020/11/27
- [elpa] externals/gnorb 96afd01 084/449: Skip Note items when scanning state changes, Stefan Monnier, 2020/11/27
- [elpa] externals/gnorb 0c247d4 085/449: Remember to put :group and :type on defcustoms, Stefan Monnier, 2020/11/27
- [elpa] externals/gnorb 5876834 088/449: BBDB posting styles, first draft, Stefan Monnier, 2020/11/27
- [elpa] externals/gnorb 69c3312 089/449: Refactoring of gnorb-org link scanning,
Stefan Monnier <=
- [elpa] externals/gnorb 6a66e21 093/449: Got the arguments to org-get-heading backwards, Stefan Monnier, 2020/11/27
- [elpa] externals/gnorb a64f652 094/449: Have gnorb-org-popup-bbdb scan the whole subtree, Stefan Monnier, 2020/11/27
- [elpa] externals/gnorb 68f1473 096/449: More robust check for an open nngnorb server, Stefan Monnier, 2020/11/27
- [elpa] externals/gnorb 9fbd947 105/449: Collect attachments on incoming trigger action, Stefan Monnier, 2020/11/27
- [elpa] externals/gnorb adba76d 117/449: Rewrite of link-scanning routine, Stefan Monnier, 2020/11/27
- [elpa] externals/gnorb 522f653 121/449: Declare some function, possibly unneccesary, Stefan Monnier, 2020/11/27
- [elpa] externals/gnorb 1a40d11 130/449: Checking wishlist items off, Stefan Monnier, 2020/11/27
- [elpa] externals/gnorb 372986c 132/449: Fix call of key-description, Stefan Monnier, 2020/11/27
- [elpa] externals/gnorb 9ecb0e2 136/449: Use BBDB posting styles in mail composition, Stefan Monnier, 2020/11/27
- [elpa] externals/gnorb 1d9c710 139/449: Error in following link should be re-raised, Stefan Monnier, 2020/11/27