]> code.delx.au - gnu-emacs-elpa/blob - packages/gnorb/gnorb-org.el
Merge commit '3fa56d7925d5b24c5cd11c61bd6b3235e753a055'
[gnu-emacs-elpa] / packages / gnorb / gnorb-org.el
1 ;;; gnorb-org.el --- The Org-centric functions of gnorb
2
3 ;; Copyright (C) 2014 Free Software Foundation, Inc.
4
5 ;; Author: Eric Abrahamsen <eric@ericabrahamsen.net>
6 ;; Keywords:
7
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
12
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
17
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
20
21 ;;; Commentary:
22
23 ;;
24
25 ;;; Code:
26
27 (require 'gnorb-utils)
28 (require 'cl-lib)
29
30 (defgroup gnorb-org nil
31 "The Org bits of Gnorb."
32 :tag "Gnorb Org"
33 :group 'gnorb)
34
35 (defcustom gnorb-org-after-message-setup-hook nil
36 "Hook run in a message buffer after setting up the message from
37 `gnorb-org-handle-mail' or `gnorb-org-email-subtree'."
38 :group 'gnorb-org
39 :type 'hook)
40
41 (defcustom gnorb-org-trigger-actions
42 '(("todo state" . todo)
43 ("take note" . note)
44 ("don't associate" . no-associate)
45 ("only associate" . associate)
46 ; ("capture to child" . cap-child)
47 ; ("capture to sibling" . cap-sib)
48 )
49 "List of potential actions that can be taken on headings.
50
51 When triggering an Org heading after receiving or sending a
52 message, this option lists the possible actions to take. Built-in
53 actions include:
54
55 todo state: Associate the message, and change TODO state.
56 take note: Associate the message, and take a note.
57 don't associate: Do nothing at all, don't connect the message and TODO.
58 only associate: Associate the message with this heading, do nothing else.
59 capture to child: [not yet implemented] Associate this message with a new child heading.
60 capture to sibling: [not yet implemented] Associate this message with a new sibling heading.
61
62 You can reorder this list or remove items as suits your workflow.
63 The two \"capture\" options will use the value of
64 `gnorb-gnus-new-todo-capture-key' to find the appropriate
65 template.
66
67 You can also add custom actions to the list. Actions should be a
68 cons of a string tag and a symbol indicating a custom function.
69 This function will be called on the heading in question, and
70 passed a plist containing information about the message from
71 which we're triggering."
72 :group 'gnorb-org
73 :type 'list)
74
75 (defcustom gnorb-org-msg-id-key "GNORB_MSG_ID"
76 "The name of the org property used to store the Message-IDs
77 from relevant messages. This is no longer used, and will be
78 removed soon."
79 :group 'gnorb-org
80 :type 'string)
81
82 (defcustom gnorb-org-mail-scan-scope 2
83 "Number of paragraphs to scan for mail-related links.
84
85 When handling a TODO heading with `gnorb-org-handle-mail', Gnorb
86 will typically reply to the most recent message associated with
87 this heading. If there are no such messages, or message tracking
88 is disabled entirely, or `gnorb-org-handle-mail' has been called
89 with a prefix arg, the heading and body text of the subtree under
90 point will instead be scanned for gnus:, mailto:, and bbdb:
91 links. This option controls how many paragraphs of body text to
92 scan. Set to 0 to only look in the heading.")
93
94 (make-obsolete-variable
95 'gnorb-org-mail-scan-strategies
96 "This variable has been superseded by `gnorb-org-trigger-actions'"
97 "September 12, 2014" 'set)
98
99 (make-obsolete-variable
100 'gnorb-org-mail-scan-state-changes
101 "This variable has been superseded by `gnorb-org-trigger-actions'"
102 "September 12, 2014" 'set)
103
104 (make-obsolete-variable
105 'gnorb-org-mail-scan-function
106 "This variable has been superseded by `gnorb-org-trigger-actions'"
107 "September 12, 2014" 'set)
108
109 (defcustom gnorb-org-find-candidates-match nil
110 "When scanning all org files for heading related to an incoming
111 message, this option will limit which headings will be offered as
112 target candidates. Specifically it will be used as the second
113 argument to `org-map-entries', and syntax is the same as that
114 used in an agenda tags view."
115 :group 'gnorb-org
116 :type 'symbol)
117
118 ;;;###autoload
119 (defun gnorb-org-contact-link (rec)
120 "Prompt for a BBDB record and insert a link to that record at
121 point.
122
123 There's really no reason to use this instead of regular old
124 `org-insert-link' with BBDB completion. But there might be in the
125 future!"
126 ;; this needs to handle an active region.
127 (interactive (list (gnorb-prompt-for-bbdb-record)))
128 (let* ((name (bbdb-record-name rec))
129 (link (concat "bbdb:" (org-link-escape name))))
130 (org-store-link-props :type "bbdb" :name name
131 :link link :description name)
132 (if (called-interactively-p 'any)
133 (insert (format "[[%s][%s]]" link name))
134 link)))
135
136 (defun gnorb-org-restore-after-send ()
137 "After an email is sent, go through all the org ids that might
138 have been in the outgoing message's headers and call
139 `gnorb-trigger-todo-action' on each one, then put us back where
140 we came from."
141 (delete-other-windows)
142 (dolist (id gnorb-message-org-ids)
143 (org-id-goto id)
144 (gnorb-trigger-todo-action nil id))
145 ;; this is a little unnecessary, but it may save grief
146 (setq gnorb-gnus-message-info nil)
147 (setq gnorb-message-org-ids nil)
148 (gnorb-restore-layout))
149
150 (defun gnorb-org-extract-links (&optional arg region)
151 "See if there are viable links in the subtree under point."
152 ;; We're not currently using the arg. What could we do with it?
153 (let (strings)
154 ;; If the region was active, only use the region
155 (if region
156 (push (buffer-substring (car region) (cdr region))
157 strings)
158 ;; Otherwise collect the heading text, and all the paragraph
159 ;; text.
160 (save-restriction
161 (org-narrow-to-subtree)
162 (let ((head (org-element-at-point))
163 (tree (org-element-parse-buffer)))
164 (push (org-element-property
165 :raw-value
166 head)
167 strings)
168 (org-element-map tree 'paragraph
169 (lambda (p)
170 (push (org-element-interpret-data p)
171 strings))
172 nil nil 'drawer))))
173 (when strings
174 ;; Limit number of paragraphs based on
175 ;; `gnorb-org-mail-scan-scope'
176 (setq strings
177 (cond ((eq gnorb-org-mail-scan-scope 'all)
178 strings)
179 ((numberp gnorb-org-mail-scan-scope)
180 (delq nil
181 (cl-subseq
182 strings 0 (1+ gnorb-org-mail-scan-scope))))
183 ;; We could provide more options here. 'tree vs
184 ;; 'subtree, for instance.
185 (t
186 strings)))
187 (with-temp-buffer
188 (dolist (s strings)
189 (insert s)
190 (insert "\n"))
191 (goto-char (point-min))
192 (gnorb-scan-links (point-max) 'gnus 'mail 'bbdb)))))
193
194 (defun gnorb-org-extract-mail-stuff (&optional arg region)
195 "Decide how to hande the Org heading under point as an email task.
196
197 See the docstring of `gnorb-org-handle-mail' for details."
198 (if (or (not gnorb-tracking-enabled)
199 region)
200 (gnorb-org-extract-links arg region)
201 ;; Get all the messages associated with the IDS in this subtree.
202 (let ((assoc-msg-ids
203 (delete-dups
204 (cl-mapcan
205 (lambda (id)
206 (gnorb-registry-org-id-search id))
207 (gnorb-collect-ids)))))
208 (gnorb-org-extract-mail-tracking assoc-msg-ids arg region))))
209
210 (defun gnorb-org-extract-mail-tracking (assoc-msg-ids &optional arg region)
211
212 (let* ((all-links (gnorb-org-extract-links nil region))
213 ;; The latest (by the creation-time registry key) of all the
214 ;; tracked messages that were not sent by our user.
215 (latest-msg-id
216 (when assoc-msg-ids
217 (car
218 (sort
219 (cl-remove-if
220 (lambda (m)
221 (let ((from (car (gnus-registry-get-id-key m 'sender))))
222 (or (null from)
223 (string-match-p
224 user-mail-address from)
225 (string-match-p
226 message-alternative-emails from))))
227 assoc-msg-ids)
228 (lambda (r l)
229 (time-less-p
230 (car (gnus-registry-get-id-key l 'creation-time))
231 (car (gnus-registry-get-id-key r 'creation-time))))))))
232 (msg-id-link
233 (when latest-msg-id
234 (gnorb-msg-id-to-link latest-msg-id))))
235 (cond
236 ;; If there are no tracked messages, or the user has specifically
237 ;; requested we ignore them with the prefix arg, just return the
238 ;; found links in the subtree.
239 ((or arg
240 (null msg-id-link))
241 all-links)
242 ;; Otherwise ignore the other links in the subtree, and return
243 ;; the latest message.
244 (msg-id-link
245 `(:gnus ,(list msg-id-link))))))
246
247 (defvar message-beginning-of-line)
248
249 (defun gnorb-org-setup-message
250 (&optional messages mails from cc bcc attachments text ids)
251 "Common message setup routine for other gnorb-org commands.
252 MESSAGES is a list of gnus links pointing to messages -- we
253 currently only use the first of the list. MAILS is a list of
254 email address strings suitable for inserting in the To header.
255 ATTACHMENTS is a list of filenames to attach. TEXT is a string or
256 buffer, which is inserted in the message body. IDS is one or more
257 Org heading ids, associating the outgoing message with those
258 headings."
259 (require 'gnorb-gnus)
260 (if (not messages)
261 ;; Either compose new message...
262 (compose-mail)
263 ;; ...or follow link and start reply.
264 (condition-case err
265 (gnorb-reply-to-gnus-link (car messages))
266 (error (gnorb-restore-layout)
267 (signal (car err) (cdr err)))))
268 ;; Add MAILS to message To header.
269 (when mails
270 (message-goto-to)
271 (when messages
272 (insert ", "))
273 (insert (mapconcat 'identity mails ", ")))
274 ;; Return us after message is sent.
275 (add-to-list 'message-exit-actions
276 'gnorb-org-restore-after-send t)
277 ;; Set headers from MAIL_* properties (from, cc, and bcc).
278 (cl-flet ((sh (h)
279 (when (cdr h)
280 (funcall (intern (format "message-goto-%s" (car h))))
281 (let ((message-beginning-of-line t)
282 (show-trailing-whitespace t))
283 (message-beginning-of-line)
284 (unless (bolp)
285 (kill-line))
286 (insert (cdr h))))))
287 (dolist (h `((from . ,from) (cc . ,cc) (bcc . ,bcc)))
288 (sh h)))
289 ;; attach ATTACHMENTS
290 (map-y-or-n-p
291 (lambda (a) (format "Attach %s to outgoing message? "
292 (file-name-nondirectory a)))
293 (lambda (a)
294 (mml-attach-file a (mm-default-file-encoding a)
295 nil "attachment"))
296 attachments
297 '("file" "files" "attach"))
298 ;; insert text, if any
299 (when text
300 (message-goto-body)
301 (insert"\n")
302 (if (bufferp text)
303 (insert-buffer-substring text)
304 (insert text)))
305 ;; insert org ids, if any
306 (when ids
307 (unless (listp ids)
308 (setq ids (list ids)))
309 (save-excursion
310 (save-restriction
311 (message-narrow-to-headers)
312 (dolist (i ids)
313 (goto-char (point-at-bol))
314 (open-line 1)
315 ;; this function hardly does anything
316 (message-insert-header
317 (intern gnorb-mail-header) i)))))
318 ;; put point somewhere reasonable
319 (if (or mails messages)
320 (if (not messages)
321 (message-goto-subject)
322 (message-goto-body))
323 (message-goto-to))
324 (run-hooks 'gnorb-org-after-message-setup-hook))
325
326 (defun gnorb-org-attachment-list (&optional id)
327 "Get a list of files (absolute filenames) attached to the
328 current heading, or the heading indicated by optional argument ID."
329 (when (featurep 'org-attach)
330 (let* ((attach-dir (save-excursion
331 (when id
332 (org-id-goto id))
333 (org-attach-dir t)))
334 (files
335 (mapcar
336 (lambda (f)
337 (expand-file-name f attach-dir))
338 (org-attach-file-list attach-dir))))
339 files)))
340
341 (defvar message-mode-hook)
342
343 ;;;###autoload
344 (defun gnorb-org-handle-mail (&optional arg text file)
345 "Handle current headline as a mail TODO.
346
347 How this function behaves depends on whether you're using Gnorb
348 for email tracking, also on the prefix arg, and on the active
349 region.
350
351 If tracking is enabled and there is no prefix arg, Gnorb will
352 begin a reply to the newest associated message that wasn't sent
353 by the user -- ie, the Sender header doesn't match
354 `user-mail-address' or `message-alternative-emails'.
355
356 If tracking is enabled and there is a prefix arg, ignore the
357 tracked messages and instead scan the subtree for mail-related
358 links. This means links prefixed with gnus:, mailto:, or bbdb:.
359 See `gnorb-org-mail-scan-scope' to limit the scope of this scan.
360 Do something appropriate with the resulting links.
361
362 With a double prefix arg, ignore all tracked messages and all
363 links, and compose a blank new message.
364
365 If tracking is enabled and you want to reply to a
366 specific (earlier) message in the tracking history, use
367 `gnorb-org-view' to open an nnir *Summary* buffer containing all
368 the messages, and reply to the one you want. Your reply will be
369 automatically tracked, as well.
370
371 If tracking is not enabled and you want to use a specific link in
372 the subtree as a basis for the email action, then put the region
373 around that link before you call this message."
374 (interactive "P")
375 (setq gnorb-window-conf (current-window-configuration))
376 (move-marker gnorb-return-marker (point))
377 (when (eq major-mode 'org-agenda-mode)
378 ;; If this is all the different types, we could skip the check.
379 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags 'search)
380 (org-agenda-check-no-diary)
381 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
382 (org-agenda-error)))
383 (buffer (marker-buffer marker))
384 (pos (marker-position marker)))
385 (switch-to-buffer buffer)
386 (widen)
387 (goto-char pos)))
388 (let ((region
389 (when (use-region-p)
390 (cons (region-beginning) (region-end)))))
391 (deactivate-mark)
392 (save-excursion
393 (unless (org-back-to-heading t)
394 (error "Not in an org item"))
395 (cl-flet ((mp (p) (org-entry-get (point) p t)))
396 ;; Double prefix means ignore everything and compose a blank
397 ;; mail.
398 (let* ((links (unless (equal arg '(16))
399 (gnorb-org-extract-mail-stuff arg region)))
400 (attachments (gnorb-org-attachment-list))
401 (from (mp "MAIL_FROM"))
402 (cc (mp "MAIL_CC"))
403 (bcc (mp "MAIL_BCC"))
404 (org-id (org-id-get-create))
405 (recs (plist-get links :bbdb))
406 (message-mode-hook (copy-sequence message-mode-hook))
407 mails)
408 (when file
409 (cons file attachments))
410 (when recs
411 (setq recs
412 (delq nil
413 (mapcar
414 (lambda (r)
415 (car (bbdb-message-search
416 (org-link-unescape r)
417 nil)))
418 recs))))
419 (when recs
420 (dolist (r recs)
421 (push (bbdb-mail-address r) mails)))
422 (when (and recs
423 gnorb-bbdb-posting-styles)
424 (add-hook 'message-mode-hook
425 (lambda ()
426 (gnorb-bbdb-configure-posting-styles (cdr recs))
427 (gnorb-bbdb-configure-posting-styles (list (car recs))))))
428 (gnorb-org-setup-message
429 (plist-get links :gnus)
430 (append mails (plist-get links :mail))
431 from cc bcc
432 attachments text org-id))))))
433
434 ;;; Email subtree
435
436 (defcustom gnorb-org-email-subtree-text-parameters nil
437 "A plist of export parameters corresponding to the EXT-PLIST
438 argument to the export functions, for use when exporting to
439 text."
440 :group 'gnorb-org
441 :type 'boolean)
442
443 (defcustom gnorb-org-email-subtree-file-parameters nil
444 "A plist of export parameters corresponding to the EXT-PLIST
445 argument to the export functions, for use when exporting to a
446 file."
447 :group 'gnorb-org
448 :type 'boolean)
449
450 (defcustom gnorb-org-email-subtree-text-options '(nil t nil t)
451 "A list of ts and nils corresponding to Org's export options,
452 to be used when exporting to text. The options, in order, are
453 async, subtreep, visible-only, and body-only."
454 :group 'gnorb-org
455 :type 'list)
456
457 (defcustom gnorb-org-email-subtree-file-options '(nil t nil nil)
458 "A list of ts and nils corresponding to Org's export options,
459 to be used when exporting to a file. The options, in order, are
460 async, subtreep, visible-only, and body-only."
461 :group 'gnorb-org
462 :type 'list)
463
464 (defcustom gnorb-org-export-extensions
465 '((latex ".tex")
466 (ascii ".txt")
467 (html ".html")
468 (org ".org")
469 (icalendar ".ics")
470 (man ".man")
471 (md ".md")
472 (odt ".odt") ; not really, though
473 (texinfo ".texi")
474 (beamer ".tex"))
475 "Correspondence between export backends and their
476 respective (usual) file extensions. Ugly way to do it, but what
477 the hey..."
478 :group 'gnorb-org)
479
480 (defvar org-export-show-temporary-export-buffer)
481
482 ;;;###autoload
483 (defun gnorb-org-email-subtree (&optional arg)
484 "Call on a subtree to export it either to a text string or a file,
485 then compose a mail message either with the exported text
486 inserted into the message body, or the exported file attached to
487 the message.
488
489 Export options default to the following: When exporting to a
490 buffer: async = nil, subtreep = t, visible-only = nil, body-only
491 = t. Options are the same for files, except body-only is set to
492 nil. Customize `gnorb-org-email-subtree-text-options' and
493 `gnorb-org-email-subtree-file-options', respectively.
494
495 Customize `gnorb-org-email-subtree-parameters' to your preferred
496 default set of parameters."
497 ;; I sure would have liked to use the built-in dispatch ui, but it's
498 ;; got too much hard-coded stuff.
499 (interactive "P")
500 (org-back-to-heading t)
501 (let* ((backend-string
502 (org-completing-read
503 "Export backend: "
504 (mapcar (lambda (b)
505 (symbol-name (org-export-backend-name b)))
506 org-export--registered-backends)
507 nil t))
508 (backend-symbol (intern backend-string))
509 (f-or-t (org-completing-read "Export as file or text? "
510 '("file" "text") nil t))
511 (org-export-show-temporary-export-buffer nil)
512 (opts (if (equal f-or-t "text")
513 gnorb-org-email-subtree-text-options
514 gnorb-org-email-subtree-file-options))
515 (result
516 (if (equal f-or-t "text")
517 (apply 'org-export-to-buffer
518 `(,backend-symbol
519 "*Gnorb Export*"
520 ,@opts
521 ,gnorb-org-email-subtree-text-parameters))
522 (apply 'org-export-to-file
523 `(,backend-symbol
524 ,(org-export-output-file-name
525 (cl-second (assoc backend-symbol gnorb-org-export-extensions))
526 t gnorb-tmp-dir)
527 ,@opts
528 ,gnorb-org-email-subtree-file-parameters))))
529 text file)
530 (setq gnorb-window-conf (current-window-configuration))
531 (move-marker gnorb-return-marker (point))
532 (if (bufferp result)
533 (setq text result)
534 (setq file result))
535 (gnorb-org-handle-mail arg text file)))
536
537 (defcustom gnorb-org-capture-collect-link-p t
538 "Should the capture process store a link to the gnus message or
539 BBDB record under point, even if it's not part of the template?
540 You'll probably end up needing it, anyway."
541 :group 'gnorb-org)
542
543 (defun gnorb-org-capture-collect-link ()
544 (when gnorb-org-capture-collect-link-p
545 (let ((buf (org-capture-get :original-buffer)))
546 (when buf
547 (with-current-buffer buf
548 (when (memq major-mode '(gnus-summary-mode
549 gnus-article-mode
550 bbdb-mode))
551 (call-interactively 'org-store-link)))))))
552
553 (add-hook 'org-capture-mode-hook 'gnorb-org-capture-collect-link)
554
555 ;;; Agenda/BBDB popup stuff
556
557 (defcustom gnorb-org-agenda-popup-bbdb nil
558 "Should Agenda tags search pop up a BBDB buffer with matching
559 records?
560
561 Records are considered matching if they have an `org-tags' field
562 matching the current Agenda search. The name of that field can be
563 customized with `gnorb-bbdb-org-tag-field'."
564 :group 'gnorb-org)
565
566 (defcustom gnorb-org-bbdb-popup-layout 'pop-up-multi-line
567 "Default BBDB buffer layout for automatic Org Agenda display."
568 :group 'gnorb-org
569 :type '(choice (const one-line)
570 (const multi-line)
571 (const full-multi-line)
572 (symbol)))
573
574 ;;;###autoload
575 (defun gnorb-org-popup-bbdb (&optional str)
576 "In an `org-tags-view' Agenda buffer, pop up a BBDB buffer
577 showing records whose `org-tags' field matches the current tags
578 search."
579 ;; I was hoping to use `org-make-tags-matcher' directly, then snag
580 ;; the tagmatcher from the resulting value, but there doesn't seem
581 ;; to be a reliable way of only getting the tag-related returns. But
582 ;; I'd still like to use that function. So an ugly hack to first
583 ;; remove non-tag contents from the query string, and then make a
584 ;; new call to `org-make-tags-matcher'.
585 (interactive)
586 (require 'gnorb-bbdb)
587 (let (recs)
588 (cond ((and
589 (and (eq major-mode 'org-agenda-mode)
590 (eq org-agenda-type 'tags))
591 (or (called-interactively-p 'any)
592 gnorb-org-agenda-popup-bbdb))
593 (let ((todo-only nil)
594 (str (or str org-agenda-query-string))
595 (re "^&?\\([-+:]\\)?\\({[^}]+}\\|LEVEL\\([<=>]\\{1,2\\}\\)\\([0-9]+\\)\\|\\(\\(?:[[:alnum:]_]+\\(?:\\\\-\\)*\\)+\\)\\([<>=]\\{1,2\\}\\)\\({[^}]+}\\|\"[^\"]*\"\\|-?[.0-9]+\\(?:[eE][-+]?[0-9]+\\)?\\)\\|[[:alnum:]_@#%]+\\)")
596 or-terms term rest out-or acc tag-clause)
597 (setq or-terms (org-split-string str "|"))
598 (while (setq term (pop or-terms))
599 (setq acc nil)
600 (while (string-match re term)
601 (setq rest (substring term (match-end 0)))
602 (let ((sub-term (match-string 0 term)))
603 (unless (save-match-data ; this isn't a tag, don't want it
604 (string-match "\\([<>=]\\)" sub-term))
605 (push sub-term acc))
606 (setq term rest)))
607 (push (mapconcat 'identity (nreverse acc) "") out-or))
608 (setq str (mapconcat 'identity (nreverse out-or) "|"))
609 (setq tag-clause (cdr (org-make-tags-matcher str)))
610 (unless (equal str "")
611 (setq recs
612 (cl-remove-if-not
613 (lambda (r)
614 (let ((rec-tags (bbdb-record-xfield
615 r gnorb-bbdb-org-tag-field)))
616 (and rec-tags
617 (let ((tags-list (org-split-string rec-tags ":"))
618 (case-fold-search t)
619 (org-trust-scanner-tags t))
620 (eval tag-clause)))))
621 (bbdb-records))))))
622 ((eq major-mode 'org-mode)
623 (save-excursion
624 (org-back-to-heading)
625 (let ((bound (org-element-property
626 :end (org-element-at-point)))
627 desc rec)
628 (while (re-search-forward
629 org-bracket-link-analytic-regexp bound t)
630 (when (string-match-p "bbdb" (match-string 2))
631 (setq desc (match-string 5)
632 rec (bbdb-search (bbdb-records) desc desc desc)
633 recs (append recs rec))))))))
634 (if recs
635 (bbdb-display-records
636 recs gnorb-org-bbdb-popup-layout)
637 (when (get-buffer-window bbdb-buffer-name)
638 (quit-window nil
639 (get-buffer-window bbdb-buffer-name)))
640 (when (called-interactively-p 'any)
641 (message "No relevant BBDB records")))))
642
643 (if (featurep 'gnorb-bbdb)
644 (add-hook 'org-agenda-finalize-hook 'gnorb-org-popup-bbdb))
645
646 ;;; Groups from the gnorb gnus server backend
647
648 ;;;###autoload
649 (defun gnorb-org-view ()
650 "Search the subtree at point for links to gnus messages, and
651 then show them in an ephemeral group, in gnus.
652
653 This won't work unless you've added a \"nngnorb\" server to
654 your gnus select methods."
655 ;; this should also work on the active region, if there is one.
656 (interactive)
657 (require 'gnorb-gnus)
658 (setq gnorb-window-conf (current-window-configuration))
659 (move-marker gnorb-return-marker (point))
660 (when (eq major-mode 'org-agenda-mode)
661 (org-agenda-check-type t 'agenda 'timeline 'todo 'tags)
662 (org-agenda-check-no-diary)
663 (let* ((marker (or (org-get-at-bol 'org-hd-marker)
664 (org-agenda-error)))
665 (buffer (marker-buffer marker))
666 (pos (marker-position marker)))
667 (switch-to-buffer buffer)
668 (goto-char pos)
669 (org-reveal)))
670 (let (id)
671 (save-excursion
672 (org-back-to-heading)
673 (setq id (concat "id+" (org-id-get-create)))
674 (gnorb-gnus-search-messages
675 id
676 `(when (and (window-configuration-p gnorb-window-conf)
677 gnorb-return-marker)
678 (set-window-configuration gnorb-window-conf)
679 (goto-char gnorb-return-marker))))))
680
681 (provide 'gnorb-org)
682 ;;; gnorb-org.el ends here