]> code.delx.au - gnu-emacs-elpa/blobdiff - nngnorb.el
Squashed 'packages/gnorb/' changes from 538b5bd..d754d2f
[gnu-emacs-elpa] / nngnorb.el
index bdaf569bc8fa66be8ee4d39fc04ae1f6885dbfcd..bb0ddfdcdfe917ab1e2110ab8e641760e40475a5 100644 (file)
@@ -1,6 +1,6 @@
 ;;; nngnorb.el --- Gnorb backend for Gnus
 
-;; This file is in the public domain.
+;; Copyright (C) 2014  Free Software Foundation, Inc.
 
 ;; Author: Eric Abrahamsen <eric@ericabrahamsen.net.>
 
@@ -39,6 +39,7 @@
 
 ;;; Code:
 
+(require 'gnus)
 (eval-and-compile
   (require 'nnheader)
   (require 'nnir))
@@ -51,7 +52,7 @@
 
 (make-variable-buffer-local 'nngnorb-attachment-file-list)
 
-(gnus-declare-backend "nngnorb" 'none)
+(gnus-declare-backend "nngnorb" 'post-mail 'virtual)
 
 (add-to-list 'nnir-method-default-engines '(nngnorb . gnorb))
 
@@ -78,14 +79,14 @@ be scanned for gnus messages, and those messages displayed."
   ;; a property, and the new registry-based system, we're going to use
   ;; both methods to collect relevant messages. This could be a little
   ;; slower, but for the time being it will be safer.
-  (save-excursion
+  (save-window-excursion
     (let ((q (cdr (assq 'query query)))
          (buf (get-buffer-create nnir-tmp-buffer))
          msg-ids org-ids links vectors)
       (with-current-buffer buf
        (erase-buffer)
        (setq nngnorb-attachment-file-list nil))
-      (when (equal "5.13" gnus-version-number)
+      (when (and (equal "5.13" gnus-version-number) (version< emacs-version "24.4"))
        (setq q (car q)))
       (cond ((string-match "id\\+\\([[:alnum:]-]+\\)$" q)
             (with-demoted-errors "Error: %S"
@@ -141,7 +142,7 @@ be scanned for gnus messages, and those messages displayed."
       (dolist (i (delq nil org-ids))
        (let ((rel-msg-id (gnorb-registry-org-id-search i)))
          (when rel-msg-id
-           (setq msg-ids (append rel-msg-id msg-ids)))))
+           (setq msg-ids (append (delq nil rel-msg-id) msg-ids)))))
       (when msg-ids
          (dolist (id msg-ids)
            (let ((link (gnorb-msg-id-to-link id)))
@@ -156,7 +157,8 @@ be scanned for gnus messages, and those messages displayed."
          (setq m (org-link-unescape m))
          (when (string-match "\\`\\([^#]+\\)\\(#\\(.*\\)\\)?" m)
            (setq server-group (match-string 1 m)
-                 msg-id (match-string 3 m)
+                 msg-id (gnorb-bracket-message-id
+                         (match-string 3 m))
                  result (ignore-errors (gnus-request-head msg-id server-group)))
            (when result
             (setq artno (cdr result))
@@ -181,7 +183,7 @@ continue to provide tracking of sent messages."
        ;; this summary buffer.
        (buffer-local-value
         'nngnorb-attachment-file-list
-         (get-buffer nnir-tmp-buffer))))
+         (get-buffer-create nnir-tmp-buffer))))
 
 (define-key gnorb-summary-minor-mode-map
   [remap gnus-summary-exit]
@@ -276,8 +278,12 @@ continue to provide tracking of sent messages."
        (message-insert-header
         (intern gnorb-mail-header)
         org-id)
-       (add-to-list 'message-exit-actions
-                    'gnorb-org-restore-after-send t))
+       ;; As with elsewhere, this should be redundant with
+       ;; `gnorb-gnus-check-outgoing-headers.'  Even if not, it
+       ;; should be switched to use `message-send-actions'
+       ;; (add-to-list 'message-exit-actions
+       ;; 'gnorb-org-restore-after-send t)
+       )
       (goto-char compose-marker))
     (when attachments
       (map-y-or-n-p
@@ -302,27 +308,36 @@ This is used in a Gnorb-created *Summary* buffer to remove the
 connection between the message and whichever Org TODO resulted in
 the message being included in this search."
   (interactive)
+  (unless (get-buffer-window gnus-article-buffer t)
+    (gnus-summary-display-article
+     (gnus-summary-article-number)))
   (let* ((msg-id (gnus-fetch-original-field "message-id"))
         (org-ids (gnus-registry-get-id-key msg-id 'gnorb-ids))
-        chosen)
-    (when org-ids
-      (if (= (length org-ids) 1)
-         ;; Only one associated Org TODO.
-         (progn (gnus-registry-set-id-key msg-id 'gnorb-ids)
-                (setq chosen (car org-ids)))
-       ;; Multiple associated TODOs, prompt to choose one.
-       (setq chosen
-             (cdr
-              (org-completing-read
-               "Choose a TODO to disassociate from: "
-               (mapcar
-                (lambda (h)
-                  (cons (gnorb-pretty-outline h) h))
-                org-ids))))
-       (gnus-registry-set-id-key msg-id 'gnorb-ids
-                                 (remove chosen org-ids)))
-      (message "Message disassociated from %s"
-              (gnorb-pretty-outline chosen)))))
+        chosen multiple-alist)
+    (if org-ids
+       (progn
+         (if (= (length org-ids) 1)
+             ;; Only one associated Org TODO.
+             (progn (gnus-registry-set-id-key msg-id 'gnorb-ids nil)
+                    (setq chosen (car org-ids)))
+           ;; Multiple associated TODOs, prompt to choose one.
+           (setq multiple-alist
+                 (mapcar
+                  (lambda (h)
+                    (cons (gnorb-pretty-outline h) h))
+                  org-ids))
+           (setq chosen
+                 (cdr
+                  (assoc
+                   (org-completing-read
+                    "Choose a TODO to disassociate from: "
+                    multiple-alist)
+                   multiple-alist)))
+           (gnus-registry-set-id-key msg-id 'gnorb-ids
+                                     (remove chosen org-ids)))
+         (message "Message disassociated from %s"
+                  (gnorb-pretty-outline chosen)))
+      (message "Message has no associations"))))
 
 (defvar nngnorb-status-string "")