emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/gnorb 5ba5ce4 062/449: Rework gnorb-org-restore-after-s


From: Stefan Monnier
Subject: [elpa] externals/gnorb 5ba5ce4 062/449: Rework gnorb-org-restore-after-send
Date: Fri, 27 Nov 2020 23:15:09 -0500 (EST)

branch: externals/gnorb
commit 5ba5ce42a408974c64da7dc36be9259fb95fc785
Author: Eric Abrahamsen <eric@ericabrahamsen.net>
Commit: Eric Abrahamsen <eric@ericabrahamsen.net>

    Rework gnorb-org-restore-after-send
    
    Now does a better job of ensuring that we're restored to the correct Org
    heading. Also supports visiting multiple Org headings, though there's
    currently no way to set up multiple headings.
---
 lisp/gnorb-org.el | 71 ++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 41 insertions(+), 30 deletions(-)

diff --git a/lisp/gnorb-org.el b/lisp/gnorb-org.el
index 196dc9e..e7b56b2 100644
--- a/lisp/gnorb-org.el
+++ b/lisp/gnorb-org.el
@@ -57,42 +57,53 @@ point."
 (defun gnorb-org-restore-after-send ()
   (when (eq major-mode 'gnus-summary-mode)
     (gnus-summary-exit nil t))
-  ;; this var would have been set in `gnorb-gnus-check-org-header',
-  ;; which was run during `message-send-hook'
-  (when gnorb-message-org-ids
-    (dolist (id gnorb-message-org-ids)
-      (with-demoted-errors
-       (org-id-goto id)
-       (delete-other-windows)
-       (when (or (null gnorb-org-mail-todos)
-                 (member (org-entry-get (point) "TODO")
-                         gnorb-org-mail-todos))
-         (call-interactively 'org-todo)))))
   (when (window-configuration-p gnorb-org-window-conf)
     (set-window-configuration gnorb-org-window-conf))
+  ;; This is some ugly stuff, but it (hopefully) results in smooth
+  ;; usage.
+  (let* ((agenda-p (eq major-mode 'org-agenda-mode))
+        ;; all this is still broken. Why?
+        (ret-dest-id (org-entry-get
+                      (if agenda-p
+                          (org-get-at-bol 'org-hd-marker)
+                        (point-at-bol)) "ID"))
+        (ret-dest-todo (org-entry-get
+                        (if agenda-p
+                            (org-get-at-bol 'org-hd-marker)
+                          (point-at-bol)) "TODO")))
+    (if (not gnorb-message-org-ids)
+       ;; If there were no Org ID headers, just throw us back where
+       ;; we were and hope.
+       (cond ((eq major-mode 'org-agenda-mode)
+              (call-interactively 'org-agenda-todo))
+             ((eq major-mode 'org-mode)
+              (call-interactively 'org-todo))
+             (t nil))
+      ;; We've been returned to a heading, is it the one referenced by
+      ;; the first of the Org ID headers? This should be the most
+      ;; common case.
+      (when (and (equal ret-dest-id (car gnorb-message-org-ids))
+                (or (null gnorb-org-mail-todos)
+                    (member ret-dest-todo gnorb-org-mail-todos)))
+       (if agenda-p
+           (call-interactively 'org-agenda-todo)
+         (call-interactively 'org-todo))
+       (setq gnorb-message-org-ids
+             (cdr gnorb-message-org-ids)))
+      ;; there's currently no way to attach multiple Org IDs to a
+      ;; message, but there might be in the future
+      (dolist (id gnorb-message-org-ids)
+       (with-demoted-errors
+         (org-id-goto id)
+         (delete-other-windows)
+         (when (or (null gnorb-org-mail-todos)
+                   (member (org-entry-get (point) "TODO")
+                           gnorb-org-mail-todos))
+           (call-interactively 'org-todo))))))
   ;; this is a little unnecessary, but still...
   (setq gnorb-org-window-conf nil)
   (setq gnorb-message-org-ids nil))
 
-   ;; (cond ((eq major-mode 'org-agenda-mode)
-   ;;    (if (null gnorb-org-mail-todos)
-   ;;        (call-interactively 'org-agenda-todo)
-   ;;      (let* ((marker (or (org-get-at-bol 'org-marker)
-   ;;                         (org-agenda-error)))
-   ;;             (buffer (marker-buffer marker)))
-   ;;        (when (save-excursion
-   ;;                (with-current-buffer buffer
-   ;;                  (goto-char (marker-position marker))
-   ;;                  (member (org-entry-get (point) "TODO")
-   ;;                          gnorb-org-mail-todos)))
-   ;;          (call-interactively 'org-agenda-todo)))))
-   ;;   ((eq major-mode 'org-mode)
-   ;;    (when (or (null gnorb-org-mail-todos)
-   ;;              (member (org-entry-get (point) "TODO")
-   ;;                      gnorb-org-mail-todos))
-   ;;      (call-interactively 'org-todo)))
-   ;;   (t nil))
-
 (defun gnorb-org-extract-mail-stuff ()
   (let (message mails)
     (while (re-search-forward org-any-link-re (line-end-position) t)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]